void AddAndRemove() { myDatabase.AddItem(bubble); Assert.AreEqual(1, myDatabase.Count); myDatabase.RemoveItem("Bubble"); Assert.AreEqual(0, myDatabase.Count); }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) { //request item by ID itemDatabase.AddItem(0, this); } else if (Input.GetKeyDown(KeyCode.R)) { itemDatabase.RemoveItem(0, this); } }
public override void OnInspectorGUI() { GUILayout.BeginHorizontal(); if (GUILayout.Button("<<")) { itemDatabase.PreviousItem(); } if (GUILayout.Button(">>")) { itemDatabase.NextItem(); } GUILayout.EndHorizontal(); if (GUILayout.Button("New Item")) { itemDatabase.CreateItem(); } if (GUILayout.Button("Remove Item")) { itemDatabase.RemoveItem(); } base.OnInspectorGUI(); }
public void removeItem(Item item) { inventory.RemoveItem(item); }
void OnGUI() { /* * Editor toolbar. */ // Button row. EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Create New Item", GUILayout.Width(300.0f))) { // Create a new item... editorState = EditorState.Create; return; } if (GUILayout.Button("Reload Database", GUILayout.Width(300.0f))) { itemDatabase.ReloadDatabase(); _conditionDatabase.ReloadDatabase(); _perkDatabase.ReloadDatabase(); return; } if (GUILayout.Button("Save to JSON", GUILayout.Width(300))) { // Delete this item from the database. itemDatabase.SaveDatabase(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } EditorGUILayout.EndHorizontal(); // Filter row. EditorGUILayout.BeginHorizontal(); filterType = (ItemType)EditorGUILayout.EnumPopup("Show Type: ", filterType); filterTypeToggle = EditorGUILayout.Toggle(filterTypeToggle); EditorGUILayout.EndHorizontal(); // Kill the script before a null pointer exception is thrown (ugh why). if (itemDatabase == null || itemDatabase.Items == null) { EditorGUILayout.LabelField("The database may need reloading."); return; } EditorGUILayout.BeginHorizontal(); // List all of the items on the left hand side. listScrollPos = EditorGUILayout.BeginScrollView(listScrollPos, false, false, GUILayout.Width(450), GUILayout.MinHeight(550)); foreach (GameItem i in itemDatabase.Items) { // Filter if necessary. if (filterTypeToggle) { if (i.ItemType != filterType) { continue; } } // Horizontal group per item. EditorGUILayout.BeginHorizontal(GUILayout.Width(400)); if (GUILayout.Button("X", GUILayout.Width(50.0f))) { // Delete this item from the database. itemDatabase.RemoveItem(i); EditorUtility.SetDirty(itemDatabase); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = itemDatabase; return; } if (GUILayout.Button("C", GUILayout.Width(50.0f))) { // Duplicate this item. itemDatabase.DuplicateItem(i); EditorUtility.SetDirty(itemDatabase); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = itemDatabase; return; } if (GUILayout.Button(i.ItemName.ToString(), GUILayout.Width(300))) { if (editorState == EditorState.Edit) { SaveExistingItem(selectedItem.ItemType); } else if (editorState == EditorState.Create) { SaveNewItem(itemType); } //Get the new item and its associated data. selectedItem = i; GetItemData(); EditorUtility.FocusProjectWindow(); Selection.activeObject = itemDatabase; editorState = EditorState.Edit; return; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); if (editorState == EditorState.Create || editorState == EditorState.Edit) { ShowCreateWindow(); } EditorGUILayout.EndHorizontal(); }