public void DraggableHandler(UI_Draggable draggable) { if(currentDragged == null) { currentDragged = draggable.GetDraggable(); } else if(currentDragged == draggable) { OnDraggableDrop(draggable); currentDragged = null; } }
private void OnDraggableDrop(UI_Draggable draggable) { draggable.Released(); Vector2 mousePos = Input.mousePosition; // check if it was released in a drop area for(int i = 0; i < dropAreas.Length; i++) { Rect screenRect = dropAreas[i].rectTransform.rect; screenRect.position = dropAreas[i].rectTransform.position; if(screenRect.Contains(mousePos)) { draggable.WasDroppedIntoArea(dropAreas[i]); break; } } }
/// <summary> /// Will receive this message when an upgrade tile is dropped onto this slot /// </summary> public void UI_ReceivedDrop(UI_Draggable draggeble) { PlayerState playerState = FindObjectOfType<PlayerState>(); UI_UpgradeTile upgradeTile = draggeble.GetComponent<UI_UpgradeTile>(); if(playerState != null && playerState != null) { Debug.Log(upgradeTile.playerUpgradeClass + " was dropped into slot [" + name + "]"); bool wasEquipped = playerState.EquipUpgradeType(upgradeTile.playerUpgradeClass, upgradeTile.playerUpgradeLevel); if(wasEquipped) { // Set the slots image SetIcon(upgradeTile.upgradeImage); hasEquippedUpgrade = true; upgradeClass = upgradeTile.playerUpgradeClass; upgradeLevel = upgradeTile.playerUpgradeLevel; UpgradeMenuManager.instance.UpgradePlacedInSlot(upgradeTile.playerUpgradeClass, this); } } }