Esempio n. 1
0
        public static void Update1To2()
        {
            if (!EditorUtility.DisplayDialog("Warning",
                                             "Execute version update and reload the active scene. Do you want to run it?", "OK", "Cancel"))
            {
                return;
            }

            if (!File.Exists(AppDataFilePath))
            {
                EditorUtility.DisplayDialog("Error", $"The target file does not exists at {AppDataFilePath}", "OK");
                return;
            }

            var json          = File.ReadAllText(AppDataFilePath);
            var obsoleteStore = JsonUtility.FromJson <UPaletteStore>(json);

            var palette = PaletteStore.LoadAsset();

            if (palette != null)
            {
                if (!EditorUtility.DisplayDialog("Warning",
                                                 $"{nameof(PaletteStore)} already exists. Do you want to overwrite it?", "OK", "Cancel"))
                {
                    return;
                }

                var assetPath = AssetDatabase.GetAssetPath(palette);
                PaletteStore.RemoveAsset();
                palette = PaletteStore.CreateAsset(assetPath);
            }
            else
            {
                // Open save file panel and create PaletteStore asset.
                palette = PaletteStore.CreateAsset();

                // If cancelled, do nothing.
                if (palette == null)
                {
                    return;
                }
            }

            var theme = palette.ColorPalette.ActiveTheme.Value;

            foreach (var obsoleteEntry in obsoleteStore.Entries)
            {
                var entry = palette.ColorPalette.AddEntry(obsoleteEntry.ID);
                entry.Name.Value             = obsoleteEntry.Name.Value;
                entry.Values[theme.Id].Value = obsoleteEntry.Value.Value;
            }

            EditorUtility.SetDirty(palette);
            AssetDatabase.SaveAssets();
            AssetDatabase.DeleteAsset(AppDataFilePath);

            // Restart the current scene.
            EditorSceneManager.OpenScene(SceneManager.GetActiveScene().path, OpenSceneMode.Single);
        }
        public override void OnGUI(string searchContext)
        {
            using (new GUIScope())
            {
                var store = PaletteStore.LoadAsset();

                if (store == null)
                {
                    EditorGUILayout.HelpBox(
                        "To use Project Settings, you need to create a PaletteStore to initialize uPalette.",
                        MessageType.Warning);

                    if (GUILayout.Button("Create Palette Store"))
                    {
                        PaletteStore.CreateAsset();
                    }

                    if (GUILayout.Button("Update Version 1 to 2"))
                    {
                        VersionUpdater.Update1To2();
                    }

                    return;
                }

                var projectSettings = UPaletteProjectSettings.instance;

                using (var ccs = new EditorGUI.ChangeCheckScope())
                {
                    store.MissingEntryErrorLevel =
                        (MissingEntryErrorLevel)EditorGUILayout.EnumPopup("Missing Entry Error",
                                                                          store.MissingEntryErrorLevel);

                    if (ccs.changed)
                    {
                        EditorUtility.SetDirty(store);
                    }
                }

                using (var ccs = new EditorGUI.ChangeCheckScope())
                {
                    projectSettings.NameEnumsFileGenerateMode =
                        (NameEnumsFileGenerateMode)EditorGUILayout.EnumPopup("Name Enums File Generation",
                                                                             projectSettings.NameEnumsFileGenerateMode);

                    projectSettings.NameEnumsFolder =
                        (DefaultAsset)EditorGUILayout.ObjectField("Name Enums File Location",
                                                                  projectSettings.NameEnumsFolder,
                                                                  typeof(DefaultAsset), false);

                    if (ccs.changed && projectSettings.NameEnumsFileGenerateMode ==
                        NameEnumsFileGenerateMode.WhenWindowLosesFocus)
                    {
                        EditorPrefs.SetBool(EditorPrefsKey.IsIdOrNameDirtyPrefsKey, true);
                    }
                }
            }
        }
        private void Update()
        {
            if (_storeInstance != null)
            {
                return;
            }

            var store = PaletteStore.LoadAsset();

            _store.Value   = store;
            _storeInstance = store;
        }
 public ThemeEditorWindowEmptyViewController(ThemeEditorWindowEmptyView view)
 {
     _view = view;
     _view.CreateButtonClickedAsObservable.Subscribe(_ =>
     {
         if (PaletteStore.LoadAsset() == null)
         {
             PaletteStore.CreateAsset();
         }
         else
         {
             throw new InvalidOperationException($"{nameof(PaletteStore)} already exists.");
         }
     }).DisposeWith(_disposables);
 }
Esempio n. 5
0
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
                                                  string[] movedFromAssetPaths)
        {
            var paletteStore = PaletteStore.LoadAsset();

            if (paletteStore == null)
            {
                return;
            }

            var assetPath = AssetDatabase.GetAssetPath(paletteStore);

            foreach (var importedAsset in importedAssets)
            {
                if (assetPath != importedAsset)
                {
                    continue;
                }

                _needReloading = false;
                EditorApplication.delayCall += OnPaletteStoreImported;
                return;
            }
        }