public void EquipItem() { itemInventoryIndex = transform.GetSiblingIndex(); if (slotIndex < 10) { if (hero.equipment.GetEquipment[slotIndex] != null) { equipmentPanel.EquipAndUnEquip(item, hero.equipment.GetEquipment[slotIndex], slotIndex, itemInventoryIndex); return; } equipmentPanel.EquipItem(item, slotIndex, itemInventoryIndex); } else if (slotIndex == 99) { if (hero.equipment.GetEquipment[slotIndex] != null) { equipmentPanel.EquipAndUnEquip(item, hero.equipment.GetEquipment[slotIndex], slotIndex, itemInventoryIndex); } if (hero.equipment.GetEquipment[slotIndex] != null) { equipmentPanel.UnEquipItem(item, slotIndex); return; } if (hero.equipment.GetEquipment[slotIndex] == null) { equipmentPanel.EquipItem(item, 2, itemInventoryIndex); } } detailsPanel.SetActive(false); }
public void OnEndDrag(PointerEventData eventData) { if (!CanDrag) { return; } var results = new List <RaycastResult>(); EventSystem.current.RaycastAll(eventData, results); DropArea dropArea = null; foreach (var result in results) { dropArea = result.gameObject.GetComponent <DropArea>(); if (dropArea != null) { break; } } if (dropArea != null) { if (dropArea.Accepts(this)) { SetIndex(dropArea.name); if (dropArea.GetComponentInChildren <SetItemIcon>() != null) { GameObject temp = dropArea.GetComponentInChildren <SetItemIcon>().gameObject; temp.transform.SetParent(parentToRenturnTo); temp.transform.SetSiblingIndex(this.positionIndex); equipmentPanel.UnEquipItem(temp.GetComponent <SetItemIcon>().GetItem, index); } dropArea.Drop(this); OnEndDragHandler?.Invoke(eventData, true); transform.SetParent(dropArea.transform); equipmentPanel.EquipItem(item, index, positionIndex); return; } } if (eventData.position.x > halfScreen && startingPosition < halfScreen) { equipmentPanel.UnEquipItem(item, index); this.transform.SetParent(inventoryPosition); rectTransform.anchoredPosition = StartPosition; OnEndDragHandler?.Invoke(eventData, false); return; } this.transform.SetParent(parentToRenturnTo); rectTransform.anchoredPosition = StartPosition; //transform.SetSiblingIndex(positionIndex); //equipmentPanel.UnEquipItem(item, index); OnEndDragHandler?.Invoke(eventData, false); }