CleanerStyleAsset.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Linq;
  3. using UnityEditor;
  4. using UnityEngine;
  5. using Object = UnityEngine.Object;
  6. #pragma warning disable 649
  7. namespace Asset_Cleaner {
  8. class CleanerStyleAsset : ScriptableObject {
  9. [Serializable]
  10. public class Style {
  11. public Color RedHighlight = new Color(1, 0, 0, 1f);
  12. public GUIContent Lock;
  13. public GUIStyle LockBtn = new GUIStyle();
  14. public GUIStyle SampleBtn = new GUIStyle();
  15. public GUIContent Unlock;
  16. public GUIStyle UnlockBtn = new GUIStyle();
  17. public GUIContent RemoveFile;
  18. public GUIContent RemoveScene;
  19. public GUIStyle RowMainAssetBtn = new GUIStyle();
  20. public GUIStyle RemoveUnusedBtn = new GUIStyle();
  21. public GUIStyle CurrentBtn = new GUIStyle();
  22. public GUIContent ArrowL;
  23. public GUIContent ArrowR;
  24. public GUIStyle ArrowBtn = new GUIStyle();
  25. public float SceneIndent1 = 20f;
  26. public float SceneIndent2 = 20f;
  27. public GUIStyle ProjectViewCounterLabel;
  28. public GUIContent MultiSelect;
  29. public static bool TryFindSelf(out Style value) {
  30. const string typeName = nameof(CleanerStyleAsset);
  31. var guids = AssetDatabase.FindAssets($"t:{typeName}");
  32. if (!guids.Any()) {
  33. AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
  34. }
  35. Asr.IsTrue(guids.Length > 0, $"No '{typeName}' assets found");
  36. var res = guids.Select(AssetDatabase.GUIDToAssetPath).Select(t => (CleanerStyleAsset) AssetDatabase.LoadAssetAtPath(t, typeof(CleanerStyleAsset))).FirstOrDefault();
  37. if (res == null) {
  38. value = default;
  39. return false;
  40. }
  41. value = EditorGUIUtility.isProSkin ? res.Pro : res.Personal;
  42. return value != null;
  43. }
  44. }
  45. #pragma warning disable 0649
  46. public Style Pro;
  47. public Style Personal;
  48. #pragma warning restore
  49. [CustomEditor(typeof(CleanerStyleAsset))]
  50. class Editor : UnityEditor.Editor {
  51. public override void OnInspectorGUI() {
  52. #if false
  53. if (GUILayout.Button("Update Btn backgrounds")) {
  54. var targ = (CleanerStyleAsset) target;
  55. Set(targ.Pro);
  56. }
  57. #endif
  58. EditorGUI.BeginChangeCheck();
  59. base.OnInspectorGUI();
  60. if (EditorGUI.EndChangeCheck())
  61. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
  62. }
  63. #if false
  64. static void Set(Style style) {
  65. var st = style;
  66. var sample = st.SampleBtn;
  67. foreach (var btn in new[] {
  68. st.LockBtn,
  69. st.UnlockBtn,
  70. st.RowMainAssetBtn,
  71. st.RemoveUnusedBtn,
  72. st.CurrentBtn,
  73. st.ArrowBtn,
  74. }) {
  75. btn.normal = sample.normal;
  76. btn.hover = sample.hover;
  77. btn.active = sample.active;
  78. btn.focused = sample.focused;
  79. btn.onNormal = sample.onNormal;
  80. btn.onHover = sample.onHover;
  81. btn.onActive = sample.onActive;
  82. btn.onFocused = sample.onFocused;
  83. }
  84. }
  85. #endif
  86. }
  87. }
  88. }