public static void CreateWindow(ItemListData itemList, int firtItemSelected) { ItemListWindow window = (ItemListWindow)EditorWindow.GetWindow(typeof(ItemListWindow), false, "ItemList Editor"); Instance = window; window.itemList = itemList; window.skin = Resources.Load("skin") as GUISkin; Instance.Init(firtItemSelected); }
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); } }
static void CreateNewListData() { ItemListData listData = ScriptableObject.CreateInstance <ItemListData>(); AssetDatabase.CreateAsset(listData, "Assets/ItemListData.asset"); }
void OnEnable() { itemList = (ItemListData)target; // skin = Resources.Load("skin") as GUISkin; // m_Logo = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D)); }