Пример #1
0
        /// <summary>
        /// 设置道具详情信息
        /// </summary>
        /// <param name="model"></param>
        private void SetupItemData(ItemModel model)
        {
            m_ItemNameText.text = model.Name;
            m_ItemDesText.text  = model.GetItemDes();
            m_ItemTypeText.text = model.GetItemCategory();

            // 图标
            GameEntry.Resource.LoadAsset(AssetUtility.GetItemSprite(model.Icon), typeof(Sprite),
                                         new LoadAssetCallbacks(LoadAssetSuccessCallback));

            switch (m_ItemInfoType)
            {
            case ItemInfoType.HumanEquipment:
                m_HumanEquipModel = (HumanEquipModel)model;
                SetupHumanEquipmentItemData(m_HumanEquipModel);
                break;

            case ItemInfoType.VehiclenEquipment:
                m_VehicleEquipModel = (VehicleEquipModel)model;
                SetupVehicleEquipmentItemData(m_VehicleEquipModel);
                break;

            case ItemInfoType.Knapsack:
                m_KnapsackModel = (KnapsackModel)model;
                SetupKnapsackItemData(m_KnapsackModel);
                break;
            }
        }
Пример #2
0
 protected override void OnClose(object userData)
 {
     base.OnClose(userData);
     m_InputField.text = string.Empty;
     m_ShopModel       = null;
     m_KnapsackModel   = null;
 }
Пример #3
0
 protected override void OnClose(object userData)
 {
     base.OnClose(userData);
     m_KnapsackModel     = null;
     m_HumanEquipModel   = null;
     m_VehicleEquipModel = null;
     m_ItemIcon.enabled  = false;
 }
Пример #4
0
        /// <summary>
        /// 实例化一个道具UI
        /// </summary>
        /// <param name="model"></param>
        private void InstantiateItem(KnapsackModel model)
        {
            var itemGo = Instantiate(m_ItemPrefab);

            itemGo.transform.SetParent(m_ItemSolts[model.Index].transform, false);
            itemGo.transform.SetAsFirstSibling();
            m_ItemSolts[model.Index].SetupData(model);
        }
Пример #5
0
        /// <summary>
        /// 清空格子里的道具
        /// </summary>
        public void ClearItemBox()
        {
            var item = GetComponentInChildren <DrawableItemUI>();

            if (item == null)
            {
                return;
            }

            // 如果格子上有道具则销毁
            m_KnapsackModel      = null;
            m_ItemCountText.text = string.Empty;
            Destroy(item.gameObject);
        }
Пример #6
0
        /// <summary>
        /// 添加物品进背包
        /// </summary>
        /// <param name="model">道具模型</param>
        /// <param name="isNewItem">是否需要新格子</param>
        /// <returns></returns>
        public void AddItem(KnapsackModel model, bool isNewItem)
        {
            // 更新背包格子数量和金币显示
            UpdateCoinAndUsedBoxCountUI();

            if (isNewItem)
            {
                // 需要新格子则实例化
                InstantiateItem(model);
            }
            else
            {
                UpdateCurrentStackCount(model.Index);
            }
        }
Пример #7
0
        /// <summary>
        /// 设置背包格子里的道具数据
        /// </summary>
        /// <param name="model">背包道具模型</param>
        public void SetupData(KnapsackModel model)
        {
            m_KnapsackModel = model;

            // 设置道具数据
            var item = GetComponentInChildren <DrawableItemUI>();

            if (item == null)
            {
                return;
            }
            item.SetupData(model.Id);

            UpdateCurrentStackCount();
        }
Пример #8
0
        /// <summary>
        /// 堆叠道具更新满后,添加新格子
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="itemCount"></param>
        /// <param name="itemSourceType"></param>
        private void AddNewItem(int itemId, int itemCount, GetItemSourceType itemSourceType)
        {
            while (true)
            {
                // 背包满了
                if (GameEntry.Archive.Data.KnapsackModels.Count == KnapsackCapacity)
                {
                    if (itemSourceType != GetItemSourceType.Shop)
                    {
                        Log.Debug("没有存放进背包的数量 " + itemCount);
                    }

                    break;
                }

                var model = new KnapsackModel(itemId)
                {
                    Index = GetEmptySoltIndex()
                };
                GameEntry.Archive.Data.KnapsackModels.Add(model);

                // 可以放得下
                if (model.StackCount >= itemCount)
                {
                    model.CurrentStackCount += itemCount;
                    if (m_KnapsackForm)
                    {
                        m_KnapsackForm.AddItem(model, true);
                    }

                    Log.Debug("放完");
                    break;
                }

                // 放不下
                model.CurrentStackCount = model.StackCount;
                if (m_KnapsackForm)
                {
                    m_KnapsackForm.AddItem(model, true);
                }

                // 剩下的
                itemCount -= model.StackCount;
                Log.Debug("放一个新格子后剩下 " + itemCount);
            }
        }
Пример #9
0
        /// <summary>
        /// 使用道具
        /// </summary>
        /// <param name="model">道具模型</param>
        public void UseItem(KnapsackModel model)
        {
            var goodsRow = model.GetGoodsRow();

            switch (goodsRow.GoodsType)
            {
            case GoodsType.Supply:
                break;

            case GoodsType.Attack:
                break;

            case GoodsType.Assist:
                break;

            case GoodsType.Tool:
                break;
            }
        }
Пример #10
0
        protected override void OnOpen(object userData)
        {
            base.OnOpen(userData);
            m_InputField.onValidateInput = OnValidateInput;
            m_InputField.text            = "1";

            m_Type = (InputCountType)(int)GameEntry.DataNode.GetData <VarInt>(Constant.NodeKey.InputCountType);
            GameEntry.DataNode.RemoveNode(Constant.NodeKey.InputCountType);
            switch (m_Type)
            {
            case InputCountType.Sell:
            case InputCountType.Discard:
                m_KnapsackModel = (KnapsackModel)userData;
                break;

            case InputCountType.Buy:
                m_ShopModel = (ShopModel)userData;
                break;
            }
        }
Пример #11
0
        /// <summary>
        /// 设置背包界面道具信息
        /// </summary>
        /// <param name="model"></param>
        private void SetupKnapsackItemData(KnapsackModel model)
        {
            // 是否打开了商店
            if (GameEntry.UI.HasUIForm(UIFormId.ShopForm))
            {
                if (model.CanSell())
                {
                    m_FuncButton1.gameObject.SetActive(false);
                    m_FuncButton2.gameObject.SetActive(true);
                    m_FuncButton2.GetComponentInChildren <Text>().text = "出售";
                }
                else
                {
                    m_FuncButton1.gameObject.SetActive(false);
                    m_FuncButton2.gameObject.SetActive(false);
                }
            }
            else
            {
                if (model.CanUse())
                {
                    m_FuncButton1.gameObject.SetActive(true);
                    m_FuncButton1.GetComponentInChildren <Text>().text = "使用";
                }
                else if (model.CanEquip())
                {
                    m_FuncButton1.gameObject.SetActive(true);
                    m_FuncButton1.GetComponentInChildren <Text>().text = "装备";
                }

                if (model.CanDiscard())
                {
                    m_FuncButton2.gameObject.SetActive(true);
                    m_FuncButton2.GetComponentInChildren <Text>().text = "丢弃";
                }
                else
                {
                    m_FuncButton2.gameObject.SetActive(false);
                }
            }
        }
Пример #12
0
 /// <summary>
 /// 出售道具
 /// </summary>
 /// <param name="model">道具模型</param>
 /// <param name="count">数量</param>
 public void SellItem(KnapsackModel model, int count = 1)
 {
     GameEntry.Archive.Data.AddGold(model.SellPrice);
     ReduceStackCount(model.Index, count);
 }
Пример #13
0
 /// <summary>
 /// 丢弃道具
 /// </summary>
 /// <param name="model">道具模型</param>
 /// <param name="count">数量</param>
 public void DiscardItem(KnapsackModel model, int count = 1)
 {
     ReduceStackCount(model.Index, count);
 }
Пример #14
0
 /// <summary>
 /// 装备道具
 /// </summary>
 /// <param name="model">道具模型</param>
 public void EquipItem(KnapsackModel model)
 {
     ReduceStackCount(model.Index, 1);
     GameEntry.Controller.CharacterInfo.WornEquipment(model.Id);
 }