예제 #1
0
    private void GridUI_ExitDrag(Transform lasttransform, Transform transform)
    {
        Isdrag = false;
        dragitemui.HideText();

        if (transform == null)   //ui 外
        {
            ItemModel.DeleteItem(lasttransform.name);
            Debug.Log("物品已移除");
        }
        else if (transform.tag == "Grid")  //拖到格子里
        {
            if (transform.childCount == 0) //空格子
            {
                Item item = ItemModel.GetItem(lasttransform.name);
                if (item != null)
                {
                    ItemModel.DeleteItem(lasttransform.name);
                }
                CreatNewItem(item, transform);
            }
            else          //已存在交换
            {
                //删除原来的物品
                Destroy(transform.GetChild(0).gameObject);
                //获取数据
                Item prevGirdItem  = ItemModel.GetItem(lasttransform.name);
                Item enterGirdItem = ItemModel.GetItem(transform.name);
                //交换的两个物体
                this.CreatNewItem(prevGirdItem, transform);
                this.CreatNewItem(enterGirdItem, lasttransform);
            }
        }
        else      //格子外
        {
            // Item item = ItemModel.GetItem(lasttransform.name);

            // CreatNewItem(item, lasttransform);
        }
    }