Beispiel #1
0
 protected override void ClearUIComponents()
 {
     UITopStatus     = null;
     TxtUsedCount    = null;
     TxtAllCount     = null;
     BtnInventoryAdd = null;
     Content         = null;
     UISolt          = null;
     mData           = null;
 }
 /// <summary>
 /// 显示新增背包列表
 /// </summary>
 public void ShowAddNewInventoryList()
 {
     for (int i = 0; i < 10; i++)
     {
         UISolt.Instantiate()
         .Parent(Content)
         .LocalIdentity()
         .ApplySelfTo(self =>
         {
             //self.Init();
             self.Show();
             mSlotList.Add(self);
         });
     }
 }
 /// <summary>
 /// 显示背包列表
 /// </summary>
 public void ShowInventoryList()
 {
     mSlotList = new List <UISolt>();
     for (int i = 0; i < GameData.InventoryCount; i++)
     {
         UISolt.Instantiate()
         .Parent(Content)
         .LocalIdentity()
         .ApplySelfTo(self =>
         {
             //self.Init();
             self.Show();
             mSlotList.Add(self);
         });
     }
 }
        /// <summary>
        /// 物品放入到物品槽内
        /// </summary>
        /// <returns><c>true</c>, if item was stored, <c>false</c> otherwise.</returns>
        /// <param name="item">Item.</param>
        public bool StoreItem(Item item)
        {
            if (item == null)
            {
                Debug.LogWarning("要存储的物品的ID不存在!");

                return(false);
            }
            else
            {
                if (item.Capacity == 1)     // 如果该物品单独占用一个物品槽(slot)
                {
                    // 找到一个空的物品槽放进去
                    UISolt slot = FindEmptySlot();
                    if (slot != null)
                    {
                        slot.StoreItem(item);
                        // 显示已使用数量
                        ShowUsedTextCount();

                        SaveInventory();

                        return(true);
                    }
                    else
                    {
                        // 跳转到失败界面
                        UIMgr.OpenPanel <UIDataUpdateSucceedPanel>(new UIDataUpdateSucceedPanelData
                        {
                            SuccessModel = new DataUpdateSuccessModel
                            {
                                StrTitle  = "失败了",
                                StrDesc   = "没有空的物品槽~",
                                IsSucceed = false
                            }
                        });
                        return(false);
                    }
                }
                else
                {
                    // 查找相同类型物品槽
                    UISolt slot = FindSameTypeSlot(item);
                    if (slot != null)
                    {
                        slot.StoreItem(item);

                        SaveInventory();

                        return(true);
                    }
                    else
                    {
                        UISolt emptySlot = FindEmptySlot();
                        if (emptySlot != null)
                        {
                            emptySlot.StoreItem(item);
                            // 显示已使用数量
                            ShowUsedTextCount();

                            SaveInventory();

                            return(true);
                        }
                        else
                        {
                            // 跳转到失败界面
                            UIMgr.OpenPanel <UIDataUpdateSucceedPanel>(new UIDataUpdateSucceedPanelData
                            {
                                SuccessModel = new DataUpdateSuccessModel
                                {
                                    StrTitle  = "失败了",
                                    StrDesc   = "没有空的物品槽~",
                                    IsSucceed = false
                                }
                            });
                            return(false);
                        }
                    }
                }
            }
        }