예제 #1
0
        /// <summary>
        /// 执行保存到二进制中
        /// </summary>
        /// <returns></returns>
        public override AssetAssemblyResult Execute()
        {
            AssetAddressAssemblyResult result = new AssetAddressAssemblyResult();

            foreach (var group in m_AssetGroups)
            {
                group.Execute(result);
            }

            //读取配置
            AssetBundleTagConfig tagConfig = Util.FileUtil.ReadFromBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath());

            if (tagConfig.GroupDatas == null)
            {
                tagConfig.GroupDatas = new List <AssetBundleGroupData>();
            }
            else
            {
                tagConfig.GroupDatas.Clear();
            }

            foreach (var groupResult in result.m_GroupResults)
            {
                AssetAddressGroupResult gResult = groupResult as AssetAddressGroupResult;

                AssetBundleGroupData groupData = new AssetBundleGroupData();
                groupData.GroupName    = gResult.m_GroupName;
                groupData.IsGenAddress = gResult.m_IsGenAddress;
                groupData.IsMain       = gResult.m_IsMain;
                groupData.IsPreload    = gResult.m_IsPreload;

                tagConfig.GroupDatas.Add(groupData);

                foreach (var operationResult in gResult.m_OperationResults)
                {
                    AssetAddressOperationResult oResult = operationResult as AssetAddressOperationResult;
                    foreach (var kvp in oResult.m_AddressDataDic)
                    {
                        AssetAddressData aaData   = new AssetAddressData();
                        AssetAddressData kvpValue = kvp.Value as AssetAddressData;

                        aaData.AssetAddress = kvpValue.AssetAddress;
                        aaData.AssetPath    = kvpValue.AssetPath;
                        aaData.BundlePath   = kvpValue.BundlePath;
                        aaData.Labels       = new List <string>(kvpValue.Labels).ToArray();

                        groupData.AssetDatas.Add(aaData);
                    }
                }
            }

            //保存配置
            Util.FileUtil.SaveToBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath(), tagConfig);

            return(result);
        }
예제 #2
0
        private Dictionary <string, int> m_AssetUsedCountDic               = new Dictionary <string, int>();            //统计到的资源的使用次数

        /// <summary>
        /// 根据配置文件查找资源的依赖情况
        /// </summary>
        /// <param name="tagConfig"></param>
        public void Find(AssetBundleTagConfig tagConfig)
        {
            m_BundleAssetPathList = (from groupData in tagConfig.GroupDatas
                                     from detailData in groupData.AssetDatas
                                     select detailData.AssetPath).ToList();
            m_FindIndex = 0;
            DealWithAtlas();

            //处理非Atlas的资源,查找其引用的资源
            m_BundleAssetPathList.ForEach((path) =>
            {
                if (!(Path.GetExtension(path).ToLower() == ".spriteatlas"))
                {
                    ProgressCallback?.Invoke(path, m_FindIndex / (float)m_BundleAssetPathList.Count);
                    m_FindIndex++;

                    List <string> depends = new List <string>();
                    FindAssetDependExcludeBundle(path, depends, new string[] { ".cs", ".shader" });
                    m_BundleDependAssetDic.Add(path, depends);
                }
            });

            //统计所有资源的使用次数
            foreach (var kvp in m_BundleDependAssetDic)
            {
                foreach (var path in kvp.Value)
                {
                    if (m_AssetUsedCountDic.ContainsKey(path))
                    {
                        m_AssetUsedCountDic[path]++;
                    }
                    else
                    {
                        m_AssetUsedCountDic.Add(path, 1);
                    }
                }
            }
        }
예제 #3
0
        private void OnEnable()
        {
            AssetBundleTagConfig tagConfig = Util.FileUtil.ReadFromBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath());

            m_Finder = BundlePackUtil.CreateAssetDependFinder(tagConfig, true);
        }