private void OnAnyItemDragStart(DragAndDropItem_Training item) { DragAndDropItem_Training myItem = GetComponentInChildren <DragAndDropItem_Training>(); // Get item from current cell if (myItem != null) { myItem.MakeRaycast(false); // Disable item's raycast for correct drop handling if (myItem == item) // If item dragged from this cell { // Check cell's type switch (cellType) { case CellType.DropOnly: DragAndDropItem_Training.icon.SetActive(false); // Item will not be dropped break; case CellType.UnlimitedSource: // Nothing to do break; default: item.MakeVisible(false); // Hide item in cell till dragging break; } } } }
public void OnDrop(PointerEventData data) { if (DragAndDropItem_Training.icon != null) { if (DragAndDropItem_Training.icon.activeSelf == true) // If icon inactive do not need to drop item in cell { DragAndDropItem_Training item = DragAndDropItem_Training.draggedItem; DragAndDropCell_Training sourceCell = DragAndDropItem_Training.sourceCell; if ((item != null) && (sourceCell != this)) { switch (sourceCell.cellType) // Check source cell's type { case CellType.UnlimitedSource: string itemName = item.name; int itemnum = item.IndexNum; item = Instantiate(item); // Clone item from source cell item.name = itemName; item.IndexNum = itemnum; break; default: // Nothing to do break; } switch (cellType) // Check this cell's type { case CellType.Swap: DragAndDropItem_Training currentItem = GetComponentInChildren <DragAndDropItem_Training>(); switch (sourceCell.cellType) { case CellType.Swap: SwapItems(sourceCell, this); // Swap items between cells break; default: PlaceItem(item.gameObject); // Place dropped item in this cell break; } break; case CellType.DropOnly: PlaceItem(item.gameObject); // Place dropped item in this cell break; default: //nothing to do. break; } } if (item.GetComponentInParent <DragAndDropCell_Training>() == null) // If item have no cell after drop { Destroy(item.gameObject); // Destroy it } TrainingManager.TMInstance.DragEndAction(sourceCell.GetCellNumber(), this.GetCellNumber(), item.IndexNum); } } }
public void OnBeginDrag(PointerEventData eventData) { if (IsItemCanDrag) { sourceCell = GetComponentInParent <DragAndDropCell_Training>(); // Remember source cell draggedItem = this; // Set as dragged item icon = new GameObject("Icon"); // Create object for item's icon Image image = icon.AddComponent <Image>(); image.sprite = GetComponent <Image>().sprite; image.raycastTarget = false; // Disable icon's raycast for correct drop handling RectTransform iconRect = icon.GetComponent <RectTransform>(); // Set icon's dimensions iconRect.sizeDelta = new Vector2(GetComponent <RectTransform>().sizeDelta.x, GetComponent <RectTransform>().sizeDelta.y); Canvas canvas = GetComponentInParent <Canvas>(); // Get parent canvas if (canvas != null) { // Display on top of all GUI (in parent canvas) icon.transform.SetParent(canvas.transform, true); // Set canvas as parent icon.transform.SetAsLastSibling(); // Set as last child in canvas transform } if (OnItemDragStartEvent != null) { OnItemDragStartEvent(this); // Notify all about item drag start } } }
private void OnAnyItemDragEnd(DragAndDropItem_Training item) { DragAndDropItem_Training myItem = GetComponentInChildren <DragAndDropItem_Training>(); // Get item from current cell if (myItem != null) { myItem.MakeRaycast(true); // Enable item's raycast } }
public void PlaceItem(GameObject itemObj) { RemoveItem(); // Remove current item from this cell if (itemObj != null) { itemObj.transform.SetParent(transform, false); itemObj.transform.localPosition = Vector3.zero; DragAndDropItem_Training item = itemObj.GetComponent <DragAndDropItem_Training>(); if (item != null) { item.MakeRaycast(true); } } }
private void InitSkillSetPanel() { string[] tempList = PlayManage.Instance.SkillPreSet.Split(','); int skillIndex; preSetList = new int[4]; for (int i = 0; i < 4; i++) { skillSetPanel[i].SetSkillSetPanel(i); DragAndDropItem_Training myitem = skillSetPanel[i].GetComponentInChildren <DragAndDropItem_Training>(); skillIndex = int.Parse(tempList[i]); preSetList[i] = skillIndex; myitem.gameObject.GetComponent <Image>().sprite = skillDB.GetSkillIcon(skillIndex); myitem.IndexNum = (skillIndex); myitem.SetItemCanDrag(true); } MarkSelectSquare(this.skillListPanel, this.preSetList, this.selectSquareSprite); }
private void InitSkillListPanel() { for (int i = 0; i < skillListPanel.Count; i++) { DragAndDropItem_Training myitem = skillListPanel[i].GetComponentInChildren <DragAndDropItem_Training>(); int skillRequireLevel = skillDB.GetSkillPrefab()[i].GetComponent <SkillBase>().GetRequiredLevel(); if (skillRequireLevel <= (PlayManage.Instance.GetPlayerLevel())) { myitem.gameObject.GetComponent <Image>().sprite = skillDB.GetSkillIcon(i); myitem.IndexNum = (i); myitem.SetItemCanDrag(true); } else { myitem.gameObject.GetComponent <Image>().sprite = GetPadLock(); myitem.SetItemCanDrag(false); ShowRequiredLevel(skillRequireLevel, myitem.transform); } } }
public void SwapItems(DragAndDropCell_Training firstCell, DragAndDropCell_Training secondCell) { if ((firstCell != null) && (secondCell != null)) { DragAndDropItem_Training firstItem = firstCell.GetItem(); // Get item from first cell DragAndDropItem_Training secondItem = secondCell.GetItem(); // Get item from second cell if (firstItem != null) { // Place first item into second cell firstItem.transform.SetParent(secondCell.transform, false); firstItem.transform.localPosition = Vector3.zero; } if (secondItem != null) { // Place second item into first cell secondItem.transform.SetParent(firstCell.transform, false); secondItem.transform.localPosition = Vector3.zero; } } }
public void OnEndDrag(PointerEventData eventData) { eventData.Reset(); if (icon != null) { Destroy(icon); // Destroy icon on item drop } MakeVisible(true); // Make item visible in cell if (OnItemDragEndEvent != null) { OnItemDragEndEvent(this); // Notify all cells about item drag end } //빈 공간에 드래그 앤 드롭 했을시 if (eventData.pointerCurrentRaycast.gameObject.tag != "SkillPanel" && sourceCell.cellType == DragAndDropCell_Training.CellType.Swap) { sourceCell.RemoveItem(); TrainingManager.TMInstance.DragEndAction(sourceCell.GetCellNumber(), null, this.IndexNum); } draggedItem = null; icon = null; sourceCell = null; }