public void OnBeginDrag(PointerEventData eventData) { if (transform.parent.GetComponent <DndCell>().cellType == DndCell.CellType.DropOnly) { return; } if (dragDisabled == false) { sourceCell = GetCell(); draggedItem = this; // base 이미지 icon = new GameObject(); icon.transform.SetParent(canvas.transform); icon.name = "Icon"; Image myImage = GetComponent <Image>(); myImage.raycastTarget = false; Image iconImage = icon.AddComponent <Image>(); iconImage.raycastTarget = false; iconImage.sprite = myImage.sprite; iconImage.color = myImage.color; RectTransform iconRect = icon.GetComponent <RectTransform>(); iconImage.type = Image.Type.Sliced; // 안쪽 아이콘 width = GetComponentInParent <test_info>().width_; spine_name = GetComponentInParent <test_info>().name_; thema = GetComponentInParent <test_info>().thema; index_ = GetComponentInParent <test_info>().index; // GameObject con_img = new GameObject(); con_img.transform.SetParent(icon.transform); con_img.name = "con_img"; Image con_myImage = myImage.GetComponent <Transform>().GetChild(0).GetComponent <Image>(); con_myImage.raycastTarget = false; Image con_iconImage = con_img.AddComponent <Image>(); con_iconImage.raycastTarget = false; con_iconImage.sprite = con_myImage.sprite; RectTransform con_Rect = con_img.GetComponent <RectTransform>(); con_Rect.sizeDelta = new Vector2(60, 60); con_Rect.localPosition = new Vector2(0, 0); // iconRect.pivot = new Vector2(0.5f, 0.5f); iconRect.anchorMin = new Vector2(0.5f, 0.5f); iconRect.anchorMax = new Vector2(0.5f, 0.5f); iconRect.sizeDelta = new Vector2(96 * width, 96); if (OnItemDragStartEvent != null) { OnItemDragStartEvent(this); } } }
public void OnDrop(PointerEventData data) { RectTransform rt = GetComponent <RectTransform>(); Vector3 vt3 = new Vector3(0.5f, 0, 0); bool dir = false; if (data.position.x > Camera.main.WorldToScreenPoint(rt.position + vt3).x) { dir = true; } else { dir = false; } int check_value = buildmgr.Instance.building_check(int.Parse(transform.parent.name), int.Parse(name), dir, Dnditem.draggedItem); if (check_value != -1) { } else { return; } if (Dnditem.icon != null) { Dnditem item = Dnditem.draggedItem; DndCell soureceCell = Dnditem.sourceCell; if (Dnditem.icon.activeSelf == true) { if ((item != null) && (soureceCell != this)) { if (cellType == CellType.DropOnly) { item.target_ = check_value; PlaceItem(item, dir); } } } if (item != null) { if (item.GetComponentInParent <DndCell>() == null) { Destroy(item.gameObject); } } UpdateMyItem(); soureceCell.UpdateMyItem(); } }
private void ResetConditions() { if (icon != null) { Destroy(icon); } if (OnItemDragEndEvent != null) { OnItemDragEndEvent(this); } draggedItem = null; icon = null; sourceCell = null; }
public void PlaceItem(Dnditem item, bool dir) { if (item != null) { DestroyItem(); mydadItem = null; DndCell cell = item.GetComponentInParent <DndCell>(); if (cell != null) { if (cell.unlimitedSource == true) { string itemName = item.name; item = Instantiate(item); item.name = itemName; } } item.transform.SetParent(transform, false); if (item.width % 2 == 1) { item.GetComponent <RectTransform>().sizeDelta = new Vector2(96 * item.width, 96); } else { RectTransform rt = item.GetComponent <RectTransform>(); if (dir) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x + 48, rt.anchoredPosition.y); rt.sizeDelta = new Vector2(96 * item.width, 96); } else { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x - 48, rt.anchoredPosition.y); rt.sizeDelta = new Vector2(96 * item.width, 96); } } item.GetComponent <RectTransform>().GetChild(0).GetComponent <RectTransform>().sizeDelta = new Vector2(60, 60); item.MakeRaycast(true); mydadItem = item; } }