Beispiel #1
0
 public void OnAfterSerialize()
 {
     Inventory.Reset();
     for (int i = 0; i < _serializedInventoryItems.Length; i++)
     {
         Inventory.AddItem(_serializedInventoryItems[i],
                           _serializedInventoryQuantities[i]);
     }
 }
Beispiel #2
0
    /// <summary>
    /// Display the Model in the Editor.</summary>
    void DrawInventory(BaseInventory inventory)
    {
        var items      = inventory.Items.GetEnumerator();
        var quantities = inventory.Quantities.GetEnumerator();

        while (items.MoveNext() && quantities.MoveNext())
        {
            EditorGUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField(ItemDatabase.GetItemById(items.Current).Name, GUILayout.Width(133));
            EditorGUILayout.LabelField("x" + quantities.Current.ToString(), GUILayout.Width(30));

            if (GUILayout.Button("+", GUILayout.Width(18)))
            {
                inventory.AddItem(items.Current, 1);
                EditorUtility.SetDirty(target);
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("-", GUILayout.Width(18)))
            {
                inventory.RemoveItem(items.Current, 1);
                EditorUtility.SetDirty(target);
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("X", GUILayout.Width(18)))
            {
                inventory.RemoveItem(items.Current, quantities.Current);
                EditorUtility.SetDirty(target);
                EditorGUILayout.EndHorizontal();
                break;
            }
            else
            {
                EditorGUILayout.EndHorizontal();
            }
        }

        //if (GUILayout.Button("Reset"))
        //{
        //    inventory.Reset();
        //    EditorUtility.SetDirty(inventory);
        //}
    }
    /// <summary>
    /// Display the Model in the Editor.</summary>
    void DrawInventory(BaseInventory inventory, Loot loot)
    {
        for (int i = 0; i < loot._serializedInventoryItems.Length; i++)
        {
            int item     = loot._serializedInventoryItems[i];
            int quantity = loot._serializedInventoryQuantities[i];

            EditorGUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField(ItemDatabase.GetItemById(item).Name, GUILayout.Width(133));
            EditorGUILayout.LabelField("x" + quantity.ToString(), GUILayout.Width(30));

            if (GUILayout.Button("+", GUILayout.Width(18)))
            {
                inventory.AddItem(item, 1);
                EditorUtility.SetDirty(target);
                loot.OnBeforeSerialize();
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("-", GUILayout.Width(18)))
            {
                inventory.RemoveItem(item, 1);
                EditorUtility.SetDirty(target);
                loot.OnBeforeSerialize();
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("X", GUILayout.Width(18)))
            {
                inventory.RemoveItem(item, quantity);
                EditorUtility.SetDirty(target);
                loot.OnBeforeSerialize();
                EditorGUILayout.EndHorizontal();
                break;
            }
            else
            {
                EditorGUILayout.EndHorizontal();
            }
        }
    }