예제 #1
0
        static IResPacker CreateResPacker(string filePath, EPackHandlerParam packHandlerParam)
        {
            filePath = filePath.Replace("\\", "/");
            IResPacker resPacker = null;

            resPacker = GetResPacker(filePath);
            resPacker.SetPath(filePath);
            resPacker.SetHandlerParam(packHandlerParam);
            return(resPacker);
        }
예제 #2
0
        //第一步
        static public bool Build(string path, List <string> filePaths, EPackHandlerParam packHandlerParam, bool customPath = false,
                                 List <string> assetNames = null, List <UnityEngine.Object> assetList = null)
        {
            List <IResPacker> packers = new List <IResPacker>();

            for (int i = 0; i < filePaths.Count; i++)
            {
                IResPacker resPacker = CreateResPacker(filePaths[i], packHandlerParam);
                packers.Add(resPacker);
            }
            return(Build(path, packers, packHandlerParam, customPath, assetNames, assetList));
        }
예제 #3
0
        static private IResPacker GetResPacker(string path)
        {
            IResPacker ret = null;

            if (path.EndsWith(".prefab"))
            {
                ret = new PrefabResPacker();
            }
            else
            {
                ret = new ComResPacker();
            }
            return(ret);
        }
예제 #4
0
        //第2步
        static bool Build(string path, List <IResPacker> packers, EPackHandlerParam packHandlerParam, bool customPath = false,
                          List <string> assetNames = null, List <UnityEngine.Object> assetList = null)
        {
            IResPacker packer = null;

            Console.WriteLine("ResPackHelper Build " + path);
            //目前无预处理
            if ((packHandlerParam & EPackHandlerParam.Preprocess) != 0)
            {
                for (int i = 0; i < packers.Count; i++)
                {
                    packer = packers[i];
                    packer.Preprocess();
                }
                Console.WriteLine("ResPackHelper Build Preprocess Finish " + path);
            }

            // 主预制件对象
            if (null == assetList)
            {
                assetList = new List <UnityEngine.Object>();
            }
            if (null == assetNames)
            {
                assetNames = new List <string>();
            }

            for (int i = 0; i < packers.Count; i++)
            {
                packer = packers[i];
                if (assetList.Count < packers.Count)
                {
                    assetList.Add(packer.GetAimAssetObj());
                }
                if (assetNames.Count < packers.Count)
                {
                    assetNames.Add(GetFileFullPathWithoutExtension(packer.GetPath().Substring(7)));
                }
            }

            if (assetList.Count == 0)
            {
                for (int i = 0; i < packers.Count; i++)
                {
                    packer = packers[i];
                    packer.Clear();
                }
                return(false);
            }
            //
            BuildAssetBundleOptions buildOpts = BuildAssetBundleOptions.DeterministicAssetBundle;

            if (0 != (packHandlerParam & EPackHandlerParam.UnCompress))
            {
                buildOpts |= BuildAssetBundleOptions.UncompressedAssetBundle;
            }
            else if (0 != (packHandlerParam & EPackHandlerParam.LZ4))
            {
                buildOpts |= BuildAssetBundleOptions.ChunkBasedCompression;
            }
            else if (0 != (packHandlerParam & EPackHandlerParam.LZMA))
            {
                //默认就是
            }
            //优化
            buildOpts |= BuildAssetBundleOptions.DisableWriteTypeTree;
            // build other
            bool bSucess = BuildAssetBundle(assetList.ToArray(), assetNames.ToArray(), path, buildOpts, customPath);

            // clear tmp asset
            for (int i = 0; i < packers.Count; i++)
            {
                packer = packers[i];
                packer.Clear();
            }
            return(bSucess);
        }