private void OnAddItem(string itemId, int count)
        {
            if (!G_idToItemUi.ContainsKey(itemId))
            {
                //实例化
                var obj = ResourceMgr.InstantiateGameObject(UiName.Slot);

                //初始化Slot信息
                var slotUi = obj.GetComponent <HiveFiveItemSlot>();
                if (!slotUi)
                {
                    throw new Exception("获取到的ItemInfoUI为空");
                }
                slotUi.Init(itemId, count, id => G_idToItemUi.Remove(id));
                slotUi.InitDragger(GemboxIsTarget, SlotIsTarget, grid.ReBuild);

                //初始化拖拽状态
                var item = GlobalVar.G_Player.GetItems()[itemId];
                if (item.gemBoxIndex == -1)
                {
                    var parent = this.grid.transform;
                    slotUi.SwitchDragType(DragType.Package, parent.gameObject);
                }
                else
                {
                    var parent = this.effectiveGemBar.GetChild(item.gemBoxIndex);
                    slotUi.SwitchDragType(DragType.Gembox, parent.gameObject);
                }

                //Ui重建
                grid.ReBuild();
                //本地保存
                G_idToItemUi.Add(itemId, slotUi);
            }
            else
            {
                G_idToItemUi[itemId].Add(count);
            }
        }
Пример #2
0
        private void OnAddItem(string itemId, int count)
        {
            if (!G_idToItemUi.ContainsKey(itemId))
            {
                var obj = ResourceMgr.InstantiateGameObject(PrefabName.Slot, grid.transform);
                obj.transform.localPosition = Vector3.zero;
                var slotUi = obj.GetComponent <Slot>();
                if (!slotUi)
                {
                    throw new Exception("获取到的ItemInfoUI为空");
                }

                slotUi.Refresh(itemId, count, id => G_idToItemUi.Remove(id));

                G_idToItemUi.Add(itemId, slotUi);

                grid.ReBuild();
            }
            else
            {
                G_idToItemUi[itemId].Add(count);
            }
        }