Exemplo n.º 1
0
        public override void BeforeBuild()
        {
            base.BeforeBuild();

            // Clear altas settings
            var resPath = Application.dataPath + "/" + ResConfig.UI_TEXTURE;
            var files   = ResBuildUtility.GetFiles(resPath);

            foreach (var file in files)
            {
                if (file.EndsWith(".png") == false && file
                    .EndsWith(".jpg") == false)
                {
                    continue;
                }

                var assetPath = "Assets/" + file.ReplaceFirst(Application.dataPath + "/", "");
                if (assetPath.StartsWith("Assets/" + ResConfig.UI_TEXTURE_RUNTIME))
                {
                    continue;
                }

                var textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                ResTextureAutoConfigurer.ConfigureUITexture(textureImporter, true);
            }
        }
Exemplo n.º 2
0
        public static void Build(BuildTarget targetPlatform)
        {
            BeforeBuild(targetPlatform);

            // Build
            var resPath = Application.dataPath + "/" + ResConfig.RES_ROOT;
            var files   = ResBuildUtility.GetFiles(resPath);

            BuildBundles(targetPlatform, files);

            AfterBuild();
        }
Exemplo n.º 3
0
        public override void OverrideBuild(string outpathRoot, List <AssetBundleBuild> filteredBuildInfos)
        {
            for (int i = filteredBuildInfos.Count - 1; i >= 0; --i)
            {
                var buildInfo = filteredBuildInfos[i];
                // Remove runtime textures from buildInfos
                if (buildInfo.assetBundleName.StartsWith("Assets/" + ResConfig.UI_TEXTURE_RUNTIME) ||
                    buildInfo.assetBundleName.StartsWith(ResConfig.DEPENDENCIES_ROOT + "/" + ResConfig.UI_TEXTURE_RUNTIME))
                {
                    filteredBuildInfos.RemoveAt(i);
                }
            }

            var resPath = Application.dataPath + "/" + ResConfig.UI_TEXTURE_RUNTIME;
            var files   = ResBuildUtility.GetFiles(resPath);

            foreach (var file in files)
            {
                if (file.EndsWith(".png") == false &&
                    file.EndsWith(".jpg") == false)
                {
                    continue;
                }

                var fileName        = Path.GetFileName(file);
                var assetBundleName = file.ReplaceFirst(_rootPath + "/", "");
                assetBundleName = assetBundleName.ReplaceLast("/" + fileName, "").ReplaceFirst("Assets/", "") + ResConfig.BUNDLE_EXTENSION;
                var assetName = file.ReplaceFirst(_rootPath + "/", "");

                var index = ResBuildUtility.TryGetBuildInfo(filteredBuildInfos, assetBundleName);
                if (index == -1)
                {
                    var buildInfo = new AssetBundleBuild();
                    buildInfo.assetNames      = new string[] { assetName };
                    buildInfo.assetBundleName = assetBundleName;
                    filteredBuildInfos.Add(buildInfo);
                }
                else
                {
                    var buildInfo  = filteredBuildInfos[index];
                    var assetNames = buildInfo.assetNames.ToList();
                    if (assetNames.Contains(assetName))
                    {
                        continue;
                    }

                    assetNames.Add(assetName);
                    buildInfo.assetNames      = assetNames.ToArray();
                    filteredBuildInfos[index] = buildInfo;
                }
            }
        }
Exemplo n.º 4
0
        public static void Build(BuildTarget targetPlatform)
        {
            BeforeBuild(targetPlatform);

            // Build bundles first
            var resPath = Application.dataPath + "/" + ResConfig.RES_ROOT;
            var files   = ResBuildUtility.GetFiles(resPath);

            BuildBundles(targetPlatform, files);

            // Build version file
            var bundlesPath = _outPath;

            files = ResBuildUtility.GetFiles(bundlesPath);
            BuildVersionFile(targetPlatform, files);
        }
Exemplo n.º 5
0
        static void BuildBundles(BuildTarget targetPlatform, string[] files)
        {
            var buildInfos = new Dictionary <string, AssetBundleBuild>();

            var filters = new List <ResAbstractBuildFilter>()
            {
                new ResLuaBuildFilter(),
                new ResSpriteBuildFilter(),

                // Assets contain dependence
                new ResPrefabBuildFilter(),
            };

            // 10
            var basePercent = 0f;
            var percent     = 10f;
            var index       = 0f;
            var count       = filters.Count;

            // BeforeBuild
            EditorUtility.DisplayProgressBar(
                "Building AssetBundles",
                string.Format("Before building..."),
                ((1) * percent + basePercent) / 100);
            foreach (var filter in filters)
            {
                filter.BeforeBuild();
                index++;
            }

            // 30
            basePercent = basePercent + percent;
            percent     = 20f;
            index       = 0;
            count       = files.Length * filters.Count;

            // Prepare build
            EditorUtility.DisplayProgressBar(
                "Building AssetBundles",
                string.Format("Preparing..."),
                ((1) * percent + basePercent) / 100);
            foreach (var file in files)
            {
                foreach (var filter in filters)
                {
                    index++;

                    if (filter.Filtered(file))
                    {
                        AssetBundleBuild?buildInfoNullable = filter.PrepareBuild(file);
                        if (buildInfoNullable != null)
                        {
                            var buildInfo = (AssetBundleBuild)buildInfoNullable;
                            buildInfos[file] = buildInfo;
                        }

                        if (filter.BlockOthers)
                        {
                            break;
                        }
                    }
                }
            }

            // 50
            basePercent = basePercent + percent;
            percent     = 20f;
            index       = 0;
            count       = files.Length * buildInfos.Count;

            try
            {
                var filteredBuildInfos = new List <AssetBundleBuild>();

                // Real build
                foreach (var pair in buildInfos)
                {
                    var filepath  = pair.Key;
                    var buildInfo = pair.Value;
                    {
                        // Add dependent buildInfos
                        ResBuildUtility.AppendDependencies(buildInfo, filteredBuildInfos);

                        // Add self buildInfo
                        filteredBuildInfos.Add(buildInfo);
                    }
                }

                // 60
                basePercent = basePercent + percent;
                percent     = 10f;
                index       = 0;
                count       = filters.Count;

                // Additive build
                foreach (var filter in filters)
                {
                    EditorUtility.DisplayProgressBar(
                        "Building AssetBundles",
                        string.Format(filter.GetType().Name + " override building..."),
                        ((index / count) * percent + basePercent) / 100);
                    index++;

                    filter.OverrideBuild(_outPath, filteredBuildInfos);
                }

                // 80
                basePercent = basePercent + percent;
                percent     = 20f;
                index       = 0;
                count       = filteredBuildInfos.Count;

                // Set bundle name
                EditorUtility.DisplayProgressBar(
                    "Building AssetBundles",
                    string.Format("Setting bundleNames..."),
                    ((1) * percent + basePercent) / 100);
                for (var i = 0; i < filteredBuildInfos.Count; ++i)
                {
                    index++;

                    var buildInfo = filteredBuildInfos[i];
                    ResBuildUtility.ResetBundleName(ref buildInfo);
                    filteredBuildInfos[i] = buildInfo;
                }

                // Build
                BuildPipeline.BuildAssetBundles(
                    _outPath,
                    // filteredBuildInfos.ToArray(),
                    _options,
                    targetPlatform
                    );

                // 100
                basePercent = basePercent + percent;
                percent     = 20f;
                index       = 1;
                count       = 1;

                // Build version file
                EditorUtility.DisplayProgressBar(
                    "Building AssetBundles",
                    string.Format("Building version file..."),
                    ((index / count) * percent + basePercent) / 100);

                var bundlesPath = _outPath;
                files = ResBuildUtility.GetFiles(bundlesPath);
                BuildVersionFile(files);
            }
            catch (Exception e)
            {
                LogManager.Error(e.Message);
            }
            finally
            {
                // After build
                foreach (var filter in filters)
                {
                    filter.AfterBuild();
                }
            }
        }
Exemplo n.º 6
0
        public override void OverrideBuild(string outpathRoot, List <AssetBundleBuild> filteredBuildInfos)
        {
            for (int i = filteredBuildInfos.Count - 1; i >= 0; --i)
            {
                var buildInfo = filteredBuildInfos[i];
                if (buildInfo.assetBundleName.StartsWith("Assets/" + ResConfig.RES_ROOT + "/" + ResConfig.LUA_ROOT) ||
                    buildInfo.assetBundleName.StartsWith(ResConfig.DEPENDENCIES_ROOT + "/" + ResConfig.RES_ROOT + "/" + ResConfig.LUA_ROOT))
                {
                    filteredBuildInfos.RemoveAt(i);
                }
            }

            var resPath = Application.dataPath + "/" + ResConfig.RES_ROOT + "/" + ResConfig.LUA_ROOT;
            var files   = ResBuildUtility.GetFiles(resPath);

            _tmpFiles.Clear();

            foreach (var file in files)
            {
                if (file.EndsWith(ResConfig.LUA_EXTENSION) == false)
                {
                    continue;
                }

                var sourceFile = file;
                var targetFile = sourceFile.ReplaceLast(ResConfig.LUA_EXTENSION, ResConfig.MOBILE_LUA_EXTENSION);

                if (File.Exists(targetFile))
                {
                    File.Delete(targetFile);
                }
                File.Copy(sourceFile, targetFile);
                _tmpFiles.Add(targetFile);

                var assetBundleName = targetFile.ReplaceFirst(Application.dataPath + "/" + ResConfig.RES_ROOT + "/", "") + ResConfig.BUNDLE_EXTENSION;
                var assetName       = targetFile.ReplaceFirst(_rootPath + "/", "");

                var index = ResBuildUtility.TryGetBuildInfo(filteredBuildInfos, assetBundleName);
                if (index == -1)
                {
                    var buildInfo = new AssetBundleBuild();
                    buildInfo.assetNames      = new string[] { assetName };
                    buildInfo.assetBundleName = assetBundleName;
                    filteredBuildInfos.Add(buildInfo);

                    LogManager.Log("lua assetbundle " + assetBundleName);
                }
                else
                {
                    var buildInfo  = filteredBuildInfos[index];
                    var assetNames = buildInfo.assetNames.ToList();
                    if (assetNames.Contains(assetName))
                    {
                        continue;
                    }

                    assetNames.Add(assetName);
                    buildInfo.assetNames      = assetNames.ToArray();
                    filteredBuildInfos[index] = buildInfo;

                    LogManager.Log("lua assetbundle " + assetBundleName);
                }
            }
            AssetDatabase.Refresh();
        }