Example #1
0
        public static AssetBundleGroupLoadHelperItem Create(string _groupName, AssetBundleGroupInfo _assetBundleGroupInfo)
        {
            GameObject gameObject = new GameObject();

            gameObject.transform.SetParent(AssetBundleManager.Instance.transform);
            AssetBundleGroupLoadHelperItem helper = gameObject.AddComponent <AssetBundleGroupLoadHelperItem>();

            helper.Init(_groupName, _assetBundleGroupInfo);
            return(helper);
        }
 public void Add(string key, AssetBundleGroupInfo value)
 {
     if (this.assetBundleGroups.ContainsKey(key))
     {
         UnityEngine.Debug.LogError("资源组重名:" + key);
     }
     else
     {
         this.assetBundleGroups.Add(key, value);
     }
 }
        /// <summary>
        /// 打Group的Bundle,并生成Group的version信息
        /// </summary>
        /// <param name="singleGroup"></param>
        public static void BuildGroup(BundleGroup singleGroup, string exportPath, BuildTarget buildTarget = BuildTarget.NoTarget)
        {
            List <string> paths = singleGroup.GetBundlePaths(GetBundleMethod.All);

            if (paths == null || paths.Count <= 0)
            {
                return;
            }

            string groupName = singleGroup.GroupName;

            if (!Directory.Exists(exportPath))
            {
                Directory.CreateDirectory(exportPath);
            }

            List <AssetBundleBuild> buildMap = new List <AssetBundleBuild>();

            //打AssetBundle包
            for (int i = 0; i < paths.Count; i++)
            {
                string           fullPath   = string.Format("{0}/{1}/{2}", Application.dataPath, "Export", paths[i]);
                AssetBundleBuild build      = new AssetBundleBuild();
                List <string>    assetnames = new List <string>();
                if (File.Exists(fullPath))
                {
                    string itemPath = paths[i];
                    int    lastDot  = itemPath.LastIndexOf(".");
                    if (lastDot > 0)
                    {
                        build.assetBundleName = itemPath.Substring(0, lastDot);
                    }
                    else
                    {
                        build.assetBundleName = itemPath;
                    }
                    assetnames.Add(FilePathTools.GetRelativePath(fullPath));
                }
                else
                {
                    build.assetBundleName = paths[i];
                    FileInfo[] files = FileUtil.GetFiles(fullPath);
                    if (files.Length <= 0)
                    {
                        continue;
                    }

                    for (int j = 0; j < files.Length; j++)
                    {
                        //Debug.Log(files[j]);
                        string path = FilePathTools.GetRelativePath(files[j].FullName);
                        if (path.Contains(".DS_Store") || path.Contains(".gitkeep"))
                        {
                            continue;
                        }
                        assetnames.Add(path);
                    }
                }

                foreach (string assetName in assetnames)
                {
                    AssetImporter.GetAtPath(assetName).SetAssetBundleNameAndVariant(build.assetBundleName, string.Empty);
                }

                build.assetNames = assetnames.ToArray();
                buildMap.Add(build);
            }
            AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(
                exportPath,
                buildMap.ToArray(),
                BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle,
                buildTarget == BuildTarget.NoTarget ? EditorUserBuildSettings.activeBuildTarget : buildTarget
                );



            //生成Version Item Info
            AssetBundleGroupInfo assetBundleGroupInfo = new AssetBundleGroupInfo(singleGroup.GroupName, singleGroup.BaseGroup);

            string[] builtAssetBundleNames = assetBundleManifest.GetAllAssetBundles();
            for (var i = 0; i < builtAssetBundleNames.Length; ++i)
            {
                string     assetBundlePath = string.Format("{0}/{1}", exportPath, builtAssetBundleNames[i]);
                string     path            = Directory.GetCurrentDirectory();
                BundleInfo bundleInfo      = singleGroup.GetBundleInfo(builtAssetBundleNames[i]);

                string          md5  = AssetUtils.BuildFileMd5(assetBundlePath);
                int             size = AssetUtils.FileSize(assetBundlePath);
                AssetBundleInfo localAssetBundleInfo = new AssetBundleInfo
                {
                    AssetBundleName         = builtAssetBundleNames[i],
                    DependenciesBundleNames = assetBundleManifest.GetAllDependencies(builtAssetBundleNames[i]),
                    releaseMode             = bundleInfo.releaseMode,
                    BaseBundle = bundleInfo.BaseBundle
                };
                localAssetBundleInfo.HashString = md5;  // 初始包里的ab包,原样拷贝md5
                localAssetBundleInfo.Size       = size; // bundle的尺寸
                assetBundleGroupInfo.Add(localAssetBundleInfo.AssetBundleName, localAssetBundleInfo);
            }
            assetBundleVersionInfo.Add(groupName, assetBundleGroupInfo);
        }
Example #4
0
 public void Init(string _groupName, AssetBundleGroupInfo _assetBundleGroupInfo)
 {
     groupName            = _groupName;
     assetBundleGroupInfo = _assetBundleGroupInfo;
     progressInfo         = new ProgressInfo();
 }