Пример #1
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);
        }
Пример #2
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();
 }
Пример #3
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();
 }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
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();
        }
Пример #7
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());
        }