Files
XCharts/Editor/MainComponents/ThemeEditor.cs

64 lines
2.2 KiB
C#
Raw Normal View History

2021-11-23 13:20:07 +08:00
using UnityEditor;
using UnityEngine;
2022-02-19 22:37:57 +08:00
using XCharts.Runtime;
2021-11-23 13:20:07 +08:00
#if dUI_TextMeshPro
using TMPro;
#endif
2021-12-24 13:33:09 +08:00
namespace XCharts.Editor
2021-11-23 13:20:07 +08:00
{
[CustomEditor(typeof(Theme))]
2021-12-24 13:33:09 +08:00
public class ThemeEditor : UnityEditor.Editor
2021-11-23 13:20:07 +08:00
{
2022-05-22 22:17:38 +08:00
static class Styles
{
2022-08-10 08:16:19 +08:00
internal static GUIContent btnReset = new GUIContent("Reset to Default", "Reset to default theme");
internal static GUIContent btnSyncFontToSubTheme = new GUIContent("Sync Font to Sub Theme", "Sync main theme font to sub theme font");
internal static GUIContent btnSyncFontFromSetting = new GUIContent("Sync Font from Setting", "Sync main theme font and sub theme font from XCSetting font");
2022-05-22 22:17:38 +08:00
}
2021-11-23 13:20:07 +08:00
private Theme m_Theme;
2022-05-22 22:17:38 +08:00
2021-11-23 13:20:07 +08:00
void OnEnable()
{
m_Theme = target as Theme;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
2022-05-22 22:17:38 +08:00
if (GUILayout.Button(Styles.btnReset))
2021-11-23 13:20:07 +08:00
{
2022-08-10 08:16:19 +08:00
if (EditorUtility.DisplayDialog(Styles.btnReset.text, Styles.btnReset.tooltip, "Yes", "Cancel"))
{
m_Theme.ResetTheme();
Debug.Log("XCharts: Reset Finish.");
}
2021-11-23 13:20:07 +08:00
}
2022-08-10 08:16:19 +08:00
if (GUILayout.Button(Styles.btnSyncFontFromSetting))
2022-05-22 22:17:38 +08:00
{
2022-08-10 08:16:19 +08:00
if (EditorUtility.DisplayDialog(Styles.btnSyncFontFromSetting.text, Styles.btnSyncFontFromSetting.tooltip, "Yes", "Cancel"))
{
m_Theme.common.font = XCSettings.font;
m_Theme.SyncFontToSubComponent();
#if dUI_TextMeshPro
m_Theme.common.tmpFont = XCSettings.tmpFont;
m_Theme.SyncTMPFontToSubComponent();
#endif
Debug.Log("XCharts: Sync Finish.");
}
}
if (GUILayout.Button(Styles.btnSyncFontToSubTheme))
{
if (EditorUtility.DisplayDialog(Styles.btnSyncFontToSubTheme.text, Styles.btnSyncFontToSubTheme.tooltip, "Yes", "Cancel"))
{
m_Theme.SyncFontToSubComponent();
#if dUI_TextMeshPro
m_Theme.SyncTMPFontToSubComponent();
#endif
Debug.Log("XCharts: Sync Finish.");
}
2022-05-22 22:17:38 +08:00
}
2021-11-23 13:20:07 +08:00
}
}
}