public static void CheckDeletedAsset(string assetPath)
        {
            if (!IsThemeAsset(assetPath))
            {
                return;
            }
            if (XCSettings.Instance == null)
            {
                return;
            }
            var themes  = XCSettings.customThemes;
            var changed = false;

            for (int i = themes.Count - 1; i >= 0; i--)
            {
                if (themes[i] == null)
                {
                    themes.RemoveAt(i);
                    changed = true;
                }
            }
            if (changed)
            {
                XCThemeMgr.ReloadThemeList();
            }
        }
Exemple #2
0
        public static T AddChart <T>(string chartName) where T : BaseChart
        {
            var parent = GetParent();

            if (parent == null)
            {
                return(null);
            }
            XCThemeMgr.CheckReloadTheme();
            var chart = new GameObject();

            chart.name = GetName(parent, chartName);
            var t = chart.AddComponent <T>();

            chart.transform.SetParent(parent);
            chart.transform.localScale    = Vector3.one;
            chart.transform.localPosition = Vector3.zero;
            var rect = chart.GetComponent <RectTransform>();

            rect.anchorMin             = new Vector2(0.5f, 0.5f);
            rect.anchorMax             = new Vector2(0.5f, 0.5f);
            rect.pivot                 = new Vector2(0.5f, 0.5f);
            Selection.activeGameObject = chart;
            EditorUtility.SetDirty(chart);
            return(t);
        }
        private void OnGUI()
        {
            if (target == null)
            {
                Close();
                return;
            }
            GUILayout.Space(10);
            GUILayout.Label("Input a new name for theme:");
            m_ChartName = GUILayout.TextField(m_ChartName);

            GUILayout.Space(10);
            GUILayout.Label("Export path:");
            if (string.IsNullOrEmpty(m_ChartName))
            {
                GUILayout.Label("Need input a new name.");
            }
            else
            {
                GUILayout.Label(XCThemeMgr.GetThemeAssetPath(m_ChartName));
            }

            GUILayout.Space(20);
            if (GUILayout.Button("Export"))
            {
                if (string.IsNullOrEmpty(m_ChartName))
                {
                    ShowNotification(new GUIContent("ERROR:Need input a new name!"));
                }
                else if (XCThemeMgr.ContainsTheme(m_ChartName))
                {
                    ShowNotification(new GUIContent("ERROR:The name you entered is already in use!"));
                }
                else if (IsAssetsExist(XCThemeMgr.GetThemeAssetPath(m_ChartName)))
                {
                    ShowNotification(new GUIContent("ERROR:The asset is exist! \npath=" +
                                                    XCThemeMgr.GetThemeAssetPath(m_ChartName)));
                }
                else
                {
                    XCThemeMgr.ExportTheme(target.theme.sharedTheme, m_ChartName);
                    ShowNotification(new GUIContent("SUCCESS:The theme is exported. \npath=" +
                                                    XCThemeMgr.GetThemeAssetPath(m_ChartName)));
                }
            }
        }
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            base.OnGUI(pos, prop, label);
            var defaultWidth = pos.width;
            var defaultX     = pos.x;
            var chart        = prop.serializedObject.targetObject as BaseChart;

            if (MakeComponentFoldout(prop, "m_Show", false, new HeaderMenuInfo("Reset|Reset to theme default color", () =>
            {
                chart.theme.sharedTheme.ResetTheme();
                chart.RefreshAllComponent();
            }), new HeaderMenuInfo("Export|Export theme to asset for a new theme", () =>
            {
                ExportThemeWindow.target = chart;
                EditorWindow.GetWindow(typeof(ExportThemeWindow));
            }), new HeaderMenuInfo("Sync color to custom|Sync shared theme color to custom color", () =>
            {
                chart.theme.SyncSharedThemeColorToCustom();
            })))
            {
                ++EditorGUI.indentLevel;
                var chartNameList = XCThemeMgr.GetAllThemeNames();
                var lastIndex     = chartNameList.IndexOf(chart.theme.themeName);
                var y             = pos.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                var selectedIndex = EditorGUI.Popup(new Rect(pos.x, y, pos.width, EditorGUIUtility.singleLineHeight),
                                                    "Shared Theme", lastIndex, chartNameList.ToArray());
                AddSingleLineHeight();
                if (lastIndex != selectedIndex)
                {
                    XCThemeMgr.SwitchTheme(chart, chartNameList[selectedIndex]);
                }
                PropertyField(prop, "m_SharedTheme");
                PropertyField(prop, "m_TransparentBackground");
                PropertyField(prop, "m_EnableCustomTheme");
                using (new EditorGUI.DisabledScope(!prop.FindPropertyRelative("m_EnableCustomTheme").boolValue))
                {
                    PropertyField(prop, "m_CustomBackgroundColor");
                    PropertyField(prop, "m_CustomColorPalette");
                }
                --EditorGUI.indentLevel;
            }
        }
        public static void CheckAddedAsset(string assetPath)
        {
            var fileName = Path.GetFileName(assetPath);

            if (fileName.Equals("XCSettings.asset"))
            {
                XCThemeMgr.ReloadThemeList();
                return;
            }
            if (!IsThemeAsset(assetPath))
            {
                return;
            }
            var theme = AssetDatabase.LoadAssetAtPath <Theme>(assetPath);

            if (XCSettings.AddCustomTheme(theme))
            {
                XCThemeMgr.ReloadThemeList();
            }
        }
Exemple #6
0
 public static void ReloadTheme()
 {
     XCThemeMgr.ReloadThemeList();
 }