Beispiel #1
0
        public void MoveElements(TreeElement parentElement, int insertionIndex, List <TreeElement> elements)
        {
            if (insertionIndex < 0)
            {
                throw new ArgumentException("Invalid input: insertionIndex is -1, client needs to decide what index elements should be reparented at");
            }

            // Invalid reparenting input
            if (parentElement == null)
            {
                return;
            }

            // We are moving items so we adjust the insertion index to accomodate that any items above the insertion index is removed before inserting
            if (insertionIndex > 0)
            {
                insertionIndex -= parentElement.children.GetRange(0, insertionIndex).Count(elements.Contains);
            }

            // Remove draggedItems from their parents
            foreach (var draggedItem in elements)
            {
                draggedItem.parent.children.Remove(draggedItem);                        // remove from old parent
                draggedItem.parent = parentElement;                                     // set new parent
            }

            if (parentElement.children == null)
            {
                parentElement.children = new List <TreeElement>();
            }

            // Insert dragged items under new parent
            parentElement.children.InsertRange(insertionIndex, elements);

            TreeElementUtility.UpdateDepthValues(root);
            TreeElementUtility.TreeToList(m_Root, m_Data);

            Changed();
        }
Beispiel #2
0
        public void RemoveElements(IList <T> elements)
        {
            foreach (var element in elements)
            {
                if (element == m_Root)
                {
                    throw new ArgumentException("It is not allowed to remove the root element");
                }
            }

            var commonAncestors = TreeElementUtility.FindCommonAncestorsWithinList(elements);

            foreach (var element in commonAncestors)
            {
                element.parent.children.Remove(element);
                element.parent = null;
            }

            TreeElementUtility.TreeToList(m_Root, m_Data);

            Changed();
        }
Beispiel #3
0
        public void AddElement(T element, TreeElement parent, int insertPosition)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", "element is null");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent", "parent is null");
            }

            if (parent.children == null)
            {
                parent.children = new List <TreeElement> ();
            }

            parent.children.Insert(insertPosition, element);
            element.parent = parent;

            TreeElementUtility.UpdateDepthValues(parent);
            TreeElementUtility.TreeToList(m_Root, m_Data);

            Changed();
        }
        private void SetupMenus()
        {
            _FileMenu         = new GenericMenu();
            _AddressablesMenu = new GenericMenu();
            _ItemsMenu        = new GenericMenu();

            AddPlugins(GetAddressablePlugins());

            // ***********************************************************************************
            // File Menu items
            // ***********************************************************************************
            AddMenuItemWithCallback(FileMenu, "Rebuild From Project", () =>
            {
                UAI.Clear();
                UAI.AddEverything(false);
                Resources.UnloadUnusedAssets();
                m_Initialized = false;
                Repaint();
            });

            AddMenuItemWithCallback(FileMenu, "Rebuild From Project (include text assets)", () =>
            {
                UAI.Clear();
                UAI.AddEverything(true);
                Resources.UnloadUnusedAssets();
                m_Initialized = false;
                Repaint();
            });
            AddMenuItemWithCallback(FileMenu, "Cleanup References", () =>
            {
                UAI.UpdateReferences();
                Resources.UnloadUnusedAssets();
                m_Initialized = false;
                Repaint();
                EditorUtility.DisplayDialog("Repair", "References cleaned", "OK");
            });

            AddMenuItemWithCallback(FileMenu, "Repair and remove invalid items", () =>
            {
                UAI.RepairAndCleanup();
                Resources.UnloadUnusedAssets();
                m_Initialized = false;
                Repaint();
                EditorUtility.DisplayDialog("Repair", "AssetIndex successfully repaired", "OK");
            });

            /* AddMenuItemWithCallback(FileMenu, "Add Build refs to all non-addressables", () =>
             * {
             *      UAI.AddReferences();
             *      RecountTypes();
             *      Resources.UnloadUnusedAssets();
             *      Repaint();
             * });
             * AddMenuItemWithCallback(FileMenu, "Clear build refs from all items", () =>
             * {
             *      UAI.ClearReferences();
             *      Resources.UnloadUnusedAssets();
             *      RecountTypes();
             *      Repaint();
             * }); */
            FileMenu.AddSeparator("");
            AddMenuItemWithCallback(FileMenu, "Toggle Utilities Panel", () =>
            {
                ShowUtilities = !ShowUtilities;
                Repaint();
            });
            FileMenu.AddSeparator("");

            AddMenuItemWithCallback(FileMenu, "Empty Index", () =>
            {
                UAI.Clear();
                m_Initialized = false;
                Repaint();
            });

#if UMA_ADDRESSABLES
            foreach (IUMAAddressablePlugin plugin in addressablePlugins)
            {
                AddMenuItemWithCallbackParm(_AddressablesMenu, "Generators/" + plugin.Menu, (object o) =>
                {
                    IUMAAddressablePlugin addrplug = o as IUMAAddressablePlugin;
                    UMAAddressablesSupport.Instance.GenerateAddressables(addrplug);
                    Resources.UnloadUnusedAssets();
                    m_Initialized = false;
                    Repaint();
                }, plugin);
            }

            _AddressablesMenu.AddSeparator("Generators/");

            // ***********************************************************************************
            // Addressables Menu items
            // ***********************************************************************************
            AddMenuItemWithCallback(_AddressablesMenu, "Generators/Generate Groups (optimized)", () =>
            {
                UMAAddressablesSupport.Instance.CleanupAddressables();
                UMAAddressablesSupport.Instance.GenerateAddressables();
                Resources.UnloadUnusedAssets();
                m_Initialized = false;
                Repaint();
            });

            /* AddMenuItemWithCallback(AddressablesMenu, "Generators/Generate Shared Group (fast)", () =>
             * {
             *      UAI.CleanupAddressables();
             *      UAI.GenerateSingleGroup();
             *      Resources.UnloadUnusedAssets();
             *      m_Initialized = false;
             *      Repaint();
             * });
             *
             * AddMenuItemWithCallback(AddressablesMenu, "Generators/Generate Shared Group (incl recipes)", () =>
             * {
             *      UAI.CleanupAddressables();
             *      UAI.GenerateSingleGroup(true);
             *      Resources.UnloadUnusedAssets();
             *      m_Initialized = false;
             *      Repaint();
             * }); */

            AddMenuItemWithCallback(_AddressablesMenu, "Remove Addressables", () =>
            {
                UMAAddressablesSupport.Instance.CleanupAddressables(false, true);
                m_Initialized = false;
                Repaint();
            });
            AddMenuItemWithCallback(_AddressablesMenu, "Delete Empty Groups", () =>
            {
                UMAAddressablesSupport.Instance.CleanupAddressables(true);
            });

            /*
             * AddMenuItemWithCallback(AddressablesMenu, "Force Add Refs (Bad!!)", () =>
             * {
             *      UAI.AddReferences(true);
             *      RecountTypes();
             *      Resources.UnloadUnusedAssets();
             *      Repaint();
             * }); */

            AddMenuItemWithCallback(_AddressablesMenu, "Remove Orphaned Slots", () =>
            {
                if (EditorUtility.DisplayDialog("Warning!", "You *must* build the addressable groups, and mark any slots you want to keep as 'keep' before running this!", "OK", "Cancel"))
                {
                    UMAAddressablesSupport.Instance.CleanupOrphans(typeof(SlotDataAsset));
                    m_Initialized = false;
                    Repaint();
                }
            });
            AddMenuItemWithCallback(_AddressablesMenu, "Remove Orphaned Overlays", () =>
            {
                if (EditorUtility.DisplayDialog("Warning!", "You *must* build the addressable groups, and mark any slots you want to keep as 'keep' before running this.", "OK", "Cancel"))
                {
                    UMAAddressablesSupport.Instance.CleanupOrphans(typeof(OverlayDataAsset));
                    m_Initialized = false;
                    Repaint();
                }
            });
#else
            AddMenuItemWithCallback(_AddressablesMenu, "Enable Addressables (Package must be installed first)", () =>
            {
                if (EditorUtility.DisplayDialog("Warning!", "The Addressables Package must be installed first before enabling Addressables support in UMA. Enabling addressables will trigger a recompile during which the library will be unavailable.", "OK", "Cancel"))
                {
                    var defineSymbols = new HashSet <string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup).Split(';'));
                    defineSymbols.Add("UMA_ADDRESSABLES");
                    PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", defineSymbols));
                    m_Initialized = false;
                    Repaint();
                }
            });
#endif
            // ***********************************************************************************
            // Items Menu items
            // ***********************************************************************************
            AddMenuItemWithCallback(ItemsMenu, "Select All", () =>
            {
                var treeElements = new List <AssetTreeElement>();
                TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);
                foreach (AssetTreeElement ate in treeElements)
                {
                    ate.Checked = true;
                }
                treeView.RecalcTypeChecks();
                Repaint();
                return;
            });

            AddMenuItemWithCallback(ItemsMenu, "Clear Selection", () =>
            {
                var treeElements = new List <AssetTreeElement>();
                TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);
                foreach (AssetTreeElement ate in treeElements)
                {
                    ate.Checked = false;
                }
                treeView.RecalcTypeChecks();
                Repaint();
                return;
            });

            foreach (RaceData rc in UAI.GetAllAssets <RaceData>())
            {
                if (rc != null)
                {
                    AddMenuItemWithCallbackParm(ItemsMenu, "Select Slots + Overlays By Race/" + rc.raceName, SelectByRace, rc);
                    AddMenuItemWithCallbackParm(ItemsMenu, "Select Slots By Race/" + rc.raceName, SelectSlotsByRace, rc);
                    AddMenuItemWithCallbackParm(ItemsMenu, "Select Overlays By Race/" + rc.raceName, SelectOverlaysByRace, rc);
                }
            }

            ItemsMenu.AddSeparator("");

            AddMenuItemWithCallback(ItemsMenu, "Add Keep Flag to Selected Items", () =>
            {
                MarkKeep(true);
                Repaint();
                return;
            });

            AddMenuItemWithCallback(ItemsMenu, "Clear Keep Flag from Selected Items", () =>
            {
                MarkKeep(false);
                Repaint();
                return;
            });

            ItemsMenu.AddSeparator("");

            AddMenuItemWithCallback(ItemsMenu, "Remove Selected", () =>
            {
                RemoveSelected();
                m_Initialized = false;
                Repaint();
                return;
            });
            AddMenuItemWithCallback(ItemsMenu, "Force Selected Items to Save", () =>
            {
                ForceSave();
                m_Initialized = false;
                Repaint();
                return;
            });
        }