Exemplo n.º 1
0
    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();
        }
    }
Exemplo n.º 2
0
    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;
        }
    }