Beispiel #1
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            if (prop.objectReferenceValue == null)
            {
                EditorGUI.ObjectField(pos, prop, new GUIContent("Theme"));
                return;
            }
            base.OnGUI(pos, prop, label);
            var defaultWidth = pos.width;
            var defaultX     = pos.x;
            var btnWidth     = 45;

            ChartEditorHelper.MakeFoldout(ref m_DrawRect, ref m_ThemeModuleToggle, "Theme");
            m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            if (m_ThemeModuleToggle)
            {
                m_DrawRect.x     = defaultX + defaultWidth - 2 * btnWidth - 2;
                m_DrawRect.width = btnWidth;
                var chart    = prop.serializedObject.targetObject as BaseChart;
                var lastFont = chart.theme.font;
#if dUI_TextMeshPro
                var lastTMPFont = chart.theme.tmpFont;
#endif
                if (GUI.Button(m_DrawRect, new GUIContent("Reset", "Reset to theme default color")))
                {
                    chart.theme.ResetTheme();
                    chart.RefreshAllComponent();
                }
                m_DrawRect.x     = defaultX + defaultWidth - btnWidth;
                m_DrawRect.width = btnWidth;
                if (GUI.Button(m_DrawRect, new GUIContent("Export", "Export theme to asset for a new theme")))
                {
                    ExportThemeWindow.target = chart;
                    EditorWindow.GetWindow(typeof(ExportThemeWindow));
                }

                var data = (ScriptableObject)prop.objectReferenceValue;
                SerializedObject   serializedObject = new SerializedObject(data);
                SerializedProperty newProp          = serializedObject.GetIterator();
                float y = pos.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                ++EditorGUI.indentLevel;

                var chartNameList = XChartsMgr.GetAllThemeNames();
                var lastIndex     = chartNameList.IndexOf(chart.theme.themeName);
                var selectedIndex = EditorGUI.Popup(new Rect(pos.x, y, pos.width, EditorGUIUtility.singleLineHeight),
                                                    "Theme", lastIndex, chartNameList.ToArray());
                m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                if (lastIndex != selectedIndex)
                {
                    GUI.changed = true;
                    XChartsMgr.SwitchTheme(chart, chartNameList[selectedIndex]);
                }
                if (newProp.NextVisible(true))
                {
                    do
                    {
                        if (newProp.name == "m_Script")
                        {
                            continue;
                        }
                        if (newProp.name == "m_ThemeName")
                        {
                            continue;
                        }
                        if (newProp.name == "m_Theme")
                        {
                            continue;
                        }
                        AddPropertyField(pos, newProp, ref y);
                    } while (newProp.NextVisible(false));
                }
                if (GUI.changed)
                {
                    chart.RefreshAllComponent();
                    serializedObject.ApplyModifiedProperties();
                }
                if (chart.theme.font != lastFont)
                {
                    chart.theme.SyncFontToSubComponent();
                }
#if dUI_TextMeshPro
                if (chart.theme.tmpFont != lastTMPFont)
                {
                    chart.theme.SyncTMPFontToSubComponent();
                }
#endif
                --EditorGUI.indentLevel;
            }
        }