示例#1
0
        public void ClearOwner()
        {
            _owner = null;
            _input = null;

            OnUnequip();
        }
示例#2
0
        public void AssignOwner(GamePlayer owner, PlayerInput input)
        {
            _owner = owner;
            _input = input;

            OnEquip();
        }
示例#3
0
        protected void UnequipItemFrom(PlayerInput input)
        {
            var slot = FindAttachmentSlot(input);
            if(slot.item == null || !IsItemEquipped(slot.item))
                return;

            Unequip(slot.item);
        }
示例#4
0
 protected bool IsAttachmentSlotInputAssigned(PlayerInput input)
 {
     return FindAttachmentSlot(input) != null;
 }
示例#5
0
 protected AttachmentSlot FindAttachmentSlot(PlayerInput input)
 {
     return _attachmentSlots.Find(x => x.input == input);
 }
示例#6
0
        protected void Equip(PlayerInput input, UsableItem item, bool unequipIfOccupied = false)
        {
            if (item.isInUse)
            {
                Debug.LogError("GamePlayer: Trying to equip an item that is already in use!");
                return;
            }

            if (!isLocalPlayer)
            {
                Debug.LogError("GamePlayer: GamePlayer.Equip(input, item, unequipIfOccupied) can't be called from non local clients!");
                return;
            }

            var slot = FindAttachmentSlot(input);
            if(slot == null) {
                Debug.LogWarning("GamePlayer: Trying to add an item to a non existant attachment slot");
                return;
            }

            // already an item equipped to that slot
            if(slot.item != null && unequipIfOccupied) {
                // unequip the current item
                // todo: can we be sure that unequip will be executed on
                //       all clients?
                Unequip(slot.item);
            }

            // notify everyone about the equipped item
            CmdOnEquip(item.gameObject, GetSlotIndex(slot));
        }
示例#7
0
        protected void AddAttachmentSlot(GameObject attachPoint, PlayerInput input = null)
        {
            if (FindAttachmentSlot(attachPoint) != null)
            {
                Debug.LogError("GamePlayer: Trying to add an attachment point that is already assigned to an attachment slot!");
                return;
            }

            if (input != null && IsAttachmentSlotInputAssigned(input))
            {
                Debug.LogError("GamePlayer: Trying to add a a player input that is already assign to an attachment slot!");
                return;
            }

            var attachmentSlot = new AttachmentSlot();
            attachmentSlot.attachPoint = attachPoint;
            attachmentSlot.input = input;

            _attachmentSlots.Add(attachmentSlot);
        }
示例#8
0
 /// <summary>
 /// Called when ever one of our controllers picks up a UsableItem
 /// </summary>
 /// <param name="input"></param>
 /// <param name="item"></param>
 void ItemPickedUp(PlayerInput input, UsableItem item)
 {
     Equip(input, item, false);
 }
示例#9
0
 /// <summary>
 /// Called when ever one of our controllers drops a UsableItem
 /// </summary>
 /// <param name="input"></param>
 /// <param name="item"></param>
 void ItemDropped(PlayerInput input, UsableItem item)
 {
     Unequip(item);
 }