示例#1
0
 public static void AppendPresetWindowInit(InventoryPreset preset)
 {
     Instance = (AppendPresetWindow)GetWindow(typeof(AppendPresetWindow), false, preset.name);
     Instance.titleContent = new GUIContent(preset.name);
     Instance.minSize      = new Vector2(375f, 200f);
     Instance.maxSize      = new Vector2(375f, Instance.maxSize.y);
     Instance.preset       = preset;
     Instance.ShowUtility();
 }
示例#2
0
 public static void ImportExternalWindowInit(InventoryPreset preset)
 {
     Instance = (ImportExternalWindow)GetWindow(typeof(ImportExternalWindow), false, preset.name);
     Instance.titleContent = new GUIContent(preset.name);
     Instance.minSize      = new Vector2(375f, 100f);
     Instance.maxSize      = new Vector2(375f, 100f);
     Instance.preset       = preset;
     Instance.ShowUtility();
 }
示例#3
0
        private void OnGUI()
        {
            EditorGUILayout.BeginVertical();

            // Header
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Append Settings", EditorStyles.boldLabel);
            DrawLine(false);

            // Preset to Append
            EditorGUI.BeginChangeCheck();
            appendPreset = (InventoryPreset)EditorGUILayout.ObjectField(new GUIContent("Preset to Append", "The Preset to append."), appendPreset, typeof(InventoryPreset), true);
            if (appendPreset != null && (EditorGUI.EndChangeCheck() || (pageNames != null && pageNames.Length != appendPreset.Pages.Count)))
            {
                pageNames = new string[appendPreset.Pages.Count];
                for (int i = 0; i < appendPreset.Pages.Count; i++)
                {
                    pageNames[i] = appendPreset.Pages[i].name;
                }
                selectedPages = new bool[appendPreset.Pages.Count];
            }

            // Page Display and Confirmation
            if (appendPreset != null)
            {
                EditorGUILayout.BeginVertical(new GUIStyle(GUI.skin.GetStyle("Box")));
                EditorGUILayout.BeginHorizontal();

                var r = EditorGUILayout.BeginVertical();
                if (pageNames.Length > 0 && selectedPages.Length > 0)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Add", EditorStyles.boldLabel, GUILayout.MaxWidth(32f));
                    GUILayout.Space(6);
                    EditorGUILayout.LabelField("Pages", EditorStyles.boldLabel);
                    EditorGUILayout.EndHorizontal();
                    // Separator
                    var rect = EditorGUILayout.BeginHorizontal();
                    Handles.color = Color.gray;
                    Handles.DrawLine(new Vector2(rect.x, rect.y + 1), new Vector2(rect.x + rect.width + 5f, rect.y + 1));
                    EditorGUILayout.EndHorizontal();

                    scroll = EditorGUILayout.BeginScrollView(scroll);
                    for (int i = 0; i < pageNames.Length; i++)
                    {
                        if (i != 0)
                        {
                            // Separator
                            rect          = EditorGUILayout.BeginHorizontal();
                            Handles.color = Color.gray;
                            Handles.DrawLine(new Vector2(rect.x, rect.y + 1), new Vector2(rect.x + rect.width + 5f, rect.y + 1));
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(16);
                        selectedPages[i] = EditorGUILayout.Toggle(selectedPages[i], GUILayout.MaxWidth(32f));
                        EditorGUILayout.LabelField(pageNames[i]);
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();

                // Separator
                Handles.color = Color.gray;
                Handles.DrawLine(new Vector2(r.x + 48, r.y), new Vector2(r.x + 48, r.y + r.height));

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.BeginVertical(new GUIStyle(GUI.skin.GetStyle("Box")), GUILayout.MaxHeight(120f));
                GUILayout.FlexibleSpace();
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("<i>No Preset Selected</i>", new GUIStyle(GUI.skin.GetStyle("Box"))
                {
                    richText = true, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState()
                    {
                        textColor = GUI.skin.textField.normal.textColor, background = null
                    }
                }, GUILayout.Height(64f));
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
            }
            GUILayout.FlexibleSpace();

            // Confirm Button
            DrawLine(false);
            EditorGUILayout.Space();
            if (GUILayout.Button("Append"))
            {
                AppendPreset(preset, appendPreset, selectedPages);
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();
        }
示例#4
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");
        }