Attributes.cs 4.4 KB

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