No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserSettings.cs 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. internal class SkinningModuleSettings
  6. {
  7. public const string kCompactToolbarKey = UserSettings.kSettingsUniqueKey + "AnimationEditorSetting.compactToolbar";
  8. public const string kShowSpriteMeshOverwriteWarningKey = UserSettings.kSettingsUniqueKey + "AnimationEditorSetting.showSpriteMeshOverwriteWarning";
  9. public static readonly GUIContent kCompactToolbarLabel = EditorGUIUtility.TrTextContent("Hide Tool Text");
  10. public static readonly GUIContent kShowSpriteMeshOverwriteWarning = new GUIContent(TextContent.showSpriteMeshOverwriteWarning, TextContent.showSpriteMeshOverwriteWarningTip);
  11. public static bool compactToolBar
  12. {
  13. get { return EditorPrefs.GetBool(kCompactToolbarKey, false); }
  14. set { EditorPrefs.SetBool(kCompactToolbarKey, value); }
  15. }
  16. public static bool showSpriteMeshOverwriteWarning
  17. {
  18. get { return EditorPrefs.GetBool(kShowSpriteMeshOverwriteWarningKey, true); }
  19. set { EditorPrefs.SetBool(kShowSpriteMeshOverwriteWarningKey, value); }
  20. }
  21. public void OnGUI()
  22. {
  23. EditorGUI.BeginChangeCheck();
  24. var c = EditorGUILayout.Toggle(kCompactToolbarLabel, compactToolBar);
  25. if (EditorGUI.EndChangeCheck())
  26. compactToolBar = c;
  27. EditorGUI.BeginChangeCheck();
  28. c = EditorGUILayout.Toggle(kShowSpriteMeshOverwriteWarning, showSpriteMeshOverwriteWarning);
  29. if (EditorGUI.EndChangeCheck())
  30. showSpriteMeshOverwriteWarning = c;
  31. }
  32. }
  33. internal class VisibilityToolSettings
  34. {
  35. public const string kBoneOpacitykey = UserSettings.kSettingsUniqueKey + "VisibilityToolSettings.boneOpacity";
  36. public const string kMeshOpacityKey = UserSettings.kSettingsUniqueKey + "VisibilityToolSettings.meshOpacity";
  37. public static float boneOpacity
  38. {
  39. get { return EditorPrefs.GetFloat(kBoneOpacitykey, 1.0f); }
  40. set { EditorPrefs.SetFloat(kBoneOpacitykey, value); }
  41. }
  42. public static float meshOpacity
  43. {
  44. get { return EditorPrefs.GetFloat(kMeshOpacityKey, 0.5f); }
  45. set { EditorPrefs.SetFloat(kMeshOpacityKey, value); }
  46. }
  47. }
  48. internal class GenerateGeomertySettings
  49. {
  50. public const int kDefaultOutlineDetail = 10;
  51. public const int kDefaultAlphaTolerance = 10;
  52. public const int kDefaultSubdivide = 0;
  53. public const string kOutlineDetailKey = UserSettings.kSettingsUniqueKey + "GenerateGeomertySetting.outlineDetail";
  54. public const string kAlphaToleranceKey = UserSettings.kSettingsUniqueKey + "GenerateGeomertySetting.alphaTolerance";
  55. public const string kSubdivideKey = UserSettings.kSettingsUniqueKey + "GenerateGeomertySetting.subdivide";
  56. public const string kGenerateWeightsKey = UserSettings.kSettingsUniqueKey + "GenerateGeomertySetting.generateWeights";
  57. public static int outlineDetail
  58. {
  59. get { return EditorPrefs.GetInt(kOutlineDetailKey, kDefaultOutlineDetail); }
  60. set { EditorPrefs.SetInt(kOutlineDetailKey, value); }
  61. }
  62. public static int alphaTolerance
  63. {
  64. get { return EditorPrefs.GetInt(kAlphaToleranceKey, kDefaultAlphaTolerance); }
  65. set { EditorPrefs.SetInt(kAlphaToleranceKey, value); }
  66. }
  67. public static int subdivide
  68. {
  69. get { return EditorPrefs.GetInt(kSubdivideKey, kDefaultSubdivide); }
  70. set { EditorPrefs.SetInt(kSubdivideKey, value); }
  71. }
  72. public static bool generateWeights
  73. {
  74. get { return EditorPrefs.GetBool(kGenerateWeightsKey, true); }
  75. set { EditorPrefs.SetBool(kGenerateWeightsKey, value); }
  76. }
  77. }
  78. internal class SelectionOutlineSettings
  79. {
  80. public const string kSelectedOutlineRedKey = UserSettings.kSettingsUniqueKey + "OutlineColorRed";
  81. public const string kSelectedOutlineGreenKey = UserSettings.kSettingsUniqueKey + "OutlineColorGreen";
  82. public const string kSelectedOutlineBlueKey = UserSettings.kSettingsUniqueKey + "OutlineColorBlue";
  83. public const string kSelectedOutlineAlphaKey = UserSettings.kSettingsUniqueKey + "OutlineColorAlpha";
  84. public const string kSelectedSpriteOutlineSize = UserSettings.kSettingsUniqueKey + "OutlineSize";
  85. public const string kSelectedBoneOutlineSize = UserSettings.kSettingsUniqueKey + "BoneOutlineSize";
  86. public static readonly GUIContent kSelectedOutlineColorLabel = new GUIContent(TextContent.selectedOutlineColor);
  87. public static readonly GUIContent kSelectedOutlineSizeLabel = new GUIContent(TextContent.spriteOutlineSize);
  88. public static readonly GUIContent kSelectedBoneOutlineSizeLabel = new GUIContent(TextContent.boneOutlineSize);
  89. public static Color outlineColor
  90. {
  91. get
  92. {
  93. return new Color()
  94. {
  95. r = EditorPrefs.GetFloat(kSelectedOutlineRedKey, 1),
  96. g = EditorPrefs.GetFloat(kSelectedOutlineGreenKey, 102.0f / 255.0f),
  97. b = EditorPrefs.GetFloat(kSelectedOutlineBlueKey, 0),
  98. a = EditorPrefs.GetFloat(kSelectedOutlineAlphaKey, 1)
  99. };
  100. }
  101. set
  102. {
  103. EditorPrefs.SetFloat(kSelectedOutlineRedKey, value.r);
  104. EditorPrefs.SetFloat(kSelectedOutlineGreenKey, value.g);
  105. EditorPrefs.SetFloat(kSelectedOutlineBlueKey, value.b);
  106. EditorPrefs.SetFloat(kSelectedOutlineAlphaKey, value.a);
  107. }
  108. }
  109. public static int selectedSpriteOutlineSize
  110. {
  111. get { return EditorPrefs.GetInt(kSelectedSpriteOutlineSize, 1); }
  112. set { EditorPrefs.SetInt(kSelectedSpriteOutlineSize, value); }
  113. }
  114. public static float selectedBoneOutlineSize
  115. {
  116. get { return EditorPrefs.GetFloat(kSelectedBoneOutlineSize, 1); }
  117. set { EditorPrefs.SetFloat(kSelectedBoneOutlineSize, value); }
  118. }
  119. public void OnGUI()
  120. {
  121. EditorGUI.BeginChangeCheck();
  122. var c = EditorGUILayout.ColorField(kSelectedOutlineColorLabel, outlineColor);
  123. if (EditorGUI.EndChangeCheck())
  124. outlineColor = c;
  125. EditorGUI.BeginChangeCheck();
  126. var s = EditorGUILayout.IntSlider(kSelectedOutlineSizeLabel, selectedSpriteOutlineSize, 0, 10);
  127. if (EditorGUI.EndChangeCheck())
  128. selectedSpriteOutlineSize = s;
  129. EditorGUI.BeginChangeCheck();
  130. var o = EditorGUILayout.Slider(kSelectedBoneOutlineSizeLabel, selectedBoneOutlineSize, 0, 3);
  131. if (EditorGUI.EndChangeCheck())
  132. selectedBoneOutlineSize = o;
  133. }
  134. }
  135. internal class UserSettings : SettingsProvider
  136. {
  137. public const string kSettingsUniqueKey = "UnityEditor.U2D.Animation/";
  138. private static SelectionOutlineSettings s_SelectionOutlineSettings = new SelectionOutlineSettings();
  139. private static SkinningModuleSettings s_SkinningModuleSettings = new SkinningModuleSettings();
  140. public UserSettings() : base("Preferences/2D/Animation", SettingsScope.User)
  141. {
  142. guiHandler = OnGUI;
  143. }
  144. [SettingsProvider]
  145. private static SettingsProvider CreateSettingsProvider()
  146. {
  147. return new UserSettings()
  148. {
  149. guiHandler = SettingsGUI
  150. };
  151. }
  152. private static void SettingsGUI(string searchContext)
  153. {
  154. s_SkinningModuleSettings.OnGUI();
  155. s_SelectionOutlineSettings.OnGUI();
  156. }
  157. }
  158. }