예제 #1
0
        private ItemBar AddItem(BagItem item, string key, string eventKey, string count)
        {
            ItemBar bar = new ItemBar();

            SimpleProto model = SingletonManager.Get <FreeUiManager>().GetUIData(key);

            if (model == null)
            {
                Debug.LogWarningFormat("item '{0}' is not defined.", key);
                return(null);
            }

            FreePrefabComponent ff = new FreePrefabComponent();

            ff.parentObject = parentBag;
            int realCount = 1;

            if (!string.IsNullOrEmpty(count))
            {
                realCount = int.Parse(count);
            }
            TipUtil.AddTip(eventKey, new TipData(item.cat, item.id, realCount));

            ff.Initial(model.Ss[2], model.Ss[3]);
            ff.SetValues("TEXT_ItemNumber" + FreeMessageConstant.SpilterField + count);
            ff.SetEvents("");
            ff.SetAllEventKey(eventKey);

            bar.prefab = ff;
            bar.value  = model.Ss[2].Split(FreeMessageConstant.SpliterStyle)[1];

            return(bar);
        }
예제 #2
0
        private void FillBox(Dictionary <string, List <FreeMoveEntity> > dic, Dictionary <int, ItemBar> cache, bool dead)
        {
            int index = 0;

            foreach (var name in dic.Keys)
            {
                ItemBar caseName = AddCaseName(name);
                if (caseName != null)
                {
                    if (dead)
                    {
                        cache.Add(-100 + index++, caseName);
                    }
                    else
                    {
                        cache.Add(-200 + index++, caseName);
                    }
                }

                List <SimpleItemInfo> infos = new List <SimpleItemInfo>();
                foreach (var item in dic[name])
                {
                    object obj = SingletonManager.Get <DeadBoxParser>().FromString(item.freeData.Value);
                    if (obj == null)
                    {
                        continue;
                    }

                    SimpleItemInfo info = (SimpleItemInfo)obj;
                    info.entityId = item.entityKey.Value.EntityId;

                    infos.Add(info);
                }

                infos.Sort(new ItemInfoSorter());

                foreach (SimpleItemInfo info in infos)
                {
                    int count = info.count;
                    if (info.cat == (int)ECategory.Weapon)
                    {
                        count = 0;
                    }
                    if (info.cat == (int)ECategory.Avatar)
                    {
                        count = 0;
                    }
                    ItemBar prefab = AddChild(info.cat, info.id, count, info.entityId);

                    if (prefab != null)
                    {
                        cache.Add(info.entityId, prefab);
                    }
                }
            }
        }
예제 #3
0
        private void RefreshBag(Contexts context, PlayerEntity player)
        {
            if (CurrentBag != null && (lastBag == null || lastBag != CurrentBag))
            {
                lastBag = CurrentBag;

                foreach (ItemBar prefab in bagDic)
                {
                    ReturnObject(prefab);
                }

                bagDic.Clear();

                List <BagItem> items = new List <BagItem>();

                for (int i = 0; i < CurrentBag.Ins[0]; i++)
                {
                    string key      = CurrentBag.Ss[i * 3 + 1];
                    string eventKey = CurrentBag.Ss[i * 3 + 2];
                    string count    = CurrentBag.Ss[i * 3 + 3];

                    BagItem item = new BagItem();
                    item.key      = key;
                    item.eventKey = eventKey;
                    item.count    = count;

                    item.cat = CurrentBag.Ins[i * 2 + 1];
                    item.id  = CurrentBag.Ins[i * 2 + 2];

                    items.Add(item);
                }

                items.Sort(new BagItemSorter());

                foreach (BagItem item in items)
                {
                    ItemBar prefab = AddItem(item, item.key, item.eventKey, item.count);
                    if (prefab != null)
                    {
                        bagDic.Add(prefab);
                    }
                }

                SetWeight();
            }
        }
예제 #4
0
        private void ReturnObject(ItemBar bar)
        {
            FreePrefabComponent prefab = bar.prefab;
            GameObject          obj    = (GameObject)prefab.currentObject;

            if (obj != null)
            {
                obj.GetComponent <Transform>().parent = null;
                FreePrefabLoader.ReturnGameObject(obj, prefab.assetInfo);

                string   imgUrl      = "";
                string[] fieldValues = bar.value.Split(FreeMessageConstant.SpliterRecord);

                foreach (string fieldValue in fieldValues)
                {
                    string[] vs = fieldValue.Split(FreeMessageConstant.SpilterField);
                    if (vs.Length == 2)
                    {
                        if (vs[0].Trim() == "IMG_WeaponIcon")
                        {
                            imgUrl = vs[1].Trim();
                        }
                    }
                }

                GameObject img = UnityUiUtility.FindUIObject(obj, "IMG_WeaponIcon");
                if (img != null && !string.IsNullOrEmpty(imgUrl))
                {
                    int       last       = imgUrl.Trim().LastIndexOf("/");
                    string    buddleName = imgUrl.Trim().Substring(0, last);
                    string    assetName  = imgUrl.Trim().Substring(last + 1);
                    AssetInfo info       = new AssetInfo(buddleName, assetName);

                    Graphic gra = img.GetComponent <Graphic>();
                    if (gra is Image)
                    {
                        FreeUILoader.ReturnGameObject(((Image)gra).sprite, info);
                    }
                    if (gra is RawImage)
                    {
                        FreeUILoader.ReturnGameObject(((RawImage)gra).texture, info);
                    }
                }
            }
        }
예제 #5
0
        private ItemBar AddChild(int cat, int id, int count, int entityId)
        {
            ItemBar bar = new ItemBar();
            string  key = (cat * 10000 + id) + "_itemUI";

            SimpleProto model = SingletonManager.Get <FreeUiManager>().GetUIData(key);

            if (model == null)
            {
                Debug.LogWarningFormat("item '{0}' is not defined.", key);
                return(null);
            }

            FreePrefabComponent ff = new FreePrefabComponent();

            ff.parentObject = parentGround;
            TipUtil.AddTip("ground,0," + entityId, new TipData(cat, id, count));

            ff.Initial(model.Ss[2], model.Ss[3]);
            if (count > 0)
            {
                ff.SetValues("TEXT_ItemNumber" + FreeMessageConstant.SpilterField + count);
            }
            else
            {
                ff.SetValues("TEXT_ItemNumber" + FreeMessageConstant.SpilterField + " ");
            }

            ff.SetEvents("");
            ff.SetAllEventKey("ground,0," + entityId);

            bar.prefab = ff;
            bar.value  = model.Ss[2].Split(FreeMessageConstant.SpliterStyle)[1];

            return(bar);
        }
예제 #6
0
        private ItemBar AddCaseName(string name)
        {
            ItemBar     bar   = new ItemBar();
            SimpleProto model = SingletonManager.Get <FreeUiManager>().GetUIData("caseName");

            if (model == null)
            {
                Debug.LogWarningFormat("item 'caseName' is not defined.");
                return(null);
            }

            FreePrefabComponent ff = new FreePrefabComponent();

            ff.parentObject = parentGround;

            ff.Initial(model.Ss[2], model.Ss[3]);
            ff.SetValues("TEXT_CaseName" + FreeMessageConstant.SpilterField + name);
            ff.SetEvents("");

            bar.prefab = ff;
            bar.value  = "";

            return(bar);
        }
예제 #7
0
        private void RefreshGround(Contexts context, PlayerEntity player)
        {
            HashSet <int> current = new HashSet <int>();

            foreach (var item in context.sceneObject.GetEntities())
            {
                if (item.hasPosition &&
                    IsNear(item.position.Value, player.position.Value) &&
                    item.hasSimpleEquipment && item.simpleEquipment.Category > 0 &&
                    HasNoObstacle(item, player))
                {
                    current.Add(item.entityKey.Value.EntityId);
                }
            }

            foreach (var item in context.freeMove.GetEntities())
            {
                if (item.hasPosition &&
                    item.hasFreeData &&
                    IsNear(item.position.Value, player.position.Value) &&
                    HasNoObstacle(item, player))
                {
                    current.Add(item.entityKey.Value.EntityId);
                }
            }

            if (!current.SetEquals(groundEntitySet))
            {
                Debug.LogFormat("当前列表{0}, 上次列表{1}", ToSetString(current), ToSetString(groundEntitySet));

                List <SceneObjectEntity> list = new List <SceneObjectEntity>();
                Dictionary <string, List <FreeMoveEntity> > deadList = new Dictionary <string, List <FreeMoveEntity> >();
                Dictionary <string, List <FreeMoveEntity> > dropList = new Dictionary <string, List <FreeMoveEntity> >();

                foreach (var id in current)
                {
                    var sceneEntity = context.sceneObject.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(id, (short)EEntityType.SceneObject));
                    if (null != sceneEntity)
                    {
                        list.Add(sceneEntity);
                        continue;
                    }
                    var freeMoveEntity = context.freeMove.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(id, (short)EEntityType.FreeMove));
                    {
                        if (freeMoveEntity.freeData.Cat == FreeEntityConstant.DeadBox)
                        {
                            if (!deadList.ContainsKey(freeMoveEntity.freeData.Key))
                            {
                                deadList.Add(freeMoveEntity.freeData.Key, new List <FreeMoveEntity>());
                            }
                            deadList[freeMoveEntity.freeData.Key].Add(freeMoveEntity);
                        }
                        if (freeMoveEntity.freeData.Cat == FreeEntityConstant.DropBox)
                        {
                            if (!dropList.ContainsKey(freeMoveEntity.freeData.Key))
                            {
                                dropList.Add(freeMoveEntity.freeData.Key, new List <FreeMoveEntity>());
                            }
                            dropList[freeMoveEntity.freeData.Key].Add(freeMoveEntity);
                        }
                    }
                }

                //foreach (var item in context.sceneObject.GetEntities())
                //{
                //    if (item.hasPosition && IsNear(item.position.Value, player.position.Value) && item.hasSimpleEquipment && item.simpleEquipment.Category > 0
                //        && HasNoObstacle(item, player))
                //    {
                //        list.Add(item);
                //    }
                //}

                //foreach (var item in context.freeMove.GetEntities())
                //{
                //    if (item.hasPosition && item.hasFreeData && IsNear(item.position.Value, player.position.Value) && HasNoObstacle(item, player))
                //    {
                //        if (item.freeData.Cat == FreeEntityConstant.DeadBox)
                //        {
                //            if (!deadList.ContainsKey(item.freeData.Key))
                //            {
                //                deadList.Add(item.freeData.Key, new List<FreeMoveEntity>());
                //            }
                //            deadList[item.freeData.Key].Add(item);
                //        }
                //        if (item.freeData.Cat == FreeEntityConstant.DropBox)
                //        {
                //            if (!dropList.ContainsKey(item.freeData.Key))
                //            {
                //                dropList.Add(item.freeData.Key, new List<FreeMoveEntity>());
                //            }
                //            dropList[item.freeData.Key].Add(item);
                //        }
                //    }
                //}

                foreach (ItemBar prefab in groundDic.Values)
                {
                    ReturnObject(prefab);
                }

                groundDic.Clear();

                FillBox(dropList, groundDic, false);
                FillBox(deadList, groundDic, true);

                list.Sort(new SceneObjectSorter());

                if (list.Count > 0)
                {
                    ItemBar caseName = AddCaseName("地面");
                    if (caseName != null)
                    {
                        groundDic.Add(-1, caseName);
                    }
                }
                foreach (var item in list)
                {
                    if (item.simpleEquipment.Category == (int)ECategory.Weapon)
                    {
                        WeaponConfigNs.WeaponResConfigItem weapon = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(item.simpleEquipment.Id);
                        if (weapon.Type != (int)EWeaponType_Config.ThrowWeapon)
                        {
                            item.simpleEquipment.Count = 0;
                        }
                    }
                    if (item.simpleEquipment.Category == (int)ECategory.Avatar)
                    {
                        item.simpleEquipment.Count = 0;
                    }

                    ItemBar prefab = AddChild(item.simpleEquipment.Category, item.simpleEquipment.Id, item.simpleEquipment.Count, item.entityKey.Value.EntityId);

                    if (prefab != null)
                    {
                        groundDic.Add(item.entityKey.Value.EntityId, prefab);
                    }
                }

                groundEntitySet = current;
            }
        }