Beispiel #1
0
        private void BuildLuaFile(string dir)
        {
            string path = BuildDefaultPath.GetLuaTempDataPath + dir;

            string[] files = Directory.GetFiles(path, "*.lua.bytes");

            string _bundleName = "lua";

            for (int i = 0; i < files.Length; i++)
            {
                files[i] = files[i].Replace('\\', '/');
            }

            if (dir != null)
            {
                dir         = dir.Replace('\\', '_').Replace('/', '_');
                _bundleName = "lua_" + dir.ToLower();
            }

            _bundleName = BuildDefaultPath.GetLuaTempDataPath + "/" + _bundleName;

            AssetBundleBuild build = new AssetBundleBuild();

            bundleName            = BuildDefaultPath.BuildAssetBunldNameWithAssetPath(path);
            build.assetBundleName = _bundleName;
            build.assetNames      = files;
            builds.Add(build);
        }
Beispiel #2
0
        private static void CreatScriptableObject(string name, BuildType buildMethod, string searchPath, string searchPattern, SearchOption option)
        {
            string path  = BuildDefaultPath.GetBuildPattrenAssetPath();
            var    asset = ScriptableObject.CreateInstance <PackagePattern>();

            asset.packagInfos.Add(SetData(name, buildMethod, searchPath, searchPattern, option));
            AssetDatabase.CreateAsset(asset, path);
        }
        private static AssetBundleBuild BuildManifest()
        {
            string           manifestAssetsName = BuildDefaultPath.GetManifestAssetPath();
            AssetBundleBuild build = new AssetBundleBuild();

            build.assetBundleName = manifestAssetsName.Substring(0, manifestAssetsName.LastIndexOf('.')).ToLower();
            build.assetNames      = new string[] { manifestAssetsName };
            return(build);
        }
Beispiel #4
0
 /// <summary>
 /// 清空
 /// </summary>
 /// <param name="isClear"></param>
 public BuildPackPattern(bool isClear)
 {
     pkgMethod = AssetDatabase.LoadAssetAtPath <PackagePattern>(BuildDefaultPath.GetBuildPattrenAssetPath());
     if (pkgMethod != null)
     {
         pkgMethod.Clear();
         AssetDatabase.DeleteAsset(BuildDefaultPath.GetBuildPattrenAssetPath());
     }
     SaveAndRefresh();
 }
Beispiel #5
0
 /// <summary>
 /// 根据路径打包所有
 /// </summary>
 /// <param name="assetDataPath"></param>
 public BuildPackPattern()
 {
     pkgMethod = AssetDatabase.LoadAssetAtPath <PackagePattern>(BuildDefaultPath.GetBuildPattrenAssetPath());
     if (pkgMethod != null)
     {
         pkgMethod.Clear();
         AssetDatabase.DeleteAsset(BuildDefaultPath.GetBuildPattrenAssetPath());
     }
     CreatScriptableObject();
     SaveAndRefresh();
 }
        private static bool LoadEachPatterns()
        {
            bool isError = true;

            //在程序编译阶段,编译器会自动将using语句生成为try-finally语句,并在finally块中调用对象的Dispose方法,来清理资源。所以,using语句等效于try-finally语句
            patterns.Clear();
            var pkgPattern = AssetDatabase.LoadAssetAtPath <PackagePattern>(BuildDefaultPath.GetBuildPattrenAssetPath());

            if (pkgPattern != null)
            {
                pkgPattern.MappingPackageData();
                var data = pkgPattern.GetCacheAssetDataInfos();
                var e    = data.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current.Value.assetFolderName != null)
                    {
                        if (e.Current.Value.BuildType == BuildType.None)
                        {
                            MyDebug.LogErrorFormat("LoadEachPatterns is Called,But  BuildType == None! 【assetName】:{0}", e.Current.Value.assetFolderName);
                            isError = false;
                            continue;
                        }

                        var type =
                            typeof(BaseBuild).Assembly.GetType("MyAssetBundleEditor." + Enum.GetName(typeof(BuildType), e.Current.Value.BuildType)); //反射得到对应对象

                        if (type != null)
                        {
                            //实例化
                            var pattern = Activator.CreateInstance(type) as BaseBuild;
                            pattern.searchPath      = e.Current.Value.searchPath;
                            pattern.searchPattern   = e.Current.Value.searchPattern;
                            pattern.bundleName      = e.Current.Value.bundleName;
                            pattern.option          = e.Current.Value.searchOption;
                            pattern.assetFolderName = e.Current.Value.assetFolderName;
                            patterns.Add(pattern);
                        }
                        else
                        {
                            Debug.LogError(string.Format("BuildType is Have.But MyAssetBundleEditor.{0} is null!!!!", e.Current.Value.BuildType));
                        }
                    }
                    else
                    {
                        Debug.LogErrorFormat("LoadEachPatterns is Called.But assetName == null  {0}", e.Current.Key);
                    }
                }
            }

            return(isError);
        }
        public BuildMainfest(List <AssetBundleBuild> builds)
        {
            string path = BuildDefaultPath.GetManifestAssetPath();

            var asset = AssetDatabase.LoadAssetAtPath <PackageManifest>(path);

            if (asset != null)
            {
                AssetDatabase.DeleteAsset(path);
            }

            CreatManifestAsset(builds);
        }
        public static List <AssetBundleBuild> GetBuilds()
        {
            packedAssets.Clear();
            builds.Clear();
            //allDependencies.Clear();
            builds.Add(BuildManifest());//添加配置文件

            string packagePatternPath = BuildDefaultPath.GetBuildPattrenAssetPath();

            if (!File.Exists(packagePatternPath))//获取打包方式
            {
                new BuildPackPattern();
            }

            if (!LoadEachPatterns())
            {
                return(null);
            }

            foreach (var item in patterns)
            {
                if (item.searchPath == "")
                {
                    Debug.LogErrorFormat("assetName:{0}   searchPath is null ! Check !!!", item.assetFolderName);
                    continue;
                }

                if (item.searchPattern == "")
                {
                    Debug.LogErrorFormat("assetName:{0}   searchPattern is null ! Check !!!", item.assetFolderName);
                    continue;
                }

                CollectDependencies(ResFileInfo.GetFilesWithoutDirectores(item.searchPath, item.searchPattern,
                                                                          item.option)); //收集资源依赖
            }


            foreach (var item in patterns)
            {
                item.Build(); //获取打包信息
            }

            BuildAtlas();//编辑图集资源

            UnityEditor.EditorUtility.ClearProgressBar();

            return(builds);
        }
        private void CreatManifestAsset(List <AssetBundleBuild> builds)
        {
            List <string>            checkIsRepeat = new List <string>();
            List <AssetManifestInfo> list          = new List <AssetManifestInfo>();

            foreach (var build in builds)
            {
                List <string> infoList = new List <string>();

                string name = build.assetBundleName.Substring(build.assetBundleName.LastIndexOf('/') + 1);

                foreach (var assetPath in build.assetNames)
                {
                    infoList.Add(assetPath);
                    string itemName = assetPath.Substring(assetPath.LastIndexOf('/') + 1);
                    if (checkIsRepeat.Contains(itemName))
                    {
                        buildIsSuccess = false;
                        Debug.LogError(string.Format("图片命名重复 【Path】:{0},【SpriteName】:{1}", assetPath, itemName));
                        Debug.LogError(string.Format("已存在图片   【Path】:{0}", assetPath));
                        Debug.LogError("===========================================================");
                    }
                    else
                    {
                        checkIsRepeat.Add(itemName);
                    }
                }

                var manifest = new AssetManifestInfo()
                {
                    name   = name,
                    bundle = build.assetBundleName,
                    assets = infoList,
                };

                list.Add(manifest);
            }

            var asset = ScriptableObject.CreateInstance <PackageManifest>();

            asset.assetInfos = list;
            asset.MapingAssetData();
            AssetDatabase.CreateAsset(asset, BuildDefaultPath.GetManifestAssetPath());
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Beispiel #10
0
        /// <summary>
        /// 打包指定路径
        /// </summary>
        /// <param name="SelectionObj"></param>
        /// <param name="buildMethod"></param>
        /// <param name="isClear"></param>
        public BuildPackPattern(Object SelectionObj, BuildType buildMethod)
        {
            pkgMethod = AssetDatabase.LoadAssetAtPath <PackagePattern>(BuildDefaultPath.GetBuildPattrenAssetPath());
            if (pkgMethod != null)
            {
                pkgMethod.MappingPackageData();
            }
            if (SelectionObj == null)
            {
                return;
            }

            string path = AssetDatabase.GetAssetPath(SelectionObj);

            if (!CheckIsVaildFolder(path))
            {
                Debug.LogErrorFormat("select path is invaild! {0}", path);
                return;
            }

            string name          = path.Substring(path.LastIndexOf('/') + 1);
            string searchPattern = GetSerchPattern(name);

            if (pkgMethod == null)//创建
            {
                CreatScriptableObject(name, buildMethod, path, searchPattern, SearchOption.AllDirectories);
                return;
            }

            if (pkgMethod.GetPackagInfoByAssetName(name) != null) //更新操作
            {
                UpdatePackgInfos(name, buildMethod, path, searchPattern, SearchOption.AllDirectories);
            }
            else //添加操作
            {
                AddPackgInfos(name, buildMethod, path, searchPattern, SearchOption.AllDirectories);
            }
            SaveAndRefresh();
        }
Beispiel #11
0
        /// <summary>
        /// 将搜索到的所有资源按资源所在的路径进行打包,同一个路径下的所有资源会被打到一个包。(将searchPath路径下的按各自目录结构打成各自的包)
        /// 粒度适中
        /// </summary>
        public override void Build()
        {
            var files = GetFilesWithoutPacked(searchPath, searchPattern, option);
            Dictionary <string, List <string> > bundles = new Dictionary <string, List <string> >();

            for (int i = 0; i < files.Count; i++)
            {
                var item = files[i];
                if (UnityEditor.EditorUtility.DisplayCancelableProgressBar(string.Format("Collecting... [{0}/{1}]", i, files.Count), item, i * 1f / files.Count))
                {
                    break;
                }

                var path = Path.GetDirectoryName(item);
                if (!bundles.ContainsKey(path))   //按目录添加
                {
                    bundles[path] = new List <string>();
                }

                bundles[path].Add(item);
                bundles[path].AddRange(GetDependencies(item));
            }
            int count = 0;

            foreach (var item in bundles)
            {
                AssetBundleBuild build = new AssetBundleBuild();
                build.assetBundleName = BuildDefaultPath.BuildAssetBunldNameWithAssetPath(item.Key);
                build.assetNames      = item.Value.ToArray();
                packedAssets.AddRange(build.assetNames);
                builds.Add(build);
                if (UnityEditor.EditorUtility.DisplayCancelableProgressBar(string.Format("Packing... [{0}/{1}]", count, bundles.Count), build.assetBundleName, count * 1f / bundles.Count))
                {
                    break;
                }

                count++;
            }
        }
Beispiel #12
0
        /// <summary>
        /// 将搜索到的所有资源按每个资源的文件名进行打包,每个文件一个包。(将searchPath路径下的。每一个文件进行依次打包)
        /// 粒度最小
        /// </summary>
        public override void Build()
        {
            var files = GetFilesWithoutPacked(searchPath, searchPattern, option);

            for (int i = 0; i < files.Count; i++)
            {
                var item = files[i];
                if (EditorUtility.DisplayCancelableProgressBar(string.Format("Packing... [{0}/{1}]", i, files.Count),
                                                               item, i * 1f / files.Count))
                {
                    break;
                }

                AssetBundleBuild build = new AssetBundleBuild();
                build.assetBundleName = BuildDefaultPath.BuildAssetBunldNameWithAssetPath(item);
                var assetNames = GetDependencies(item);
                assetNames.Add(item);
                build.assetNames = assetNames.ToArray();
                packedAssets.AddRange(assetNames);
                builds.Add(build);
            }
        }
Beispiel #13
0
        /// <summary>
        /// 所有资源采用默认方法打包
        /// </summary>
        private static void CreatScriptableObject(bool isBuildLua = true)
        {
            var asset = ScriptableObject.CreateInstance <PackagePattern>();

            if (isBuildLua)
            {
                string[] sts  = Directory.GetFiles(BuildDefaultPath.GetLuaDataPath);
                string   name = BuildDefaultPath.assetsLuaFloder;
                asset.packagInfos.Add(SetData(name, GetBuildType(name), BuildDefaultPath.GetLuaDataPath,
                                              GetSerchPattern(name), SearchOption.AllDirectories));
            }

            string[] dirs = Directory.GetDirectories(BuildDefaultPath.GetAssetDataPath());
            foreach (var dir in dirs)
            {
                if (CheckIsVaildFolder(dir))
                {
                    string name = dir.Substring(dir.LastIndexOf('/') + 1);
                    asset.packagInfos.Add(SetData(name, GetBuildType(name), dir,
                                                  GetSerchPattern(name), SearchOption.AllDirectories));
                }
            }
            AssetDatabase.CreateAsset(asset, BuildDefaultPath.GetBuildPattrenAssetPath());
        }
Beispiel #14
0
 public override string GetAssetBundleName(string assetPath)
 {
     return(BuildDefaultPath.BuildAssetBunldNameWithAssetPath(Path.GetDirectoryName(assetPath)));
 }