static void BuildAssetBundles() { var outputPath = ResKitUtil.BuildAssetBundleFullPath(string.Empty); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); var versionConfigFilePath = outputPath + "/ResVersion.json"; List <string> AssetBundleMD5s = GetAssetBundleMD5s(outputPath); var resVersion = new ResVersion() { Version = HotUpdateStaticConfig.RemoteBundleVersion, AssetBundleNames = AssetDatabase.GetAllAssetBundleNames().Where(name => File.Exists(string.Format("{0}/{1}", outputPath, name)) && !HotUpdateStaticConfig.UnrecordBundleName.Contains(name)).ToList(), AssetBundleMD5s = AssetBundleMD5s }; var resVersionJson = JsonUtility.ToJson(resVersion, true); File.WriteAllText(versionConfigFilePath, resVersionJson); AssetDatabase.Refresh(); }
public AssetBundleRes(string assetName) { mPath = ResKitUtil.FullPathForAssetBundle(assetName); Name = assetName; State = ResState.Waiting; }
private void Load() { if (ResMgr.IsSimulationModeLogic) { #if UNITY_EDITOR var assetBundleNames = UnityEditor.AssetDatabase.GetAllAssetBundleNames(); foreach (var assetBundleName in assetBundleNames) { var assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); var assetBundleData = new AssetBundleData() { Name = assetBundleName, DenpendnecyBundleNames = UnityEditor.AssetDatabase.GetAssetBundleDependencies(assetBundleName, false) }; foreach (var assetPath in assetPaths) { var assetData = new AssetData() { Name = assetPath.Split('/') .Last() .Split('.') .First(), OwnerBundleName = assetBundleName }; assetBundleData.AssetDataList.Add(assetData); } AssetBundleDatas.Add(assetBundleData); } AssetBundleDatas.ForEach(abData => { Debug.LogFormat("----{0}----", abData.Name); abData.AssetDataList.ForEach(assetData => { Debug.LogFormat("AB:{0} AssetData:{1}", abData.Name, assetData.Name); }); foreach (var dependencyBundleName in abData.DenpendnecyBundleNames) { Debug.LogFormat("AB:{0} Depend:{1}", abData.Name, dependencyBundleName); } }); #endif } else { var mainBundlePath = ResKitUtil.FullPathForAssetBundle(ResKitUtil.GetPlatformName()); AssetBundle mainBundle = AssetBundle.LoadFromFile(mainBundlePath); mManifest = mainBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); } }
private IEnumerator DoFullDownloadRes(ResVersion remoteResVersion, Action downloadDone) { //创建临时目录 if (!Directory.Exists(TempAssetBundlesPath)) { Directory.CreateDirectory(TempAssetBundlesPath); } var remoteBasePath = FullHotUpdateMgr.Instance.Config.RemoteAssetBundleURLBase; //补上 AssetBundleMenifest 文件 remoteResVersion.AssetBundleNames.Add(ResKitUtil.GetPlatformName()); for (int i = 0; i < remoteResVersion.AssetBundleNames.Count; i++) { string assetBundleName = remoteResVersion.AssetBundleNames[i]; UnityWebRequest uwr = UnityWebRequest.Get(string.Format("{0}/{1}", remoteBasePath, assetBundleName)); uwr.timeout = 5; uwr.SendWebRequest(); if (uwr.isHttpError || uwr.isNetworkError) { Debug.Log(uwr.error); //todo error处理 } else { while (!uwr.isDone) { var progress = uwr.downloadProgress; yield return(0); } if (uwr.isDone) //如果下载完成了 { Debug.Log("完成"); } var bytes = uwr.downloadHandler.data; var filepath = TempAssetBundlesPath + assetBundleName; File.WriteAllBytes(filepath, bytes); } } downloadDone(); }
private IEnumerator DoIncrementDownloadRes(List <string> AssetBundleNames, Action downloadDone, Action <string> downloadError) { if (!Directory.Exists(IncrementHotUpdateMgr.Instance.Config.HotUpdateAssetBundlesFolder)) { Directory.CreateDirectory(IncrementHotUpdateMgr.Instance.Config.HotUpdateAssetBundlesFolder); } var remoteBasePath = IncrementHotUpdateMgr.Instance.Config.RemoteAssetBundleURLBase; //补上 AssetBundleMenifest 文件 AssetBundleNames.Add(ResKitUtil.GetPlatformName()); for (int i = 0; i < AssetBundleNames.Count; i++) { string assetBundleName = AssetBundleNames[i]; UnityWebRequest uwr = UnityWebRequest.Get(string.Format("{0}/{1}", remoteBasePath, assetBundleName)); uwr.timeout = 5; uwr.SendWebRequest(); if (uwr.isHttpError || uwr.isNetworkError) { downloadError(uwr.error); } else { while (!uwr.isDone) { var progress = uwr.downloadProgress; yield return(0); } if (uwr.isDone) //如果下载完成了 { Debug.Log("完成"); } var bytes = uwr.downloadHandler.data; var filepath = TempAssetBundlesPath + assetBundleName; File.WriteAllBytes(filepath, bytes); } } downloadDone(); }
public static string BuildAssetBundlesFolder(string bundleName) { return(Application.streamingAssetsPath + "/AssetBundles/" + ResKitUtil.GetPlatformName() + "/" + bundleName); }