UserSettings.cs 6.9 KB

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