Example #1
0
        void RegisterUndo(ISelectionGroup @group, string msg)
        {
            if (group is SelectionGroups.Runtime.SelectionGroup runtimeGroup)
            {
                Undo.RegisterCompleteObjectUndo(runtimeGroup, msg);
                EditorUtility.SetDirty(runtimeGroup);
            }

            if (group is SelectionGroup editorGroup)
            {
                SelectionGroupPersistenceManager.RegisterUndo(msg);
            }
        }
        internal static void CreateAndLoad()
        {
            System.Diagnostics.Debug.Assert(_instance == null);
            //Find existing
            var managers = Resources.FindObjectsOfTypeAll(typeof(SelectionGroupPersistenceManager));

            if (managers.Length > 0)
            {
                _instance = managers[0] as SelectionGroupPersistenceManager;
                if (managers.Length != 1)
                {
                    Debug.LogError($"Multiple SelectionGroupManager instances detected! {managers.Length}");
                }
            }

            if (_instance == null)
            {
                // Load
                string filePath = GetFilePath();
                if (!string.IsNullOrEmpty(filePath))
                {
                    // If a file exists the
                    var objects = InternalEditorUtility.LoadSerializedFileAndForget(filePath);
                    if (objects.Length > 0 && objects[0] is SelectionGroupPersistenceManager)
                    {
                        _instance = (SelectionGroupPersistenceManager)objects[0];
                    }
                }
            }

            if (_instance == null)
            {
                // Create
                var t = CreateInstance <SelectionGroupPersistenceManager>();
                // t.hideFlags = HideFlags.HideAndDontSave;
                _instance = t;
            }

            System.Diagnostics.Debug.Assert(_instance != null);
            _instance.hideFlags = HideFlags.HideAndDontSave;
            Instance            = _instance;
        }