private void RemoveSelected()
        {
            var treeElements = new List <AssetTreeElement>();

            TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);

            EditorUtility.DisplayProgressBar("Removing Assets", "Finding and removing selected assets", 0.0f);

            float total = 0.0f;

            foreach (AssetTreeElement tr in treeElements)
            {
                if (tr.ai != null && tr.Checked)
                {
                    total += 1.0f;
                }
            }

            if (total > 0.0f)
            {
                float current = 0.0f;
                foreach (AssetTreeElement tr in treeElements)
                {
                    if (tr.ai != null && tr.Checked)
                    {
                        EditorUtility.DisplayProgressBar("Removing Assets", "Removing Item: " + tr.ai.EvilName, current / total);
                        UAI.RemoveAsset(tr.ai._Type, tr.ai._Name);
                        current += 1.0f;
                    }
                }
            }
            EditorUtility.DisplayProgressBar("Removing Assets", "Save Index to Disk", 1.0f);
            UAI.ForceSave();
            EditorUtility.ClearProgressBar();
        }
        public void RecountTypes()
        {
            var treeElements = new List <AssetTreeElement>();

            TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);

            List <AssetTreeElement> Types = new List <AssetTreeElement>();

            foreach (TreeElement t in treeView.treeModel.root.children)
            {
                AssetTreeElement ate = t as AssetTreeElement;
                ate.IsResourceCount = 0;
                ate.IsAddrCount     = 0;
                ate.Keepcount       = 0;
                if (t.hasChildren)
                {
                    foreach (TreeElement c in t.children)
                    {
                        AssetItem ai = (c as AssetTreeElement).ai;
                        if (ai.IsResource)
                        {
                            ate.IsResourceCount++;
                        }
                        if (ai.IsAlwaysLoaded)
                        {
                            ate.Keepcount++;
                        }
                        if (ai.IsAddressable)
                        {
                            ate.IsAddrCount++;
                        }
                    }
                }
            }
        }
        private void ForceSave()
        {
            var treeElements = new List <AssetTreeElement>();

            TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);

            EditorUtility.DisplayProgressBar("Marking Assets", "Finding and marking selected assets", 0.0f);

            float total = 0.0f;

            foreach (AssetTreeElement tr in treeElements)
            {
                if (tr.ai != null && tr.Checked)
                {
                    total += 1.0f;
                }
            }

            if (total > 0.0f)
            {
                float current = 0.0f;
                foreach (AssetTreeElement tr in treeElements)
                {
                    if (tr.ai != null && tr.Checked)
                    {
                        EditorUtility.DisplayProgressBar("Marking Assets", "Marking Item: " + tr.ai.EvilName, current / total);
                        EditorUtility.SetDirty(tr.ai.Item);
                        current += 1.0f;
                    }
                }
            }
            EditorUtility.DisplayProgressBar("Saving Assets", "Save Assets to Disk", 1.0f);
            AssetDatabase.SaveAssets();
            EditorUtility.ClearProgressBar();
        }
Beispiel #4
0
        public void AddElements(IList <T> elements, TreeElement parent, int insertPosition)
        {
            if (elements == null)
            {
                throw new ArgumentNullException("elements", "elements is null");
            }
            if (elements.Count == 0)
            {
                throw new ArgumentNullException("elements", "elements Count is 0: nothing to add");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent", "parent is null");
            }

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

            parent.children.InsertRange(insertPosition, elements.Cast <TreeElement> ());
            foreach (var element in elements)
            {
                element.parent = parent;
                element.depth  = parent.depth + 1;
                TreeElementUtility.UpdateDepthValues(element);
            }

            TreeElementUtility.TreeToList(m_Root, m_Data);

            Changed();
        }
        void UpdateMaterials()
        {
            var treeElements = new List <AssetTreeElement>();

            TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);

            foreach (AssetTreeElement ate in treeElements)
            {
                if (ate.ai != null && ate.Checked)
                {
                    SetItemMaterial(ate.ai);
                }
            }
        }
        void SelectByAssetItems(List <AssetItem> items)
        {
            var treeElements = new List <AssetTreeElement>();

            TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);

            foreach (AssetTreeElement ate in treeElements)
            {
                if (ate.ai != null && items.Contains(ate.ai))
                {
                    ate.Checked = true;
                }
            }
            treeView.RecalcTypeChecks();
        }
        void MarkKeep(bool Keep)
        {
            var treeElements = new List <AssetTreeElement>();

            TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);

            foreach (AssetTreeElement tr in treeElements)
            {
                if (tr.ai != null && tr.Checked)
                {
                    tr.ai.IsAlwaysLoaded = Keep;
                }
            }
            UMAAssetIndexer.Instance.ForceSave();
            RecountTypes();
        }
        void SearchBar(Rect rect)
        {
            Rect DropDown = new Rect(rect);

            DropDown.width = 150;

            int newLoadedItems = EditorGUI.Popup(DropDown, LoadedItems, LoadedValues);

            if (newLoadedItems != LoadedItems)
            {
                LoadedItems = newLoadedItems;
                if ((eLoaded)LoadedItems == eLoaded.SelectedOnly)
                {
                    LoadOnly.Clear();
                    var treeElements = new List <AssetTreeElement>();
                    TreeElementUtility.TreeToList <AssetTreeElement>(treeView.treeModel.root, treeElements);
                    foreach (AssetTreeElement ate in treeElements)
                    {
                        if (ate.ai != null && ate.Checked)
                        {
                            LoadOnly.Add(ate.ai);
                        }
                    }
                    treeView.ExpandAll();
                }
                m_Initialized = false;
                Repaint();
            }

            DropDown.x    += DropDown.width;
            DropDown.width = 110;

            int newShowIndex = EditorGUI.Popup(DropDown, ShowIndex, ShowTypes);

            if (newShowIndex != ShowIndex)
            {
                ShowIndex     = newShowIndex;
                m_Initialized = false;
                Repaint();
            }

            rect.x                = DropDown.x + DropDown.width;
            rect.width           -= rect.x;
            treeView.searchString = m_SearchField.OnGUI(rect, treeView.searchString);
        }
Beispiel #9
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 #10
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 #11
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;
            });
        }