示例#1
0
    public void GridUIOnLeftBeginDrag(Transform gridTransform) //开始拖动
    {
        if (gridTransform.childCount == 0)                     //格子上没有物品
        {
            isDragNull = true;                                 //禁止拖动空格子
            return;
        }
        else
        {
            isDragNull = false;

            //drag item更新为选择的物品
            Item item = ItemModel.GetItem(gridTransform.name);
            if (item != null)
            {
                dragUI.UpdateIcon(item.iconIndex);
                dragUI.UpdateCount(item.count);

                //将选择的物品从格子上销毁
                Destroy(gridTransform.GetChild(0).gameObject);

                //显示拖动物品
                Vector2 position;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("Canvas").transform as RectTransform,
                                                                        Input.mousePosition, null, out position);
                dragUI.SetLocalPosition(position);

                dragUI.ShowItem();
            }
        }
    }