示例#1
0
        /// <summary>
        /// Constructor : instatiate the inventory slots
        /// </summary>
        public PlayerInventory(Transform cameraTransform, [CanBeNull] PlayerUIScript ui, PhotonView playerPhotonView, WeaponHolderScript weaponHolder, ConsommableHolderScript consommableHolder)
        {
            playerView             = playerPhotonView;
            camera                 = cameraTransform;
            inventory              = new PlayerInventorySlot[5];
            this.weaponHolder      = weaponHolder;
            this.consommableHolder = consommableHolder;

            playerUI = ui;

            for (var i = 0; i < inventory.Length; i++)
            {
                inventory[i] = new PlayerInventorySlot();
            }
        }
示例#2
0
        public void SwapInventorySlot(int slotIndexSrc, int slotIndexDest)
        {
            //set the current ammo of the weapon in the inventory before the switch
            var currentActive = GetCurrentActive();

            if (currentActive && currentActive.IsWeapon() && weaponHolder.currentWeapon)
            {
                currentActive.GetWeapon().SetCurrentAmmo(weaponHolder.currentWeapon.currentAmmo);
            }

            PlayerInventorySlot tmp = inventory[slotIndexDest];

            inventory[slotIndexDest] = inventory[slotIndexSrc];
            inventory[slotIndexSrc]  = tmp;
            playerUI.SetItemUISlot(inventory[slotIndexSrc].GetItem(), slotIndexSrc);
            playerUI.SetItemUISlot(inventory[slotIndexDest].GetItem(), slotIndexDest);
            SwapActiveIndex(slotIndexSrc);
        }