Пример #1
0
        private void InitItemDic()
        {
            m_ItemHolderDic = CocoData.CreateDictionary(itemHolders, itemHolder => itemHolder.id);

            var configHolder = ParentHolder.ParentHolder as CocoAssetConfigHolder;

            if (configHolder == null)
            {
                return;
            }

            var itemHolderDic = configHolder.ItemHolderDic;

            foreach (var sceneItemHolder in itemHolders)
            {
                var dressItemHolder = itemHolderDic.GetValue(sceneItemHolder.id);
                if (dressItemHolder == null)
                {
                    continue;
                }

                sceneItemHolder.LinkedDressItemHolder = dressItemHolder;
                dressItemHolder.LinkedSceneItemHolder = sceneItemHolder;
            }
        }
Пример #2
0
        public List <T> GetRandomSuitItems <T> (Dictionary <string, List <CocoRoleDressItemHolder> > categoryItemHolders,
                                                System.Func <CocoRoleDressItemHolder, T> extractFunc, bool onlyOwned = false)
        {
            var suitItems = new List <T> ();

            var configHolder      = (CocoAssetConfigHolder)ParentHolder;
            var suitCategoryIds   = configHolder.GetRandomSuitCategoryIds(categoryItemHolders.Keys);
            var count             = suitCategoryIds.Count;
            var randomIdGenerator = new CocoRandomIdGenerator(count);
            var stateModel        = onlyOwned ? CocoRoot.GetInstance <CocoDressStateModel> () : null;

            for (var i = 0; i < count; i++)
            {
                var categoryId = suitCategoryIds [randomIdGenerator.RandomId];
                var currCategoryItemHolders = categoryItemHolders [categoryId];

                CocoRoleDressItemHolder itemHolder;
                if (!onlyOwned)
                {
                    itemHolder = CocoData.GetRandomItem(currCategoryItemHolders);
                }
                else
                {
                    var ownedItemHolders = GetOwnedItemHoldersInList(currCategoryItemHolders, stateModel);
                    itemHolder = CocoData.GetRandomItem(ownedItemHolders);
                }
                if (itemHolder != null)
                {
                    suitItems.Add(extractFunc(itemHolder));
                }
            }

            return(suitItems);
        }
Пример #3
0
        void InitTexture(int pWidth, int pHeight, Color pColor)
        {
            // pixels
            mTargetPixels = CocoData.CreateArray <Color32> (pWidth * pHeight, pColor);

            // target texture
            mTargetTexture = new Texture2D(pWidth, pHeight, TextureFormat.ARGB32, false);
            mTargetTexture.SetPixels32(mTargetPixels);
            mTargetTexture.Apply();
            TargetMaterial.SetTexture(mTargetMaterialProperty, mTargetTexture);
        }
        private static void LoadEditorConfig()
        {
            // load config
            var path = CocoDressEditorHelper.GetFullPath(CocoDressSettings.EditorConfigFilePath);

            m_EditConfigHolder = CocoData.LoadFromJsonFile <CocoDressEditorConfigHolder> (path);

            // fix default config
            FixEditorDefaultConfig();

            UpdateAssetFullDirectory();
        }
Пример #5
0
        public CocoRoleDressItemHolder GetRandomItemHolder(bool onlyOwned = false)
        {
            if (!onlyOwned)
            {
                return(CocoData.GetRandomItem(itemHolders));
            }

            var stateModel          = CocoRoot.GetInstance <CocoDressStateModel> ();
            var randomInItemHolders = ((CocoRoleDressHolder)ParentHolder).GetOwnedItemHoldersInList(itemHolders, stateModel);

            return(CocoData.GetRandomItem(randomInItemHolders));
        }
Пример #6
0
        public void SaveToFile(string rootDirectory, bool prettyPrint)
        {
            if (m_AssetEntity == null)
            {
                Debug.LogWarningFormat("[{0}]->SaveToFile: asset [{1}] NOT loaded!", GetType().Name, assetPath);
                return;
            }


            var path = Path.Combine(rootDirectory, assetPath);

            CocoData.SaveToJsonFile(m_AssetEntity, path, prettyPrint);
        }
        private void SaveEditorConfig()
        {
            if (m_EditConfigHolder == null)
            {
                return;
            }

            var path = CocoDressEditorHelper.GetFullPath(CocoDressSettings.EditorConfigFilePath);

            CocoData.SaveToJsonFile(m_EditConfigHolder, path, true);

            AssetDatabase.Refresh();
        }
        private void LoadAssetConfig()
        {
            var path = Path.Combine(_assetConfigFullDirectory, m_EditConfigHolder.globalConfigFileName);

            m_AssetConfigHolder = CocoData.LoadFromJsonFile <CocoAssetConfigHolder> (path);

            if (m_AssetConfigHolder == null)
            {
                return;
            }

            m_AssetConfigHolder.LoadSubConfigs(_rootFullDirectory);
            m_AssetConfigHolder.LinkParent(null);
        }
Пример #9
0
        public CocoRoleDressItemHolder GetRandomItemHolder(string categoryId, bool onlyOwned = false)
        {
            var categoryItemHolders = m_CategoryItemHolderDic.GetValue(categoryId);

            if (!onlyOwned)
            {
                return(CocoData.GetRandomItem(categoryItemHolders));
            }

            var stateModel          = CocoRoot.GetInstance <CocoDressStateModel> ();
            var randomInItemHolders = ((CocoRoleDressHolder)ParentHolder).GetOwnedItemHoldersInList(categoryItemHolders, stateModel);

            return(CocoData.GetRandomItem(randomInItemHolders));
        }
        private void SaveAssetConfig()
        {
            if (m_AssetConfigHolder == null)
            {
                return;
            }

            m_AssetConfigHolder.SaveSubConfigs(_rootFullDirectory, m_EditConfigHolder.prettyPrint);

            var path = Path.Combine(_assetConfigFullDirectory, m_EditConfigHolder.globalConfigFileName);

            CocoData.SaveToJsonFile(m_AssetConfigHolder, path, true);

            AssetDatabase.Refresh();
        }
Пример #11
0
        private TConfig GenerateConfig <TConfig, THolder> (THolder holder, string tag)
            where TConfig : CocoAssetJsonHolder <THolder>, new () where THolder : CocoHolderBase
        {
            var id   = string.Format("config_{0}_{1}", tag, holder.id);
            var path = Path.Combine(_assetConfigFullDirectory, id + ".json");

            if (!CocoData.SaveToJsonFile(holder, path, true))
            {
                return(null);
            }

            var categoryConfigHolder = new TConfig {
                id = id, assetPath = GetRelativePath(path)
            };

            return(categoryConfigHolder);
        }
Пример #12
0
        /**
         * Create Texture (Color32), faster but only support ARGB32
         */
        public static Texture2D CreateColor32Texture(int width, int height, bool applied, TextureFormat format, Color32 color32)
        {
            switch (format)
            {
            case TextureFormat.ARGB32:
                Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
                texture.SetPixels32(CocoData.CreateArray <Color32> (width * height, color32));
                if (applied)
                {
                    texture.Apply();
                }
                return(texture);
            }

            Debug.LogError("CocoTexture->CreateColor32Texture: texture format [" + format + "] NOT supported.");
            return(null);
        }
Пример #13
0
 private void InitCategoryItemIdSet()
 {
     m_CategoryHolderDic = CocoData.CreateDictionary(categoryHolders, categoryHolder => categoryHolder.id);
 }