Пример #1
0
        void OnGUI()
        {
            if (!skin)
            {
                skin = Resources.Load("skin") as GUISkin;
            }
            GUI.skin = skin;

            this.minSize      = rect;
            this.titleContent = new GUIContent("Inventory System", null, "ItemManager Creator Window");

            GUILayout.BeginVertical("ItemManager Creator Window", "window");
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUILayout.BeginVertical("box");

            inventoryPrefab = EditorGUILayout.ObjectField("Inventory Prefab: ", inventoryPrefab, typeof(vInventory), false) as vInventory;
            itemListData    = EditorGUILayout.ObjectField("Item List Data: ", itemListData, typeof(vItemListData), false) as vItemListData;

            if (inventoryPrefab != null && inventoryPrefab.GetComponent <vInventory>() == null)
            {
                EditorGUILayout.HelpBox("Please select a Inventory Prefab that contains the vInventory script", MessageType.Warning);
            }

            GUILayout.EndVertical();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("Need to know how it works?");
            if (GUILayout.Button("Video Tutorial"))
            {
                //Application.OpenURL("https://www.youtube.com/watch?v=1aA_PU9-G-0&index=3&list=PLvgXGzhT_qehtuCYl2oyL-LrWoT7fhg9d");
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (inventoryPrefab != null && itemListData != null)
            {
                if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent <vThirdPersonController>() != null)
                {
                    if (GUILayout.Button("Create"))
                    {
                        Create();
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Please select the Player to add this component", MessageType.Warning);
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
Пример #2
0
        public static void CreateWindow(vItemListData itemList, int firtItemSelected)
        {
            vItemListWindow window = (vItemListWindow)EditorWindow.GetWindow(typeof(vItemListWindow), false, "ItemList Editor");

            Instance        = window;
            window.itemList = itemList;
            window.skin     = Resources.Load("skin") as GUISkin;
            Instance.Init(firtItemSelected);
        }
Пример #3
0
        static void CreateNewListData()
        {
            vItemListData listData = ScriptableObject.CreateInstance <vItemListData>();

            AssetDatabase.CreateAsset(listData, "Assets/ItemListData.asset");
        }
Пример #4
0
 void OnEnable()
 {
     itemList = (vItemListData)target;
     skin     = Resources.Load("skin") as GUISkin;
     m_Logo   = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D));
 }
Пример #5
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(vItemListData), false) as vItemListData;

            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 <vItem>();
                addItem.name = "New Item";

                currentItemDrawer = null;
                inAddItem         = true;
            }
            if (inAddItem)
            {
                DrawAddItem();
            }
            if (GUILayout.Button("Open ItemEnums Editor"))
            {
                vItemEnumsWindow.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);
            }
        }