Пример #1
0
        // Appends pages from one preset to the current one.
        private static void AppendPreset(InventoryPreset preset, InventoryPreset appendPreset, bool[] selectedPages)
        {
            // Null checks
            if (appendPreset == null || preset == null)
            {
                EditorUtility.DisplayDialog("Inventory Inventor", "ERROR: No preset selected.", "Close");
                return;
            }

            // Append to Preset
            string      _path    = AssetDatabase.GetAssetPath(preset.GetInstanceID());
            List <Page> newPages = new List <Page>();
            List <Page> oldPages = appendPreset.Pages;

            for (int i = 0; i < oldPages.Count; i++)
            {
                if (selectedPages[i])
                {
                    Page newPage = DeepClonePage(oldPages[i]);
                    newPages.Add(newPage);
                    AssetDatabase.AddObjectToAsset(newPage, _path);
                    foreach (PageItem item in newPage.Items)
                    {
                        AssetDatabase.AddObjectToAsset(item, _path);
                        foreach (GroupItem groupItem in item.ButtonGroup)
                        {
                            AssetDatabase.AddObjectToAsset(groupItem, _path);
                        }
                        foreach (GroupItem groupItem in item.EnableGroup)
                        {
                            AssetDatabase.AddObjectToAsset(groupItem, _path);
                        }
                        foreach (GroupItem groupItem in item.DisableGroup)
                        {
                            AssetDatabase.AddObjectToAsset(groupItem, _path);
                        }
                    }
                }
            }

            // Correct references
            foreach (Page page in newPages)
            {
                foreach (PageItem item in page.Items)
                {
                    item.PageReference = FindClonedPage(item.PageReference, ref newPages);
                    foreach (GroupItem groupItem in item.ButtonGroup)
                    {
                        groupItem.Item = FindClonedItem(groupItem.Item, ref newPages, ref oldPages);
                    }
                    foreach (GroupItem groupItem in item.EnableGroup)
                    {
                        groupItem.Item = FindClonedItem(groupItem.Item, ref newPages, ref oldPages);
                    }
                    foreach (GroupItem groupItem in item.DisableGroup)
                    {
                        groupItem.Item = FindClonedItem(groupItem.Item, ref newPages, ref oldPages);
                    }
                }
            }

            // Deal with Pages with the same name
            List <string> oldNames = new List <string>();

            foreach (Page page in preset.Pages)
            {
                oldNames.Add(page.name);
            }
            for (int i = 0; i < newPages.Count; i++)
            {
                List <string> newNames = new List <string>();
                foreach (Page newPage in newPages)
                {
                    if (newPage != newPages[i])
                    {
                        newNames.Add(newPage.name);
                    }
                }
                if (oldNames.Contains(newPages[i].name) || newNames.Contains(newPages[i].name))
                {
                    int occurance = 0;
                    while (oldNames.Contains(newPages[i].name + " " + occurance) || newNames.Contains(newPages[i].name + " " + occurance))
                    {
                        occurance++;
                    }
                    newPages[i].name = newPages[i].name + " " + occurance;
                }
            }


            // Save changes
            preset.Pages.AddRange(newPages);
            InventoryPresetUtility.SaveChanges(preset);
            if (Instance != null)
            {
                Instance.Close();
            }
            EditorUtility.DisplayDialog("Inventory Inventor", "All menus imported successfully.", "Close");
        }
Пример #2
0
        // Converts and imports the menus.
        private void ImportMenus()
        {
            // Null checks
            if (importMenu == null)
            {
                EditorUtility.DisplayDialog("Inventory Inventor", "ERROR: No menu selected.", "Close");
                return;
            }
            else if (preset == null)
            {
                EditorUtility.DisplayDialog("Inventory Inventor", "ERROR: No preset selected.", "Close");
                return;
            }

            // Identify menus
            List <VRCExpressionsMenu> allMenus = new List <VRCExpressionsMenu>();

            if (enableRecursion)
            {
                FindMenus(importMenu, ref allMenus);
            }
            else
            {
                allMenus.Add(importMenu);
            }

            // Convert menus
            List <Page> newPages = new List <Page>();

            foreach (VRCExpressionsMenu menu in allMenus)
            {
                newPages.Add(ConvertMenu(menu));
            }

            // Update Page references (if needed)
            if (enableRecursion)
            {
                foreach (Page page in newPages)
                {
                    foreach (PageItem item in page.Items)
                    {
                        if (item.Control.type == VRCExpressionsMenu.Control.ControlType.SubMenu && item.Control.subMenu != null)
                        {
                            item.Type          = PageItem.ItemType.Subpage;
                            item.PageReference = newPages[allMenus.IndexOf(item.Control.subMenu)];
                        }
                    }
                }
            }

            // Append to Preset
            string _path = AssetDatabase.GetAssetPath(preset.GetInstanceID());

            foreach (Page page in newPages)
            {
                page.hideFlags = HideFlags.HideInHierarchy;
                AssetDatabase.AddObjectToAsset(page, _path);
                foreach (PageItem item in page.Items)
                {
                    item.hideFlags = HideFlags.HideInHierarchy;
                    AssetDatabase.AddObjectToAsset(item, _path);
                }
            }
            preset.Pages.AddRange(newPages);

            // Save changes
            InventoryPresetUtility.SaveChanges(preset);
            Close();
            EditorUtility.DisplayDialog("Inventory Inventor", "All menus imported successfully.", "Close");
        }