Exemplo n.º 1
0
        private string GetCommonBundleName(string assetPath)
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(buildItem.assetBundleNameFormat))
            {
                string assetFileName   = Path.GetFileName(assetPath);
                string assetBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleCommonName(_builderName, assetFileName, buildItem.commonPrefixBuildOne);
                return(assetBundleName);
            }
            else
            {
                string buildName = GetName();

                string nameFormat = buildItem.assetBundleNameFormat;
                nameFormat = AssetBuildConfiger.GetInstance().GetFormatBundleName(nameFormat, assetPath);
                nameFormat = nameFormat.Replace("{buildName}", buildName);

                nameFormat = nameFormat.ToLower();
                return(nameFormat);
            }
        }
Exemplo n.º 2
0
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            if (!AssetBuildConfiger.GetInstance())
            {
                return;
            }

            if (!AssetBuildConfiger.GetInstance().isUseDependenciesCache)
            {
                return;
            }

            if (!AssetDependentCollector.GetInstance().IsLoaded)
            {
                return;
            }

            foreach (var assetPath in importedAssets)
            {
                AssetDependentCollector.GetInstance().AddRelation(assetPath);
            }
            foreach (var assetPath in deletedAssets)
            {
                AssetDependentCollector.GetInstance().RemoveRelation(assetPath);
            }
            for (int i = 0; i < movedAssets.Length; i++)
            {
                var srcPath  = movedFromAssetPaths[i];
                var destPath = movedAssets[i];
                AssetDependentCollector.GetInstance().MoveRelation(srcPath, destPath);
            }
        }
Exemplo n.º 3
0
        public virtual void Build()
        {
            Clear();

            var buildList = GetBuildList();

            if (buildList != null && buildList.Count > 0)
            {
                BuildAssetBundleOptions bundleOptions;//打包设置:
                bundleOptions  = BuildAssetBundleOptions.None;
                bundleOptions |= BuildAssetBundleOptions.ChunkBasedCompression;
                bundleOptions |= BuildAssetBundleOptions.DeterministicAssetBundle;
                bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileName;
                bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension;

                var buildExportPath = AssetBuildConfiger.GetInstance().GetExportFolderPath();
                var buildPlatform   = AssetBuildConfiger.GetInstance().GetBuildType();

                if (!XFolderTools.Exists(buildExportPath))
                {
                    XFolderTools.CreateDirectory(buildExportPath);
                }

                BuildPipeline.BuildAssetBundles(buildExportPath, buildList.ToArray(), bundleOptions, buildPlatform);
            }
        }
Exemplo n.º 4
0
        protected override void OnInit()
        {
            var cfgObj = AddObject(AssetBuildConfiger.GetInstance());
            var prop   = AddProperty("buildItemList");

            m_itemSortedList = new ReorderableList(cfgObj, prop, true, true, true, true);
            m_itemSortedList.elementHeight = 90;//设置单个元素的高度

            //绘制单个元素
            m_itemSortedList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                var element = prop.GetArrayElementAtIndex(index);
                rect.height -= 4;
                rect.y      += 2;
                EditorGUI.PropertyField(rect, element);
            };

            //背景色
            m_itemSortedList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) =>
            {
                GUI.backgroundColor = Color.yellow;
            };

            //头部
            m_itemSortedList.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, "常规打包项");
        }
Exemplo n.º 5
0
        //这里需要做下合并,减少ab数量:一个依赖的与依赖合并,一个引用的与引用合并
        private void Build4Share()
        {
            List <string>          shareAssetList  = CollectShare();
            List <AssetBundlePair> shareBundleList = GetOrCreateShareList();

            Dictionary <string, string> depMap = new Dictionary <string, string>();
            Dictionary <string, string> refMap = new Dictionary <string, string>();

            if (AssetBuildConfiger.GetInstance().isOptimzeShareBundle)
            {
                foreach (var assetPath in shareAssetList)
                {
                    string[] dps = AssetBuildRelationship.GetDependencies(assetPath);
                    foreach (var dp in dps)
                    {
                        //忽略自己
                        if (string.Compare(assetPath, dp, true) == 0)
                        {
                            continue;
                        }

                        // 单一依赖
                        if (dps.Length == 2)
                        {
                            depMap[assetPath] = dp;
                        }

                        //单一引用
                        if (refMap.ContainsKey(dp))
                        {
                            refMap[dp] = "";    //已经不是单一引用了
                        }
                        else
                        {
                            refMap[dp] = assetPath;
                        }
                    }
                }
            }

            foreach (var assetPath in shareAssetList)
            {
                string shareBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleShareName(assetPath);//全部打到Share里去
                if (depMap.TryGetValue(assetPath, out var depFilePath))
                {
                    shareBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleShareName(depFilePath);
                }
                else if (refMap.TryGetValue(assetPath, out var refFilePath))
                {
                    if (!string.IsNullOrEmpty(refFilePath))
                    {
                        shareBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleShareName(refFilePath);
                    }
                }

                shareBundleList.Add(new AssetBundlePair(assetPath, shareBundleName));
            }
        }
Exemplo n.º 6
0
 public static string[] GetReferences(string path)
 {
     if (AssetBuildConfiger.GetInstance().isUseDependenciesCache)
     {
         TryUpdate(path);
         return(GetCollector().GetReferences(path));
     }
     else
     {
         return(EMPTY_RET);
     }
 }
Exemplo n.º 7
0
 private void Build()
 {
     if (AssetBuildConfiger.GetInstance().isUseDependenciesCache)
     {
         AssetBuildRelationship.TryLoadCache();
     }
     BuildBefore();
     BuildAll();
     BuildAfter();
     if (AssetBuildConfiger.GetInstance().isUseDependenciesCache)
     {
         AssetBuildRelationship.SaveCache();
     }
 }
Exemplo n.º 8
0
        private string GetShareBundleName(string assetPath)
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(buildItem.shareBundleNameFormat))
            {
                string assetBundleName = AssetBuildConfiger.GetInstance().GetBuildBundleShareName(assetPath);
                return(assetBundleName);
            }
            else
            {
                string buildName = GetName();

                string nameFormat = buildItem.shareBundleNameFormat;
                nameFormat = AssetBuildConfiger.GetInstance().GetFormatBundleName(nameFormat, assetPath);
                nameFormat = nameFormat.Replace("{buildName}", buildName);

                nameFormat = nameFormat.ToLower();
                return(nameFormat);
            }
        }
Exemplo n.º 9
0
        protected override void OnShow()
        {
            GUILayout.BeginVertical();
            m_scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), m_scrollPos, new Rect(0, 0, position.width, 1000));
            //标题
            GUILayout.Space(10);
            GUILayout.Label("打包配置", new GUIStyle(GUI.skin.label)
            {
                fontSize = 24, alignment = TextAnchor.MiddleCenter
            });
            if (GUILayout.Button("打包"))
            {
                AssetBuilderManager.GetInstance().Build();
            }

            AssetBuildConfiger.GetInstance().targetType             = (AssetBuildConfiger.BuildPlatform)EditorGUILayout.EnumPopup("当前平台", AssetBuildConfiger.GetInstance().targetType);
            AssetBuildConfiger.GetInstance().exportFolder           = GUILayoutEx.ShowPathBar("输出目录", AssetBuildConfiger.GetInstance().exportFolder);
            AssetBuildConfiger.GetInstance().shareBundleName        = EditorGUILayout.TextField("公共包名", AssetBuildConfiger.GetInstance().shareBundleName);
            AssetBuildConfiger.GetInstance().isCombinePlatformName  = EditorGUILayout.Toggle("输出目录拼接平台名称", AssetBuildConfiger.GetInstance().isCombinePlatformName);
            AssetBuildConfiger.GetInstance().isOptimzeShareBundle   = EditorGUILayout.Toggle("优化Share打包", AssetBuildConfiger.GetInstance().isOptimzeShareBundle);
            AssetBuildConfiger.GetInstance().isRidofSpecialChar     = EditorGUILayout.Toggle("包名移除特殊字符", AssetBuildConfiger.GetInstance().isRidofSpecialChar);
            AssetBuildConfiger.GetInstance().isUseDependenciesCache = EditorGUILayout.Toggle("使用依赖缓存加速", AssetBuildConfiger.GetInstance().isUseDependenciesCache);

            m_itemSortedList.DoLayoutList();
            EditorGUILayout.HelpBox("包路径说明\n" +
                                    "{assetEx}资源后缀" +
                                    "{assetRootPath}资源父路径" +
                                    "{assetNameNotEx}资源不带后缀名" +
                                    "{assetName}资源名" +
                                    "{assetKey}资源名中到_的部分" +
                                    "{assetFlatPath}资源扁平化路径" +
                                    "{buildName}构建器名", MessageType.Info);

            GUI.EndScrollView();
            GUILayout.EndVertical();
        }
Exemplo n.º 10
0
        private void BuildAll()
        {
            Build4Common();
            Build4Custom();
            Build4Share();

            BuildAssetBundleOptions bundleOptions;//打包设置:

            bundleOptions  = BuildAssetBundleOptions.None;
            bundleOptions |= BuildAssetBundleOptions.ChunkBasedCompression;
            bundleOptions |= BuildAssetBundleOptions.DeterministicAssetBundle;
            bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileName;
            bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension;

            var buildExportPath = AssetBuildConfiger.GetInstance().GetExportFolderPath();
            var buildPlatform   = AssetBuildConfiger.GetInstance().GetBuildType();

            if (!XFolderTools.Exists(buildExportPath))
            {
                XFolderTools.CreateDirectory(buildExportPath);
            }

            BuildPipeline.BuildAssetBundles(buildExportPath, GetBuildsArray(), bundleOptions, buildPlatform);
        }
Exemplo n.º 11
0
        private void BuildBefore()
        {
            //
            var commonItems = AssetBuildConfiger.GetInstance().buildItemList;

            if (commonItems != null && commonItems.Count > 0)
            {
                foreach (var item in commonItems)
                {
                    if (!item.isEnabled)
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(item.builderName))
                    {
                        continue;
                    }

                    AssetBaseBuilder builder = new AssetCommonBuilder(item);
                    m_builderCommonList.Add(builder);
                }
            }

            //通过反射获取所有类
            Type[]      types             = Assembly.GetCallingAssembly().GetTypes();
            List <Type> builderClassList  = new List <Type>();
            Type        customBuilderType = typeof(AssetCustomBuilder);

            foreach (Type item in types)
            {
                if (item.IsAbstract)
                {
                    continue;
                }
                if (item == customBuilderType)
                {
                    continue;
                }

                if (item.BaseType == customBuilderType)
                {
                    builderClassList.Add(item);
                }
            }

            SortedList <int, AssetBaseBuilder> sortedClassList = new SortedList <int, AssetBaseBuilder>(new BuilderComparer());

            foreach (Type item in builderClassList)
            {
                object             obj     = Activator.CreateInstance(item);//创建一个obj对象
                AssetCustomBuilder builder = obj as AssetCustomBuilder;
                builder.Init();

                var builderPriority = builder.GetPriority();
                if (!string.IsNullOrEmpty(builder.GetName()))
                {
                    sortedClassList.Add(builderPriority, builder);
                }
            }

            for (int i = 0; i < m_builderCustomList.Count; i++)
            {
                var oldIns = m_builderCustomList[i];
                sortedClassList.Add(100000 + i, oldIns);
            }
            m_builderCustomList = new List <AssetBaseBuilder>(sortedClassList.Values);
        }