Пример #1
0
        public override void OnInspectorGUI()
        {
            if (skin)
            {
                GUI.skin = skin;
            }
            var assetPath = AssetDatabase.GetAssetPath(target);

            GUILayout.BeginVertical("vItemEnums List", "window");
            GUILayout.Space(30);
            if (assetPath.Contains("Resources"))
            {
                GUILayout.BeginVertical("box");
                base.OnInspectorGUI();
                GUILayout.EndHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("Open ItemEnums Editor"))
                {
                    ItemEnumsWindow.CreateWindow();
                }
                EditorGUILayout.Space();
                if (GUILayout.Button("Refresh ItemEnums"))
                {
                    ItemEnumsBuilder.RefreshItemEnums();
                }

                EditorGUILayout.HelpBox("-This list will be merged with other lists and create the enums.\n- The Enum Generator will ignore equal values.\n- If our change causes errors, check which enum value is missing and adds to the list and press the refresh button.", MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("Please put this list in Resources folder", MessageType.Warning);
            }
            GUILayout.EndVertical();
        }
Пример #2
0
        public static void CreateWindow()
        {
            if (instance == null)
            {
                var window = ItemEnumsWindow.GetWindow <ItemEnumsWindow>("Item Enums", true);
                instance    = window;
                window.skin = Resources.Load("skin") as GUISkin;
                #region Get all vItemType values of current Enum
                try
                {
                    window._itemTypeNames = Enum.GetNames(typeof(ItemType)).vToList();
                }
                catch
                {
                }
                #endregion

                #region Get all vItemAttributes values of current Enum
                try
                {
                    window._itemAttributeNames = Enum.GetNames(typeof(ItemAttributes)).vToList();
                }
                catch
                {
                }
                #endregion
                window.datas   = Resources.LoadAll <ItemEnumsList>("");
                window.minSize = new Vector2(460, 600);
            }
        }
Пример #3
0
        public void OnGUI()
        {
            if (skin)
            {
                GUI.skin = skin;
            }

            GUILayout.BeginVertical("Item List", "window");
            GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
            GUILayout.Space(10);

            GUILayout.BeginVertical("box");

            GUI.enabled = !Application.isPlaying;
            itemList    = EditorGUILayout.ObjectField("ItemListData", itemList, typeof(ItemListData), false) as ItemListData;

            if (serializedObject == null && itemList != null)
            {
                serializedObject = new SerializedObject(itemList);
            }
            else if (itemList == null)
            {
                GUILayout.EndVertical();
                return;
            }

            serializedObject.Update();

            if (!inAddItem && GUILayout.Button("Create New Item"))
            {
                addItem      = ScriptableObject.CreateInstance <Item>();
                addItem.name = "New Item";

                currentItemDrawer = null;
                inAddItem         = true;
            }
            if (inAddItem)
            {
                DrawAddItem();
            }
            if (GUILayout.Button("Open ItemEnums Editor"))
            {
                ItemEnumsWindow.CreateWindow();
            }
            GUILayout.Space(10);
            GUILayout.EndVertical();

            GUILayout.Box(itemList.items.Count.ToString("00") + " Items");
            scroolView = GUILayout.BeginScrollView(scroolView, GUILayout.ExpandWidth(true));
            for (int i = 0; i < itemList.items.Count; i++)
            {
                if (itemList.items[i] != null)
                {
                    Color color = GUI.color;
                    GUI.color = currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? Color.green : color;
                    GUILayout.BeginVertical("box");
                    GUI.color = color;
                    GUILayout.BeginHorizontal();
                    var      texture  = itemList.items[i].iconTexture;
                    var      name     = " ID " + itemList.items[i].id.ToString("00") + "\n - " + itemList.items[i].name + "\n - " + itemList.items[i].type.ToString();
                    var      content  = new GUIContent(name, texture, currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? "Click to Close" : "Click to Open");
                    GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
                    GUI.skin.box.alignment = TextAnchor.UpperLeft;
                    GUI.skin.box.fontStyle = FontStyle.Italic;
                    GUI.skin.box.fontSize  = 11;

                    if (GUILayout.Button(content, "box", GUILayout.Height(50), GUILayout.MinWidth(50)))
                    {
                        GUI.FocusControl("clearFocus");
                        scroolView.y      = 1 + i * 60;
                        currentItemDrawer = currentItemDrawer != null ? currentItemDrawer.item == itemList.items[i] ? null : new vItemDrawer(itemList.items[i]) : new vItemDrawer(itemList.items[i]);
                    }
                    EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

                    GUI.skin.box = boxStyle;
                    var duplicateImage = Resources.Load("duplicate") as Texture;
                    if (GUILayout.Button(new GUIContent("", duplicateImage, "Duplicate Item"), GUILayout.MaxWidth(45), GUILayout.Height(45)))
                    {
                        if (EditorUtility.DisplayDialog("Duplicate the " + itemList.items[i].name,
                                                        "Are you sure you want to duplicate this item? ", "Duplicate", "Cancel"))
                        {
                            DuplicateItem(itemList.items[i]);
                            GUILayout.EndHorizontal();
                            Repaint();
                            break;
                        }
                    }
                    if (GUILayout.Button(new GUIContent("x", "Delete Item"), GUILayout.MaxWidth(20), GUILayout.Height(45)))
                    {
                        if (EditorUtility.DisplayDialog("Delete the " + itemList.items[i].name,
                                                        "Are you sure you want to delete this item? ", "Delete", "Cancel"))
                        {
                            var item = itemList.items[i];
                            itemList.items.RemoveAt(i);
                            DestroyImmediate(item, true);
                            OrderByID();
                            AssetDatabase.SaveAssets();
                            serializedObject.ApplyModifiedProperties();
                            EditorUtility.SetDirty(itemList);
                            GUILayout.EndHorizontal();
                            Repaint();
                            break;
                        }
                    }

                    GUILayout.EndHorizontal();

                    GUI.color = color;
                    if (currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] && itemList.items.Contains(currentItemDrawer.item))
                    {
                        currentItemDrawer.DrawItem(ref itemList.items, false);
                    }

                    GUILayout.EndVertical();
                }
            }
            GUILayout.EndScrollView();

            GUILayout.EndVertical();
            if (GUI.changed || serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.SetDirty(itemList);
            }
        }