Esempio n. 1
0
        void TryFillUpDressItem(CocoDressItemHolder itemHolder, List <string> shouldAddedItemIds, List <string> currItemIds, bool onlyInMainCategory = false)
        {
            if (itemHolder == null)
            {
                return;
            }

            // check if in main category
            if (onlyInMainCategory)
            {
                CocoDressCategoryHolder categoryHolder = (CocoDressCategoryHolder)itemHolder.ParentHolder;
                if (!categoryHolder.isMain)
                {
                    return;
                }
            }

            // check if conflict with will added items
            List <CocoDressItemConflictData> lastConflictDatas = GetDressConflictDatas(itemHolder, shouldAddedItemIds);

            if (lastConflictDatas.Count > 0)
            {
                return;
            }

            // check if conflict with current existed items
            lastConflictDatas = GetDressConflictDatas(itemHolder, currItemIds);
            if (lastConflictDatas.Count > 0)
            {
                return;
            }

            // Debug.LogError ("fill: " + itemHolder.id);
            shouldAddedItemIds.Add(itemHolder.id);
        }
Esempio n. 2
0
        void AddDressModelSet(CocoDressItemHolder itemHolder, List <GameObject> itemModels)
        {
            CocoDressItemModelSet modelSet = new CocoDressItemModelSet(itemHolder);

            modelSet.ItemRenderers = new List <SkinnedMeshRenderer> ();
            itemModels.ForEach(model => {
                RebindModelBone(model);

                SkinnedMeshRenderer[] smrs = model.GetComponentsInChildren <SkinnedMeshRenderer> ();
                smrs.ForEach(smr => {
                    smr.transform.SetParent(m_RootBone, false);
                    smr.gameObject.layer = m_RootBone.gameObject.layer;
                    modelSet.ItemRenderers.Add(smr);

                    if (OnRendererChanged != null)
                    {
                        OnRendererChanged(smr, true);
                    }
                });

                Destroy(model);
            });

            m_DressData.AddDress(modelSet);
        }
Esempio n. 3
0
        CocoDressItemConflictData GetDressConflictData(CocoDressItemHolder newItemHolder, CocoDressItemHolder oldItemHolder)
        {
            if (newItemHolder.IsCoverLayerConflicted(oldItemHolder) || newItemHolder == oldItemHolder)
            {
                CocoDressItemConflictData conflictData = new CocoDressItemConflictData();
                conflictData.itemHolder = oldItemHolder;
                return(conflictData);
            }

            return(null);
        }
Esempio n. 4
0
 public void ResetDressItem(string itemId, System.Action <CocoDressItemHolder> endAction = null)
 {
     ResetDressItem(new List <string> {
         itemId
     }, itemHolders => {
         CocoDressItemHolder itemHolder = (itemHolders != null && itemHolders.Count > 0) ? itemHolders [0] : null;
         if (endAction != null)
         {
             endAction(itemHolder);
         }
     });
 }
        private List <GameObject> LoadItemModels(CocoDressItemHolder itemHolder)
        {
            var modelHolders = itemHolder.modelHolders;
            var modelGos     = new List <GameObject> (modelHolders.Count);

            for (var i = 0; i < modelHolders.Count; i++)
            {
                var go = LoadModel(modelHolders [i]);
                go.name = itemHolder.id + "_" + i;
                modelGos.Add(go);
                //Debug.LogError (itemHolder.id + ":" + go.name);
            }

            return(modelGos);
        }
Esempio n. 6
0
        private CocoDressItemHolder GenerateItem(string itemId)
        {
            var itemHolder = new CocoDressItemHolder {
                id = itemId
            };

            // match cover layer
            _editorConfigHolder.dressItemPrefixCoverLayerIds.ForEach((itemIdPrefix, coverLayerId) => {
                if (itemId.StartsWith(itemIdPrefix))
                {
                    itemHolder.coverLayerId = coverLayerId;
                }
            });

            return(itemHolder);
        }
Esempio n. 7
0
        List <CocoDressItemConflictData> GetDressConflictDatas(CocoDressItemHolder itemHolder)
        {
            List <CocoDressItemConflictData> conflictDatas = new List <CocoDressItemConflictData> ();

            if (itemHolder != null)
            {
                m_CurrDressModelSetDic.ForEach(modelSet => {
                    CocoDressItemConflictData conflictData = GetDressConflictData(itemHolder, modelSet.ItemHolder);
                    if (conflictData != null)
                    {
                        conflictDatas.Add(conflictData);
                    }
                });
            }

            return(conflictDatas);
        }
Esempio n. 8
0
        List <CocoDressItemConflictData> GetDressConflictDatas(CocoDressItemHolder itemHolder, List <string> checkedItemIds)
        {
            List <CocoDressItemConflictData> conflictDatas = new List <CocoDressItemConflictData> ();

            if (itemHolder != null && checkedItemIds != null)
            {
                checkedItemIds.ForEach(itemId => {
                    CocoDressItemHolder checkedItemHolder  = m_ItemHolderDic.GetValue(itemId);
                    CocoDressItemConflictData conflictData = GetDressConflictData(itemHolder, checkedItemHolder);
                    if (conflictData != null)
                    {
                        conflictDatas.Add(conflictData);
                    }
                });
            }

            return(conflictDatas);
        }
Esempio n. 9
0
        private void FillModelContentsInItem(CocoDressItemHolder itemHolder, Dictionary <string, bool> modelPaths)
        {
            var usedPath = string.Empty;

            foreach (var kvpModelPath in modelPaths)
            {
                var modelPath = kvpModelPath.Key;
                var modelId   = Path.GetFileNameWithoutExtension(modelPath);
                if (string.IsNullOrEmpty(modelId))
                {
                    continue;
                }
                if (!itemHolder.id.StartsWith(modelId))
                {
                    continue;
                }

                var modelHolder = itemHolder.modelHolders [0];
                modelHolder.id        = modelId;
                modelHolder.assetPath = GetRelativePath(modelPath);
                usedPath = modelPath;
                break;
            }

            var changedPath = _owner.OnItemModelContentFilled(itemHolder);

            if (string.IsNullOrEmpty(usedPath) && !string.IsNullOrEmpty(changedPath))
            {
                usedPath = changedPath;
            }

            if (string.IsNullOrEmpty(usedPath))
            {
                Debug.LogWarningFormat("[{0}]->FillModelContentsInItem: can NOT found model for item [{1}]!", GetType().Name, itemHolder.id);
            }
            else
            {
                if (modelPaths.ContainsKey(usedPath))
                {
                    modelPaths [usedPath] = true;
                }
            }
        }
Esempio n. 10
0
        void CheckChangeForRemoveItem(CocoDressItemModelSet modelSet)
        {
            modelSet.ItemRenderers.ForEach(smr => {
                if (m_RendererDic.ContainsKey(smr.name))
                {
                    m_RendererDic.Remove(smr.name);
                }
            });

            CocoDressItemHolder     itemHolder     = modelSet.ItemHolder;
            CocoDressCategoryHolder categoryHolder = (CocoDressCategoryHolder)itemHolder.ParentHolder;

            if (!categoryHolder.isMain)
            {
                return;
            }

            // record last item, in order to resume it
            var layer = itemHolder.CoverLayer;

            if (m_LastCoverItemHolderDic.ContainsKey(layer))
            {
                m_LastCoverItemHolderDic [layer] = itemHolder;
                int index = m_SortedLastCovers.IndexOf(layer);
                for (int i = index + 1; i < m_SortedLastCovers.Count; i++)
                {
                    m_SortedLastCovers [i - 1] = m_SortedLastCovers [i];
                }
                m_SortedLastCovers [m_SortedLastCovers.Count - 1] = layer;
                //Debug.LogError ("update " + layer + " -> " + itemHolder.id);
            }
            else
            {
                m_LastCoverItemHolderDic.Add(layer, itemHolder);
                //Debug.LogError ("add " + layer + " -> " + itemHolder.id);
                m_SortedLastCovers.Add(layer);
            }
        }
        private void SetItemTag(CocoDressItemHolder itemHolder, string tag)
        {
            // model
            foreach (var modelHolder in itemHolder.modelHolders)
            {
                var modelPath = GetAssetPath(modelHolder.assetPath);
                SetAssetTag(modelPath, tag, modelHolder.id);

                // material
                foreach (var materialHolder in modelHolder.materialHolders)
                {
                    var materialPath = GetAssetPath(materialHolder.assetPath);
                    if (SetAssetTag(materialPath, tag, materialHolder.id))
                    {
                        SetMaterialContentTag(materialPath, tag);
                    }
                }
            }

            // icon
            foreach (var spriteHolder in itemHolder.spriteHolders)
            {
                var iconPath = GetAssetPath(spriteHolder.assetPath);
                SetAssetTag(iconPath, tag, spriteHolder.id);

                // icon material
                if (spriteHolder.materialHolder == null)
                {
                    continue;
                }

                var materialPath = GetAssetPath(spriteHolder.materialHolder.assetPath);
                if (SetAssetTag(materialPath, tag, spriteHolder.materialHolder.id))
                {
                    SetMaterialContentTag(materialPath, tag);
                }
            }
        }
Esempio n. 12
0
        private void FillSpriteContentsInItem(CocoDressItemHolder itemHolder, Dictionary <string, bool> spritePaths,
                                              Dictionary <string, bool> spriteMaterialPaths)
        {
            var usedPath = string.Empty;

            foreach (var kvpSpritePath in spritePaths)
            {
                var spritePath = kvpSpritePath.Key;
                var spriteId   = Path.GetFileNameWithoutExtension(spritePath);
                if (string.IsNullOrEmpty(spriteId))
                {
                    continue;
                }
                if (!itemHolder.id.StartsWith(spriteId))
                {
                    continue;
                }

                var spriteHolder = new CocoAssetSpriteHolder {
                    id = spriteId, assetPath = GetRelativePath(spritePath)
                };
                itemHolder.spriteHolders.Add(spriteHolder);

                FillMaterialContentsInSprite(spriteHolder, itemHolder.id, spriteMaterialPaths);
                usedPath = spritePath;
                break;
            }

            if (string.IsNullOrEmpty(usedPath))
            {
                Debug.LogErrorFormat("[{0}]->FillSpriteContentsInItem: can NOT found sprite for item [{1}]!", GetType().Name, itemHolder.id);
            }
            else
            {
                spritePaths [usedPath] = true;
            }
        }
Esempio n. 13
0
 public CocoDressItemModelSet(CocoDressItemHolder itemHolder)
 {
     ItemHolder = itemHolder;
 }
Esempio n. 14
0
        public List <string> PrepareRemoveDressItems(List <string> itemIds, out List <CocoDressItemConflictData> conflictDatas)
        {
            // make will removed items as conflict datas
            Dictionary <string, CocoDressItemConflictData> itemConflictDataDic = new Dictionary <string, CocoDressItemConflictData> ();

            itemIds.ForEach(itemId => {
                if (!itemConflictDataDic.ContainsKey(itemId))
                {
                    CocoDressItemHolder itemHolder = m_ItemHolderDic.GetValue(itemId);
                    if (itemHolder != null)
                    {
                        CocoDressItemConflictData conflictData = new CocoDressItemConflictData();
                        conflictData.itemHolder = itemHolder;
                        itemConflictDataDic.Add(itemId, conflictData);
                    }
                    else
                    {
                        Debug.LogErrorFormat("{0}->PrepareAddDressItems: item [{1}] NOT exists in asset config !", GetType().Name, itemId);
                    }
                }
            });

            // find should added items
            List <string> shouldAddedItemIds = new List <string> ();

            // curr items
            List <string> currItemIds = new List <string> ();

            m_CurrDressModelSetDic.Keys.ForEach(itemId => {
                if (!itemConflictDataDic.ContainsKey(itemId))
                {
                    currItemIds.Add(itemId);
                }
            });

            // try add last items
            for (int i = m_SortedLastCovers.Count - 1; i >= 0; i--)
            {
                CocoDressItemHolder lastItemHolder = m_LastCoverItemHolderDic [m_SortedLastCovers [i]];
                if (itemConflictDataDic.ContainsKey(lastItemHolder.id))
                {
                    // should removed, skip it
                    continue;
                }

                TryFillUpDressItem(lastItemHolder, shouldAddedItemIds, currItemIds);
            }

            // try add basic items
            for (int i = m_BasicItemIds.Count - 1; i >= 0; i--)
            {
                CocoDressItemHolder basicItemHolder = m_ItemHolderDic.GetValue(m_BasicItemIds [i]);
                TryFillUpDressItem(basicItemHolder, shouldAddedItemIds, currItemIds, true);
            }

            // try add will remove items (if not other choice)
            foreach (var itemId in itemIds)
            {
                CocoDressItemHolder willRemoveItemHolder = m_ItemHolderDic.GetValue(itemId);
                TryFillUpDressItem(willRemoveItemHolder, shouldAddedItemIds, currItemIds, true);
            }

            // if should add, don't remove them
            HashSet <string> shouldAddedItemIdSet = new HashSet <string> (shouldAddedItemIds);

            shouldAddedItemIdSet.ForEach(itemId => {
                if (itemConflictDataDic.ContainsKey(itemId))
                {
                    itemConflictDataDic.Remove(itemId);
                    shouldAddedItemIds.Remove(itemId);
                }
            });

            //string str = "PrepareRemoveDressItems should add: ";
            //shouldAddedItemIds.ForEach (itemId => str += itemId + ", ");
            //str += " conflict: ";
            //itemConflictDataDic.Keys.ForEach (itemId => str += itemId + ", ");
            //Debug.LogError (str);

            conflictDatas = new List <CocoDressItemConflictData> (itemConflictDataDic.Values);
            return(shouldAddedItemIds);
        }
Esempio n. 15
0
        public List <string> PrepareAddDressItems(List <string> itemIds, out List <CocoDressItemConflictData> conflictDatas)
        {
            // check conflict
            Dictionary <string, CocoDressItemConflictData> itemConflictDataDic = new Dictionary <string, CocoDressItemConflictData> ();

            itemIds.ForEach(itemId => {
                CocoDressItemHolder itemHolder = m_ItemHolderDic.GetValue(itemId);
                if (itemHolder != null)
                {
                    List <CocoDressItemConflictData> itemConflictDatas = GetDressConflictDatas(itemHolder);
                    itemConflictDatas.ForEach(conflictData => {
                        if (!itemConflictDataDic.ContainsKey(conflictData.itemHolder.id))
                        {
                            itemConflictDataDic.Add(conflictData.itemHolder.id, conflictData);
                        }
                    });
                }
                else
                {
                    Debug.LogErrorFormat("{0}->PrepareAddDressItems: item [{1}] NOT exists in asset config !", GetType().Name, itemId);
                }
            });

            // find should added items
            List <string> shouldAddedItemIds = new List <string> ();

            // curr items
            List <string> currItemIds = new List <string> ();

            m_CurrDressModelSetDic.Keys.ForEach(itemId => {
                if (!itemConflictDataDic.ContainsKey(itemId))
                {
                    currItemIds.Add(itemId);
                }
            });

            // try add expected items
            for (int i = itemIds.Count - 1; i >= 0; i--)
            {
                CocoDressItemHolder expectedItemHolder = m_ItemHolderDic.GetValue(itemIds [i]);
                TryFillUpDressItem(expectedItemHolder, shouldAddedItemIds, currItemIds);
            }

            // try add last items
            for (int i = m_SortedLastCovers.Count - 1; i >= 0; i--)
            {
                CocoDressItemHolder lastItemHolder = m_LastCoverItemHolderDic [m_SortedLastCovers [i]];
                TryFillUpDressItem(lastItemHolder, shouldAddedItemIds, currItemIds);
            }

            // try add basic items
            for (int i = m_BasicItemIds.Count - 1; i >= 0; i--)
            {
                CocoDressItemHolder basicItemHolder = m_ItemHolderDic.GetValue(m_BasicItemIds [i]);
                TryFillUpDressItem(basicItemHolder, shouldAddedItemIds, currItemIds, true);
            }

            //string str = "PrepareAddDressItems should add: ";
            //shouldAddedItemIds.ForEach (itemId => str += itemId + ", ");
            //str += " conflict: ";
            //itemConflictDataDic.Keys.ForEach (itemId => str += itemId + ", ");
            //Debug.LogError (str);

            conflictDatas = new List <CocoDressItemConflictData> (itemConflictDataDic.Values);
            return(shouldAddedItemIds);
        }
 public string OnItemModelContentFilled(CocoDressItemHolder itemHolder)
 {
     return(OnAfterFindModel != null?OnAfterFindModel(itemHolder) : string.Empty);
 }