public override void OnGUI(string searchContext)
        {
            m_InventorSettings.Update();

            // Auto Update
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(Styles.autoUpdate, new GUILayoutOption[] { GUILayout.MinWidth(160f) });
            m_InventorSettings.FindProperty("m_AutoUpdate").boolValue = !Convert.ToBoolean(GUILayout.Toolbar(Convert.ToInt32(!m_InventorSettings.FindProperty("m_AutoUpdate").boolValue), new string[] { "Yes", "No" }, new GUILayoutOption[] { GUILayout.MinWidth(128f), GUILayout.MaxWidth(384f) }));
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(2);

            // Auto Update
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(Styles.allowInvalid, new GUILayoutOption[] { GUILayout.MinWidth(160f) });
            m_InventorSettings.FindProperty("m_AllowInvalid").boolValue = !Convert.ToBoolean(GUILayout.Toolbar(Convert.ToInt32(!m_InventorSettings.FindProperty("m_AllowInvalid").boolValue), new string[] { "Yes", "No" }, new GUILayoutOption[] { GUILayout.MinWidth(128f), GUILayout.MaxWidth(384f) }));
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(4);

            // Default Path
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(Styles.defaultPath, new GUILayoutOption[] { GUILayout.MinWidth(160f) });
            EditorGUI.BeginChangeCheck();
            m_InventorSettings.FindProperty("m_DefaultPath").stringValue = EditorGUILayout.TextField(m_InventorSettings.FindProperty("m_DefaultPath").stringValue, new GUILayoutOption[] { GUILayout.MinWidth(128f), GUILayout.MaxWidth(384f) });
            if (EditorGUI.EndChangeCheck() && !m_InventorSettings.FindProperty("m_DefaultPath").stringValue.StartsWith("Assets"))
            {
                m_InventorSettings.FindProperty("m_DefaultPath").stringValue = k_InventorSettingsPath.Substring(0, k_InventorSettingsPath.LastIndexOf("Editor") - 1) + Path.DirectorySeparatorChar + "Output";
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            // Upgrade All
            DrawLine(false);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Space(4f);
            if (GUILayout.Button(Styles.upgradeButton, GUILayout.MaxWidth(512f)))
            {
                InventoryPresetUtility.UpgradeAll(true);
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            m_InventorSettings.ApplyModifiedProperties();
        }
Пример #2
0
        private static void OnScriptsReloaded()
        {
            if (InventorSettings.GetSerializedSettings().FindProperty("m_Updating").boolValue)
            {
                // Get Main Path
                string mainPath = GetSettingsPath().Substring(0, GetSettingsPath().LastIndexOf("Editor") - 1);

                // Upgrade Presets
                InventoryPresetUtility.UpgradeAll(false);

                // Display Changes
                if (File.Exists(mainPath + "/CHANGES.md"))
                {
                    EditorApplication.update += OnUpdatedUpdate;
                }

                // Disable Updating Flag
                var settings = InventorSettings.GetSerializedSettings();
                settings.FindProperty("m_Updating").boolValue = false;
                settings.ApplyModifiedProperties();
            }
        }
Пример #3
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");
        }
Пример #4
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");
        }