Exemplo n.º 1
0
 /// <summary>
 /// 拖动和交换物品位置
 /// </summary>
 /// <param name="surface"></param>
 protected override void OnDragDropRelease(GameObject surface)
 {
     base.OnDragDropRelease(surface);
     // Debug.Log(surface.gameObject);
     if (surface != null)
     {
         if (surface.tag == Tags.InventoryItemGrid)
         {
             if (surface == transform.parent.gameObject)
             {
                 ResetPosition();
             }
             else
             {
                 //得到这个 要拖动的物品的父类格子,在得到要落下的 格子,在设置这个格子为物品的父类
                 //在设置要 落下的格子 里的这个物品的属性
                 UIInventoryItemGrid grid1 = transform.parent.GetComponent <UIInventoryItemGrid>();
                 UIInventoryItemGrid grid2 = surface.GetComponent <UIInventoryItemGrid>();
                 transform.parent = surface.transform;
                 grid2.SetGridId(grid1.gridID, grid1.itemNum);
                 grid1.CheakItem();
             }
         }
         else if (surface.tag == Tags.InventoryItem)
         {
             UIInventoryItemGrid grid1 = transform.parent.GetComponent <UIInventoryItemGrid>();
             UIInventoryItemGrid grid2 = surface.transform.parent.GetComponent <UIInventoryItemGrid>();
             int id = grid1.gridID; int num = grid1.itemNum;
             grid1.SetGridId(grid2.gridID, grid2.itemNum);
             grid2.SetGridId(id, num);
         }
     }
     ResetPosition();
 }
Exemplo n.º 2
0
    public void GetItem(int id, int count = 1)//count 购买的数量
    {
        UIInventoryItemGrid grid = null;

        foreach (UIInventoryItemGrid temp in itemGridList)
        {
            if (temp.gridID == id)
            {
                grid = temp; break;
            }
        }
        if (grid != null)
        {
            grid.PulsName(count);
        }
        else
        {
            foreach (UIInventoryItemGrid temp in itemGridList)
            {
                if (temp.gridID == 0)
                {
                    grid = temp; break;
                }
            }
            if (grid != null)
            {
                GameObject item = Instantiate(inventoryItem);
                item.transform.SetParent(grid.transform);
                item.transform.localPosition = Vector3.zero;
                item.transform.localScale    = Vector3.one;
                grid.SetGridId(id, count);
            }
        }
    }