Beispiel #1
0
 public void RemoveItem()
 {
     Item = null;
     if (image == null)
     {
         return;
     }
     image.sprite  = null;
     image.enabled = false;
 }
    public override bool Equals(object obj)
    {
        if (obj == null || GetType() != obj.GetType())
        {
            return(false);
        }

        ScriptableBase sb = obj as ScriptableBase;

        return(Name.Equals(sb.Name) && Type == sb.Type);
    }
Beispiel #3
0
    private void UpdateUiFromInventory()
    {
        ScriptableBase currentWeapon = mInventory.GetActiveWeaponItem();

        craftingPanel.GetChild(WEAPON_BUTTON_CHILD_NO).GetComponentInChildren <ItemSlot>().AddItem(currentWeapon);
        ScriptableBase curBullet = mInventory.GetActiveBulletItem();

        craftingPanel.GetChild(BULLET_BUTTON_CHILD_NO).GetComponentInChildren <ItemSlot>().AddItem(curBullet);
        ScriptableBase curCore = mInventory.GetActiveCoreItem();

        craftingPanel.GetChild(CORE_BUTTON_CHILD_NO).GetComponentInChildren <ItemSlot>().AddItem(curCore);
    }
Beispiel #4
0
    private void updateInventoryItem(ScriptableBase item, bool removeItem)
    {
        if (item == null)
        {
            Debug.LogWarning("The item you try to add to the UI is null!");
            return;
        }

        int childNo = 0;

        switch (Utils.ConvertCollectableType(item.Type))
        {
        case CraftingType.BULLET:
            childNo = BULLET_SLOTS_CHILD_NO;
            break;

        case CraftingType.WEAPON:
            childNo = WEAPON_SLOTS_CHILD_NO;
            break;

        case CraftingType.CORE:
            childNo = CORE_SLOTS_CHILD_NO;
            break;
        }

        ItemSlot[] itemSlots = inventoryPanel.GetChild(childNo).GetComponentsInChildren <ItemSlot>();

        if (removeItem)
        {
            foreach (ItemSlot slot in itemSlots)
            {
                if (slot.Item.Equals(item))
                {
                    slot.RemoveItem();
                    return;
                }
            }
            Debug.LogWarning("Asked to remove item, but item not found in the inventory slots ....");
        }
        else
        {
            foreach (ItemSlot slot in itemSlots)
            {
                if (slot.IsEmpty())
                {
                    slot.AddItem(item);
                    return;
                }
            }
            Debug.LogError("No empty slots found");
        }
    }
Beispiel #5
0
    private void addOrRemoveCraftingItem(int childNo, ScriptableBase item)
    {
        ItemSlot slot = craftingPanel.GetChild(childNo).GetComponentInChildren <ItemSlot>();

        if (item == null)
        {
            slot.RemoveItem();
        }
        else
        {
            slot.AddItem(item);
        }
    }
Beispiel #6
0
    public void AddItem(ScriptableBase item)
    {
        if (item == null)
        {
            return;
        }

        Item = item;
        if (image != null)
        {
            image.sprite  = Item.Art;
            image.enabled = true;
        }
    }
Beispiel #7
0
 private void removeIventoryItem(ScriptableBase item)
 {
     if (item == null)
     {
         return;
     }
     if (mInventory.ContainsKey(item))
     {
         mInventory.Remove(item);
         OnInventoryItemChanged?.Invoke(this, new InventoryEventArgs()
         {
             itemRemoved = true, Item = item, amount = 0
         });
     }
 }
Beispiel #8
0
    //###############
    //##  HELPERS  ##
    //###############

    private void AddInventoryItem(ScriptableBase item, int amount = 1)
    {
        if (item == null)
        {
            return;
        }

        int newAmount = amount;

        if (mInventory.ContainsKey(item))
        {
            mInventory.TryGetValue(item, out newAmount);
            newAmount += amount;
            mInventory.Remove(item);
        }

        mInventory.Add(item, newAmount);
        OnInventoryItemChanged?.Invoke(this, new InventoryEventArgs()
        {
            Item = item, amount = newAmount
        });
    }
 void DrawScriptableObject(ScriptableBase obj)
 {
     GUILayout.BeginHorizontal();
     GUILayout.Label(obj.name, GUILayout.Width(200));
     GUILayout.EndHorizontal();
 }