Example #1
0
    public void EquipWeapon(int _id)
    {
        Transform item = Items[_id];

        if (item.gameObject.activeSelf)
        {
            item.gameObject.SetActive(false);
            equipped = null;
            melee    = true;
        }
        else
        {
            if (equipped != null)
            {
                equipped.gameObject.SetActive(false);
            }
            item.gameObject.SetActive(true);
            weaponData = item.GetComponent <ItemData>().weaponData;
            equipped   = item;
            melee      = weaponData.Melee;
            UpdateSpecs();
        }
    }
    void CheckContents(ItemData object_)
    {
        //ItemData itemDataScript = object_.GetComponent<ItemData>();
        ItemData     itemDataScript = object_;
        ItemDataPack itemPack       = itemDataScript._item;

        ///if the item is a weapon
        if (itemPack.Type == 1)
        {
            WeaponDataPack weaponPack = itemDataScript.weaponData;
            //if item is a primary weapon
            if (weaponPack.WeaponType == 1)
            {
                if (primarySlotOne.transform.childCount == 0)
                {
                    GameObject itemToInstantiate = null;
                    if (itemPack.Type == 1)
                    {
                        itemToInstantiate = itemIconDict[itemPack.Id];
                    }
                    GameObject i = Instantiate(itemToInstantiate);
                    i.transform.SetParent(primarySlotOne.transform);
                    InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>();
                    scrpt.IncreaseStack(itemPack.Amount);
                    return;
                }
                if (primarySlotTwo.transform.childCount == 0)
                {
                    GameObject itemToInstantiate = null;
                    if (itemPack.Type == 1)
                    {
                        itemToInstantiate = itemIconDict[itemPack.Id];
                    }
                    GameObject i = Instantiate(itemToInstantiate);
                    i.transform.SetParent(primarySlotTwo.transform);
                    InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>();
                    scrpt.IncreaseStack(itemPack.Amount);
                    return;
                }
                if (GameData.instance.currentSlot < 2)
                {
                    GameObject itemToInstantiate = null;
                    if (itemPack.Type == 1)
                    {
                        itemToInstantiate = itemIconDict[itemPack.Id];
                    }
                    Destroy(primarySlotOne.transform.GetChild(0).gameObject);
                    GameObject i = Instantiate(itemToInstantiate);
                    i.transform.SetParent(primarySlotOne.transform);
                    InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>();
                    scrpt.IncreaseStack(itemPack.Amount);

                    GameData.instance.weaponHolder.GetComponent <GunControlV2>().EquipWeapon(i);
                    return;
                }
                if (GameData.instance.currentSlot == 2)
                {
                    GameObject itemToInstantiate = null;
                    if (itemPack.Type == 1)
                    {
                        itemToInstantiate = itemIconDict[itemPack.Id];
                    }
                    Destroy(primarySlotTwo.transform.GetChild(0).gameObject);
                    GameObject i = Instantiate(itemToInstantiate);
                    i.transform.SetParent(primarySlotTwo.transform);
                    InventoryStackControl scrpt = i.GetComponent <InventoryStackControl>();
                    scrpt.IncreaseStack(itemPack.Amount);
                    GameData.instance.weaponHolder.GetComponent <GunControlV2>().EquipWeapon(i);
                    return;
                }
            }
            if (weaponPack.WeaponType == 2)
            {
                if (secondarySlot.transform.childCount == 0)
                {
                    return;
                }
            }
            if (weaponPack.WeaponType == 3)
            {
                CheckSlots(object_, explosiveInventory);
                return;
            }
            ////
        }
        else
        {
            CheckSlots(object_, Inventory);
        }
    }