File size: 4,492 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | using System;
using UnityEngine;
namespace UnityEditor.SettingsManagement
{
/// <summary>
/// Register a static field of type IUserSetting with the UserSettingsProvider window.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public sealed class UserSettingAttribute : Attribute
{
string m_Category;
GUIContent m_Title;
bool m_VisibleInSettingsProvider;
/// <summary>
/// Settings that are automatically scraped from assemblies are displayed in groups, organized by category.
/// </summary>
/// <value>
/// The title of the group of settings that this setting will be shown under.
/// </value>
public string category
{
get { return m_Category; }
}
/// <value>
/// The label to show for this setting.
/// </value>
public GUIContent title
{
get { return m_Title; }
}
/// <value>
/// True if this field should be shown in the UserSettingsProvider interface, false if not.
/// </value>
public bool visibleInSettingsProvider
{
get { return m_VisibleInSettingsProvider; }
}
/// <summary>
/// Register a static field as a setting. Field must be of a type implementing IUserSetting.
/// </summary>
public UserSettingAttribute()
{
m_VisibleInSettingsProvider = false;
}
/// <summary>
/// Register a static field as a setting and create an entry in the UI. Field must be of a type implementing IUserSetting.
/// </summary>
public UserSettingAttribute(string category, string title, string tooltip = null)
{
m_Category = category;
m_Title = new GUIContent(title, tooltip);
m_VisibleInSettingsProvider = true;
}
}
/// <summary>
/// Register a field with Settings, but do not automatically create a property field in the SettingsProvider.
/// Unlike UserSettingAttribute, this attribute is valid for instance properties as well as static. These values
/// will not be shown in the SettingsProvider, but will have their stored values cleared when "Reset All" is invoked.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public sealed class SettingsKeyAttribute : Attribute
{
string m_Key;
SettingsScope m_Scope;
/// <value>
/// The key for this value.
/// </value>
public string key
{
get { return m_Key; }
}
/// <value>
/// Where this setting is serialized.
/// </value>
public SettingsScope scope
{
get { return m_Scope; }
}
/// <summary>
/// Register a field as a setting. This allows the UserSettingsProvider to reset it's value and display it's
/// value in debugging modes.
/// </summary>
/// <param name="key">The setting key.</param>
/// <param name="scope">The scope in which this setting is serialized.</param>
public SettingsKeyAttribute(string key, SettingsScope scope = SettingsScope.Project)
{
m_Key = key;
m_Scope = scope;
}
}
/// <summary>
/// UserSettingBlock allows you add a section of settings to a category.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class UserSettingBlockAttribute : Attribute
{
string m_Category;
/// <summary>
/// Settings that are automatically scraped from assemblies are displayed in groups, organized by category.
/// </summary>
/// <value>
/// The title of the group of settings that this setting will be shown under.
/// </value>
public string category
{
get { return m_Category; }
}
/// <summary>
/// Register a static method for a callback in the UserSettingsProvider editor under a category.
/// <code>
/// [UserSettingBlock("General")]
/// static void GeneralSettings(string[] searchContext) {}
/// </code>
/// </summary>
/// <param name="category">The title of the group of settings that this setting will be shown under.</param>
public UserSettingBlockAttribute(string category)
{
m_Category = category;
}
}
}
|