/// <summary> /// /// Exectes the hotbar slot action clicked /// </summary> /// <param name="eventData"></param> public void OnPointerClick(PointerEventData eventData) { HotbarSlotGUI slotClicked = eventData.rawPointerPress.GetComponentInParent <HotbarSlotGUI>(); if (!slotClicked) { return; } if (_slots.Contains(slotClicked)) { slotClicked.ExecuteSlotAction(); } }
/// <summary> /// Updates the slot if another slot with a different action is dropped on it /// </summary> public void OnDrop(PointerEventData eventData) { if (!GUIManager.Instance.Hotbar) { Debug.Log("No Hotbar GUI!"); return; } HotbarSlotGUI recieverSlot = eventData.pointerEnter.GetComponentInParent <HotbarSlotGUI>(); HotbarSlotGUI senderSlot = eventData.pointerDrag.GetComponentInParent <HotbarSlotGUI>(); if (!recieverSlot) { return; } if (recieverSlot == senderSlot) { return; } if (!recieverSlot.GetComponentInParent <Hotbar>()) { return; } // Save old action of slot reciever in case we are swapping action IHotbarAction auxAction = senderSlot.HotbarAction; // Check if we are swapping slots if (GUIManager.Instance.Hotbar.IsActionInHotbar(senderSlot.HotbarAction)) { GUIManager.Instance.Hotbar.InitializeSlot( GUIManager.Instance.Hotbar.indexOfAction(auxAction), recieverSlot.HotbarAction ); } recieverSlot.Initialize(auxAction); }