Exemple #1
0
        /// <summary>
        /// Remove slot from group including weapon contained in this slot.
        /// </summary>
        public virtual bool RemoveSlotFromGroup(string groupName, KeyCode key)
        {
            if (string.IsNullOrEmpty(groupName) || !cacheGroupToSlots.ContainsKey(groupName))
            {
                return(false);
            }

            for (int i = 0, length = groups.Count; i < length; i++)
            {
                InventoryGroup group = groups[i];
                if (group.GetName() == groupName)
                {
                    for (int j = 0, _length = group.GetInventorySlotsLength(); j < _length; j++)
                    {
                        InventorySlot slot = group.GetInventorySlot(j);
                        if (slot.GetKey() == key)
                        {
                            if (currentWeaponKey == slot.GetKey())
                            {
                                HideWeapon(true);
                                currentWeaponKey = KeyCode.None;
                            }
                            groups[i].GetInventorySlots().RemoveAt(j);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Weapon count.
        /// </summary>
        /// <returns></returns>
        public virtual int WeaponCount()
        {
            int count = 0;

            for (int i = 0, length = groups.Count; i < length; i++)
            {
                InventoryGroup group = groups[i];
                for (int j = 0, _length = group.GetInventorySlotsLength(); j < length; j++)
                {
                    InventorySlot slot = group.GetInventorySlot(i);
                    if (slot.GetWeapon() != null)
                    {
                        count++;
                    }
                }
            }
            return(count);
        }
Exemple #3
0
        protected virtual void SelectWeaponByKey()
        {
            if (!Input.anyKeyDown || (switchWeaponAnimation != null || hideWeaponAnimation != null) || Input.GetKeyDown(currentWeaponKey))
            {
                return;
            }

            for (int i = 0, length = groups.Count; i < length; i++)
            {
                InventoryGroup group = groups[i];
                for (int j = 0, _length = group.GetInventorySlotsLength(); j < _length; j++)
                {
                    InventorySlot slot = group.GetInventorySlot(j);
                    if (Input.GetKeyDown(slot.GetKey()))
                    {
                        if (slot.GetWeapon() == null)
                        {
                            break;
                        }
                        ActivateWeapon(slot.GetKey());
                    }
                }
            }
        }