public void Swap(SlottableItem item) { SlottableItem currentItem = Item; SlottableItem draggedItem = item; if (draggedItem == null || currentItem == draggedItem) { return; } var oldSlot = draggedItem.Slot; if (IsFree && AcceptsItem(draggedItem) && draggedItem.AcceptsSlot(this)) { Drop(draggedItem); oldSlot.Clear(); return; } // Items need to be swapped if (AcceptsItem(draggedItem) && oldSlot.AcceptsItem(currentItem) && draggedItem.AcceptsSlot(this) && currentItem.AcceptsSlot(oldSlot)) { Drop(draggedItem); oldSlot.Drop(currentItem); } }
public void Clear() { SlottableItem oldItem = Item; Item = null; ExecuteEvents.ExecuteHierarchy <ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, null, oldItem)); }
public bool AcceptsItem(SlottableItem item) { if (AcceptedItemType == "" || AcceptedItemType == item.Item.GetType().Name) { return(true); } return(false); }
/// <summary> /// Weather the Slot accepts the given Item.</summary> public override bool AcceptsItem(SlottableItem item) { if (_acceptedItemType == "" || _acceptedItemType == item.Data.GetType().Name) { return true; } return false; }
/// <summary> /// Add an Item to the next available Slot.</summary> public virtual void AddItem(SlottableItem item) { Slot slot = NextAvailableSlot(); if (slot != null) { slot.Drop(item); } }
/// <summary> /// Add an Item to the next available Slot.</summary> public void AddItem(SlottableItem item) { Slot slot = NextAvailableSlot(); if (slot != null) { slot.Drop(item); } }
/// <summary> /// Drop an Item onto this Slot.</summary> public void Drop(SlottableItem item) { var oldItem = _item; var newItem = item; item.transform.SetParent(transform); item.FitIntoSlot(); ExecuteEvents.ExecuteHierarchy<ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, newItem, oldItem)); _item = item; _item._slot = this; }
/// <summary> /// Drop an Item onto this Slot.</summary> public void Drop(SlottableItem item) { var oldItem = Item; var newItem = item; item.transform.SetParent(transform); item.FitIntoSlot(); ExecuteEvents.ExecuteHierarchy <ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, newItem, oldItem)); Item = item; Item.Slot = this; }
public void OnBeginDrag(PointerEventData eventData) { if (!Slot.AllowsDrag) { return; } _canvas = GetComponentInParent <Canvas>(); DraggedItem = this; _startSlot = Slot; _canvasGroup.blocksRaycasts = false; transform.SetParent(GetComponentInParent <Canvas>().transform); }
/// <summary> /// Catch the current Slot. /// Parent the Item under the Canvas in order to have it in /// front of everything while dragging.</summary> public void OnBeginDrag(PointerEventData eventData) { if (!_slot._allowsDrag) { return; } _canvas = GetComponentInParent<Canvas>(); _draggedItem = this; startSlot = _slot; GetComponent<CanvasGroup>().blocksRaycasts = false; transform.SetParent(GetComponentInParent<Canvas>().transform); }
public void OnEndDrag(PointerEventData eventData) { if (!Slot.AllowsDrag) { return; } DraggedItem = null; _canvasGroup.blocksRaycasts = true; if (Slot == _startSlot) { Slot.Drop(this); } }
public void AddItem(SlottableItem item, string slotName = null) { Slot slot = null; if (slotName == null) { slot = NextAvailableSlot(); } else { slot = SlotByName(slotName); } if (slot != null) { slot.Drop(item); } }
public void ResetSlots() { foreach (Slot slot in _slots) { if (slot.Item != null) { slot.Item.gameObject.SetActive(false); Items.Remove(slot.Item.Name.text); slot.Item.Amount = 0; slot.Item.Item = null; SlottableItem item = slot.Item; slot.Clear(); Slot target = NextAvailableSlot(); if (target != null) { target.Drop(item); } } } }
/// <summary> /// Update the Character in case the Item is placed in a special /// Slot, like the Weapon Slot.</summary> public override void SlotChanged(Slot slot, SlottableItem currentItem, SlottableItem previousItem) { if (slot == _weaponSlot) { Player._player.Stats._equippedWeapon = currentItem != null ? (Weapon)currentItem.Data : null; } }
/// <summary> /// Slots have changed.</summary> public virtual void SlotChanged(Slot slot, SlottableItem currentItem, SlottableItem previousItem) { }
/// <summary> /// Swap the given Item with the Item in this Slot if possible.</summary> public void Swap(SlottableItem item) { var currentItem = _item; var draggedItem = item; if (draggedItem == null || currentItem == draggedItem) { return; } var oldSlot = draggedItem._slot; if (IsFree && AcceptsItem(draggedItem) && draggedItem.AcceptsSlot(this)) { Drop(draggedItem); oldSlot.Clear(); return; } // Items need to be swapped if (AcceptsItem(draggedItem) && oldSlot.AcceptsItem(currentItem) && draggedItem.AcceptsSlot(this) && currentItem.AcceptsSlot(oldSlot)) { Drop(draggedItem); oldSlot.Drop(currentItem); } }
/// <summary> /// Set the Slot free.</summary> public void Clear() { var oldItem = _item; _item = null; ExecuteEvents.ExecuteHierarchy<ISlotChanged>(gameObject, null, (x, y) => x.SlotChanged(this, null, oldItem)); }
/// <summary> /// Weather the Slot accepts the given Item.</summary> public virtual bool AcceptsItem(SlottableItem item) { return true; }
/// <summary> /// Update the Character in case the Item is placed in a special /// Slot, like the Weapon Slot.</summary> public void SlotChanged(Slot slot, SlottableItem currentItem, SlottableItem previousItem) { }
/// <summary> /// If no new Slot was found, drop the Item back into the current Slot.</summary> public void OnEndDrag(PointerEventData eventData) { if (!_slot._allowsDrag) { return; } _draggedItem = null; GetComponent<CanvasGroup>().blocksRaycasts = true; if (_slot == startSlot) { _slot.Drop(this); } }