Пример #1
0
    /// <summary>
    /// 拾取物品
    /// </summary>
    /// <param name="id"></param>
    public void GetId(int id)
    {
        //查找是否存在该物品
        //存在 num+1
        //不存在 查找空的方格存放进去
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in items)
        {
            if (temp.id == id)
            {
                grid = temp; break;
            }
        }

        if (grid != null)
        {
            //存在
            grid.AddNum();
        }
        else
        {
            //不存在,查找空的方格
            foreach (InventoryItemGrid temp in items)
            {
                if (temp.id == 0)
                {
                    grid = temp; break;
                }
            }

            if (grid != null)
            {
                //有足够的格子
                grid.SetId(id);
            }
            else
            {
                print("没有多的格子了");
            }
        }
    }
Пример #2
0
 /// <summary>
 /// 添加到装备
 /// </summary>
 void AddEquipment()
 {
     if (isPointEnter)
     {
         if (inventoryItemGrid.num > 0)
         {
             bool isAddEquip = equipment.SetId(id);
             if (isAddEquip)
             {
                 inventoryItemGrid.AddNum(-1);
                 if (inventoryItemGrid.num == 0)
                 {
                     Destroy(inventoryItemGo);
                     inventoryItemGrid.ClearInfo();
                     labelUI.HideLabel();
                     isPointEnter = false;
                 }
             }
         }
     }
 }