説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ThemeDrawer.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. #if dUI_TextMeshPro
  5. using TMPro;
  6. #endif
  7. using XCharts.Runtime;
  8. namespace XCharts.Editor
  9. {
  10. [CustomPropertyDrawer(typeof(ThemeStyle), true)]
  11. public class ThemeStyleDrawer : BasePropertyDrawer
  12. {
  13. public override string ClassName { get { return "Theme"; } }
  14. public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
  15. {
  16. base.OnGUI(pos, prop, label);
  17. var defaultWidth = pos.width;
  18. var defaultX = pos.x;
  19. var chart = prop.serializedObject.targetObject as BaseChart;
  20. if (MakeComponentFoldout(prop, "m_Show", false, new HeaderMenuInfo("Reset|Reset to theme default color", () =>
  21. {
  22. chart.theme.sharedTheme.ResetTheme();
  23. chart.RefreshAllComponent();
  24. }), new HeaderMenuInfo("Export|Export theme to asset for a new theme", () =>
  25. {
  26. ExportThemeWindow.target = chart;
  27. EditorWindow.GetWindow(typeof(ExportThemeWindow));
  28. }), new HeaderMenuInfo("Sync color to custom|Sync shared theme color to custom color", () =>
  29. {
  30. chart.theme.SyncSharedThemeColorToCustom();
  31. })))
  32. {
  33. ++EditorGUI.indentLevel;
  34. var chartNameList = XCThemeMgr.GetAllThemeNames();
  35. var lastIndex = chartNameList.IndexOf(chart.theme.themeName);
  36. var y = pos.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
  37. var selectedIndex = EditorGUI.Popup(new Rect(pos.x, y, pos.width, EditorGUIUtility.singleLineHeight),
  38. "Shared Theme", lastIndex, chartNameList.ToArray());
  39. AddSingleLineHeight();
  40. if (lastIndex != selectedIndex)
  41. {
  42. XCThemeMgr.SwitchTheme(chart, chartNameList[selectedIndex]);
  43. }
  44. PropertyField(prop, "m_SharedTheme");
  45. PropertyField(prop, "m_TransparentBackground");
  46. PropertyField(prop, "m_EnableCustomTheme");
  47. using(new EditorGUI.DisabledScope(!prop.FindPropertyRelative("m_EnableCustomTheme").boolValue))
  48. {
  49. PropertyField(prop, "m_CustomBackgroundColor");
  50. PropertyField(prop, "m_CustomColorPalette");
  51. }
  52. --EditorGUI.indentLevel;
  53. }
  54. }
  55. private void AddPropertyField(Rect pos, SerializedProperty prop, ref float y)
  56. {
  57. float height = EditorGUI.GetPropertyHeight(prop, new GUIContent(prop.displayName), true);
  58. EditorGUI.PropertyField(new Rect(pos.x, y, pos.width, height), prop, true);
  59. y += height + EditorGUIUtility.standardVerticalSpacing;
  60. m_Heights[m_KeyName] += height + EditorGUIUtility.standardVerticalSpacing;
  61. }
  62. }
  63. public class ExportThemeWindow : UnityEditor.EditorWindow
  64. {
  65. public static BaseChart target;
  66. private static ExportThemeWindow window;
  67. private string m_ChartName;
  68. static void Init()
  69. {
  70. window = (ExportThemeWindow) EditorWindow.GetWindow(typeof(ExportThemeWindow), false, "Export Theme", true);
  71. window.minSize = new Vector2(600, 50);
  72. window.maxSize = new Vector2(600, 50);
  73. window.Show();
  74. }
  75. void OnInspectorUpdate()
  76. {
  77. Repaint();
  78. }
  79. private void OnGUI()
  80. {
  81. if (target == null)
  82. {
  83. Close();
  84. return;
  85. }
  86. GUILayout.Space(10);
  87. GUILayout.Label("Input a new name for theme:");
  88. m_ChartName = GUILayout.TextField(m_ChartName);
  89. GUILayout.Space(10);
  90. GUILayout.Label("Export path:");
  91. if (string.IsNullOrEmpty(m_ChartName))
  92. {
  93. GUILayout.Label("Need input a new name.");
  94. }
  95. else
  96. {
  97. GUILayout.Label(XCThemeMgr.GetThemeAssetPath(m_ChartName));
  98. }
  99. GUILayout.Space(20);
  100. if (GUILayout.Button("Export"))
  101. {
  102. if (string.IsNullOrEmpty(m_ChartName))
  103. {
  104. ShowNotification(new GUIContent("ERROR:Need input a new name!"));
  105. }
  106. else if (XCThemeMgr.ContainsTheme(m_ChartName))
  107. {
  108. ShowNotification(new GUIContent("ERROR:The name you entered is already in use!"));
  109. }
  110. else if (IsAssetsExist(XCThemeMgr.GetThemeAssetPath(m_ChartName)))
  111. {
  112. ShowNotification(new GUIContent("ERROR:The asset is exist! \npath=" +
  113. XCThemeMgr.GetThemeAssetPath(m_ChartName)));
  114. }
  115. else
  116. {
  117. XCThemeMgr.ExportTheme(target.theme.sharedTheme, m_ChartName);
  118. ShowNotification(new GUIContent("SUCCESS:The theme is exported. \npath=" +
  119. XCThemeMgr.GetThemeAssetPath(m_ChartName)));
  120. }
  121. }
  122. }
  123. private bool IsAssetsExist(string path)
  124. {
  125. return File.Exists(Application.dataPath + "/../" + path);
  126. }
  127. }
  128. }