public void ClearOwner() { _owner = null; _input = null; OnUnequip(); }
public void AssignOwner(GamePlayer owner, PlayerInput input) { _owner = owner; _input = input; OnEquip(); }
protected void UnequipItemFrom(PlayerInput input) { var slot = FindAttachmentSlot(input); if(slot.item == null || !IsItemEquipped(slot.item)) return; Unequip(slot.item); }
protected bool IsAttachmentSlotInputAssigned(PlayerInput input) { return FindAttachmentSlot(input) != null; }
protected AttachmentSlot FindAttachmentSlot(PlayerInput input) { return _attachmentSlots.Find(x => x.input == input); }
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)); }
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); }
/// <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); }
/// <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); }