public static void CopyAssetBundlesAudioToStreamingAssetsAudio(BuildTarget buildTarget, string channelName) { string pltname = GetPlatformName(buildTarget); string sourcePath = GetAudioOutputPath(buildTarget, channelName); //string sourcePath = Path.Combine(source, pltname); string destination = AssetBundleUtility.GetStreamingAssetsAudioDataPath(); string destPath = Path.Combine(destination, pltname); GameUtility.CheckDirAndCreateWhenNeeded(destPath); GameUtility.SafeDeleteDir(destPath); //清理目录 CopyFolder(sourcePath, destPath, ".meta"); string soundbakSrcpath = Path.Combine(sourcePath, AssetBundleConfig.WWISESoundbanksInfo); string soundbakDstpath = Path.Combine(Application.dataPath, AssetBundleConfig.WWISESoundbanksInfoPath); try { GameUtility.SafeDeleteFile(soundbakDstpath); FileUtil.CopyFileOrDirectoryFollowSymlinks(soundbakSrcpath, soundbakDstpath); } catch (System.Exception ex) { Debug.LogError("CopyAssetBundlesAudioToStreamingAssetsAudio, err : " + ex); return; } Debug.Log("CopyAssetBundlesAudioToStreamingAssetsAudio success"); AssetDatabase.Refresh(); }
IEnumerator UpdateFinish() { statusText.text = "正在准备资源..."; // 保存服务器资源版本号与Manifest GameUtility.SafeWriteAllText(resVersionPath, serverResVersion); GameUtility.SafeWriteAllText(AssetBundleUtility.GetPersistentDataPath(BuildUtils.UpdateFileName), hostAudioMd5Ceontent); clientResVersion = serverResVersion; //hostManifest.SaveToDiskCahce(); // 重启资源管理器 卸载之后会出现UI没有的情况,所以这里不卸载资源,只是重新初始化manfaist文件确保使用的是新的依赖文件 //yield return AssetBundleManager.Instance.Cleanup(); yield return(AssetBundleManager.Instance.Initialize()); //// 启动xlua热修复模块 //XLuaManager.Instance.Startup(); //// 重启Lua虚拟机 //Coroutine co = StartCoroutine(AssetBundleManager.Instance.PreLoadLua()); //yield return co; ////XLuaManager.Instance.Restart(); //XLuaManager.Instance.OnInit(); //XLuaManager.Instance.StartHotfix(); yield break; }
public AssetBundlePreloader( DownloadQueue downloadQueue, IEnumerable <AssetBundleRecord> assetBundleRecords) { this.onDownloaded = OnDownloaded; this.downloadQueue = downloadQueue; this.assetBundleRecordsToDownload = assetBundleRecords .Where((AssetBundleRecord assetBundleRecord) => { string localStoragePath = AssetBundleUtility.GetLocalStoragePath(assetBundleRecord.AssetBundleName); return(!File.Exists(localStoragePath)); }) .ToArray(); foreach (AssetBundleRecord assetBundleRecord in this.assetBundleRecordsToDownload) { string localStoragePath = AssetBundleUtility.GetLocalStoragePath(assetBundleRecord.AssetBundleName); if (File.Exists(localStoragePath)) { continue; } this.MaxAssetBundleCount++; this.MaxBytes += assetBundleRecord.FileSizeBytes; } }
IEnumerator InitAppVersion() { AsyncOperationHandle <TextAsset> handle = Addressables.LoadAssetAsync <TextAsset>(BuildUtils.AppVersionFileName); yield return(handle); if (handle.Status == AsyncOperationStatus.Succeeded) { var streamingAppVersion = handle.Result.text; var appVersionPath = AssetBundleUtility.GetPersistentDataPath(BuildUtils.AppVersionFileName); var persistentAppVersion = GameUtility.SafeReadAllText(appVersionPath); Logger.Log(string.Format("streamingAppVersion = {0}, persistentAppVersion = {1}", streamingAppVersion, persistentAppVersion)); // 如果persistent目录版本比streamingAssets目录app版本低,说明是大版本覆盖安装,清理过时的缓存 if (!string.IsNullOrEmpty(persistentAppVersion) && BuildUtils.CheckIsNewVersion(persistentAppVersion, streamingAppVersion)) { var path = AssetBundleUtility.GetPersistentDataPath(); GameUtility.SafeDeleteDir(path); } GameUtility.SafeWriteAllText(appVersionPath, streamingAppVersion); ChannelManager.instance.appVersion = streamingAppVersion; Addressables.Release(handle); } yield break; }
IEnumerator UpdateFinish(bool hasUpdate) { var start = DateTime.Now; UILauncher.Instance.SetSatus("正在准备资源..."); if (hasUpdate) { // 存储版本号 var appVersionPath = AssetBundleUtility.GetPersistentDataPath(BuildUtils.AppVersionFileName); GameUtility.SafeWriteAllText(appVersionPath, clientAppVersion + "|" + serverResVersion + "|" + ChannelManager.Instance.channelName); clientResVersion = serverResVersion; // 拷贝临时文件 versions.SaveAllToTemp(); CopyTemp2Data(); // 设置版本号 Logger.appVersion = clientAppVersion; Logger.resVersion = clientResVersion; ChannelManager.Instance.resVersion = serverResVersion; // 重启资源管理器 yield return(AssetBundleManager.Instance.Cleanup()); yield return(AssetBundleManager.Instance.Initialize()); } Logger.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds)); }
public static void CopyAssetBundlesToStreamingAssets(BuildTarget buildTarget, string channelName) { string source = GetAssetBundleOutputPath(buildTarget, channelName); string destination = AssetBundleUtility.GetStreamingAssetsDataPath(); // 有毒,竟然在有的windows系统这个函数删除不了目录,不知道是不是Unity的Bug // GameUtility.SafeDeleteDir(destination); AssetDatabase.DeleteAsset(GameUtility.FullPathToAssetPath(destination)); AssetDatabase.Refresh(); try { FileUtil.CopyFileOrDirectoryFollowSymlinks(source, destination); } catch (System.Exception ex) { Debug.LogError("Something wrong, you need manual delete AssetBundles folder in StreamingAssets, err : " + ex); return; } var allManifest = GameUtility.GetSpecifyFilesInFolder(destination, new string[] { ".manifest" }); if (allManifest != null && allManifest.Length > 0) { for (int i = 0; i < allManifest.Length; i++) { GameUtility.SafeDeleteFile(allManifest[i]); } } AssetDatabase.Refresh(); }
IEnumerator InitAppVersion() { var appVersionRequest = AssetBundleManager.Instance.RequestAssetFileAsync(BuildUtils.AppVersionFileName); yield return(appVersionRequest); var streamingAppVersion = appVersionRequest.text; appVersionRequest.Dispose(); var appVersionPath = AssetBundleUtility.GetPersistentDataPath(BuildUtils.AppVersionFileName); var persistentAppVersion = GameUtility.SafeReadAllText(appVersionPath); Logger.Log(string.Format("streamingAppVersion = {0}, persistentAppVersion = {1}", streamingAppVersion, persistentAppVersion)); // 如果persistent目录版本比streamingAssets目录app版本低,说明是大版本覆盖安装,清理过时的缓存 if (!string.IsNullOrEmpty(persistentAppVersion) && BuildUtils.CheckIsNewVersion(persistentAppVersion, streamingAppVersion)) { var path = AssetBundleUtility.GetPersistentDataPath(); GameUtility.SafeDeleteDir(path); } GameUtility.SafeWriteAllText(appVersionPath, streamingAppVersion); ChannelManager.instance.appVersion = streamingAppVersion; yield break; }
public override void Awake() { base.Awake(); string path = AssetBundleUtility.PackagePathToAssetsPath(luaAssetbundleAssetName); AssetbundleName = AssetBundleUtility.AssetBundlePathToAssetBundleName(path); }
public static string GetCurBuildSettingStreamingManifestPath() { string path = AssetBundleUtility.GetStreamingAssetsDataPath(); path = Path.Combine(path, BuildUtils.ManifestBundleName); return(path); }
public static string GetCurBuildSettingStreamingManifestPath() { string path = AssetBundleUtility.GetStreamingAssetsDataPath(); path = Path.Combine(path, GetCurSelectedChannel().ToString()); return(path); }
void Initialize() { luaState = new LuaState(); loader = new LuaResLoader(); #if UNITY_EDITOR luaState.AddSearchPath(LuaConst.luaDir); #endif #if AB_MODE luaState.AddSearchPath(AssetBundleUtility.LocalAssetBundlePath); luaState.AddSearchPath(AssetBundleUtility.GetStreamingPath()); #endif luaState.OpenLibs(LuaDLL.luaopen_pb); //if (LuaConst.openLuaSocket) //{ // OpenLuaSocket(); //} //if (LuaConst.openZbsDebugger) //{ // OpenZbsDebugger(); //} luaState.LuaSetTop(0); LuaBinder.Bind(luaState); luaState.Start(); LuaCoroutine.Register(luaState, this); }
IEnumerator ClearAsync() { foreach (string filePath in Directory.GetFiles(AssetBundleUtility.GetLocalStoragePath(string.Empty), "*", SearchOption.AllDirectories)) { if (protectingFilePaths.Contains(filePath)) { continue; } try { File.Delete(filePath); } catch (Exception e) { Debug.LogError(e); } if (TimeUtility.DropFrameExists()) { yield return(null); } } this.IsFinished = true; }
void Update() { if (!isDownloading) { return; } for (int i = downloadingRequest.Count - 1; i >= 0; i--) { var request = downloadingRequest[i]; if (request.isDone) { if (!string.IsNullOrEmpty(request.error)) { Logger.LogError("Error when downloading file : " + request.assetbundleName + "\n from url : " + request.url + "\n err : " + request.error); hasError = true; needDownloadList.Add(request.assetbundleName); } else { // TODO:是否需要显示下载流量进度? Logger.Log("Finish downloading file : " + request.assetbundleName + "\n from url : " + request.url); downloadingRequest.RemoveAt(i); finishedDownloadCount++; var filePath = AssetBundleUtility.GetPersistentDataPath(request.assetbundleName); GameUtility.SafeWriteAllBytes(filePath, request.bytes); } request.Dispose(); } } if (!hasError) { while (downloadingRequest.Count < MAX_DOWNLOAD_NUM && needDownloadList.Count > 0) { var fileName = needDownloadList[needDownloadList.Count - 1]; needDownloadList.RemoveAt(needDownloadList.Count - 1); var request = AssetBundleManager.Instance.DownloadAssetBundleAsync(fileName); downloadingRequest.Add(request); } } if (downloadingRequest.Count == 0) { isDownloading = false; } float progressSlice = 1.0f / totalDownloadCount; float progressValue = finishedDownloadCount * progressSlice; for (int i = 0; i < downloadingRequest.Count; i++) { progressValue += (progressSlice * downloadingRequest[i].progress); } slider.normalizedValue = progressValue; }
/// <summary> /// キャッシュ再構築 /// </summary> private void RebuildCache() { if (m_Target != null) { if (m_TargetSerialized == null) { m_TargetSerialized = new SerializedObject(m_Target); } if ((m_CatalogSerialized == null) || (m_CatalogSerialized.targetObject == null)) { if (m_Target.catalog != null) { m_CatalogSerialized = new SerializedObject(m_Target.catalog); } } else if (m_CatalogSerialized.targetObject != m_Target.catalog) { if (m_Target.catalog != null) { m_CatalogSerialized = new SerializedObject(m_Target.catalog); } else { m_CatalogSerialized = null; } } var editor = AssetBundleUtility.GetAssetBundleManagerEditor(m_Target); if ((m_EditorSerialized == null) || (m_EditorSerialized.targetObject == null)) { if (editor != null) { m_EditorSerialized = new SerializedObject(editor); } } else if (m_EditorSerialized.targetObject != editor) { m_EditorSerialized = new SerializedObject(editor); } if (m_DownloadQueue == null) { m_DownloadQueue = m_Target.GetDownloadQueue(); } if (m_Downloading == null) { m_Downloading = m_Target.GetDownloading(); } if (m_Downloaded == null) { m_Downloaded = m_Target.GetDownloaded(); } if (m_Progressing == null) { m_Progressing = m_Target.GetProgressing(); } } }
protected override void Init() { base.Init(); string path = AssetBundleUtility.RelativeAssetPathToAbsoluteAssetPath(luaAssetbundleAssetName); AssetbundleName = AssetBundleUtility.AssetBundleAssetPathToAssetBundleName(path); InitLuaEnv(); }
protected override void Init() { base.Init(); string path = AssetBundleUtility.PackagePathToAssetsPath(luaAssetbundleAssetName); AssetbundleName = AssetBundleUtility.AssetBundlePathToAssetBundleName(path); InitLuaEnv(); }
void Start() { resVersionPath = AssetBundleUtility.GetPersistentDataPath(BuildUtils.ResVersionFileName); noticeVersionPath = AssetBundleUtility.GetPersistentDataPath(BuildUtils.NoticeVersionFileName); DateTime startDate = new DateTime(1970, 1, 1); timeStamp = (DateTime.Now - startDate).TotalMilliseconds; statusText.text = "正在检测资源更新..."; }
protected override void Init() { base.Init(); string path = AssetBundleUtility.PackagePathToAssetsPath(luaAssetbundleAssetName); AssetbundleName = AssetBundleUtility.AssetBundlePathToAssetBundleName(path); InitLuaEnv(); SceneManager.sceneLoaded += SceneManagerOnSceneLoaded; }
public AssetBundleSweeper( IEnumerable <string> protectingAssetBundleNames, NullOnlyCoroutineOwner coroutineOwner) { this.coroutineOwner = coroutineOwner; this.protectingFilePaths = protectingAssetBundleNames .Select(assetBundleName => AssetBundleUtility.GetLocalStoragePath(assetBundleName)) .ToHashSet(); }
void Start() { //screen = GameObject.Find("UIRoot/TipLayer").transform.GetComponent<RectTransform>(); //width = (int)screen.sizeDelta.x; //height= (int)screen.sizeDelta.y; //list.Clear(); //常驻内存 AssetBundleManager.Instance.LoadAssetBundleAsync(AssetBundleUtility.AssetBundlePathToAssetBundleName("Effect/Prefab/UI/fx_ui_clickbutton.prefab")); }
// ダウンロード処理 // 真なら、ダウンロード済み、それ以外は初回ダウンロード private static bool _DownloadAssetBundle(string assetBundleName, bool isDownloadingABManifest) { /* * テスト用キャッシュクリア * if(Chaching.CleanChache()) * { * Debug.Log("chache Clear"); * } */ // 既にダウンロード済み DownloadedAssetBundle downloadedAB = null; _downloadedAssetBundleDic.TryGetValue(assetBundleName, out downloadedAB); if (downloadedAB != null) { // 既にダウンロード済みで、再度リクエストがあった場合、追加で参照アカウントを進める downloadedAB.referenceCount++; return(true); } // ダウンロード実行中のリストをチェックする if (_downloadingWWWDic.ContainsKey(assetBundleName)) { return(true); } // ダウンロード実行中リストへ追加 WWW downloadQue = null; // ここでAssetBundleのURLを設定する string url = AssetBundleUtility.GetDownloadPath() + assetBundleName; // マニフェストファイル or AssetBundle if (isDownloadingABManifest) { downloadQue = new WWW(url); } else { if (_assetBundleManifest == null) { downloadQue = WWW.LoadFromCacheOrDownload(url, 0); } else { // ダウンロードキューデータとして成功 downloadQue = WWW.LoadFromCacheOrDownload(url, _assetBundleManifest.GetAssetBundleHash(assetBundleName), 0); } } // ダウンロード実行中リストに追加 _downloadingWWWDic.Add(assetBundleName, downloadQue); // 初ダウンロード return(false); }
/// <summary> /// 暗号化確認 /// </summary> /// <param name="assetBundleNameWithVariant">バリアント付きアセットバンドル名</param> /// <returns>true:暗号化, false:平文</returns> public bool IsCrypto(string assetBundleNameWithVariant) { var result = cryptoAssetBundleNamesWithVariant.ContainsKey(assetBundleNameWithVariant); if (!result && !AssetBundleUtility.IsDeliveryStreamingAsset(assetBundleNameWithVariant)) { //アセットバンドル result = AssetBundleEditorUtility.buildOptionForceCrypto; } return(result); }
public void ExcludeAssetsInAssetBundle() { var platformString = AssetBundleUtility.GetPlatformString(); TestInAssetBundle(platformString, "assetbundleshoshatest/excludematerials", ab => { Assert.IsTrue(ab != null); var assets = ab.LoadAllAssets(); Assert.AreEqual(1, assets.Length); Assert.AreEqual(typeof(DummyWeight), assets[0].GetType()); }); }
public static void SwitchChannel(string channelName) { var channelFolderPath = AssetBundleUtility.PackagePathToAssetsPath(AssetBundleConfig.ChannelFolderName); var guids = AssetDatabase.FindAssets("t:textAsset", new string[] { channelFolderPath }); foreach (var guid in guids) { var path = AssetDatabase.GUIDToAssetPath(guid); UtilityGame.SafeWriteAllText(path, channelName); } AssetDatabase.Refresh(); }
public void IncludeAssetsInCryptoAssetBundle() { var platformString = AssetBundleUtility.GetPlatformString(); TestInAssetBundle(platformString, "assetbundleshoshatest/cryptoassetbundle", ab => { Assert.IsTrue(ab != null); var assets = ab.LoadAllAssets(); Assert.AreEqual(1, assets.Length); var textAsset = (TextAsset)assets[0]; Assert.IsTrue(textAsset.bytes != null); }); }
public static void ClearCache() { var resultOfClearDeliveryStreamingAssetsCache = false; var clearDeliveryStreamingAssetsCache = AssetBundleUtility.ClearDeliveryStreamingAssetsCacheThread(x => resultOfClearDeliveryStreamingAssetsCache = x); clearDeliveryStreamingAssetsCache.Start(); var resultOfClearAssetBundlesCache = Caching.ClearCache(); clearDeliveryStreamingAssetsCache.Join(); if (!resultOfClearAssetBundlesCache || !resultOfClearDeliveryStreamingAssetsCache) { Debug.LogError("Cache clear failed"); Debug.LogError("resultOfClearAssetBundlesCache:" + resultOfClearAssetBundlesCache + ", resultOfClearDeliveryStreamingAssetsCache:" + resultOfClearDeliveryStreamingAssetsCache); } }
/// <summary> /// パス取得 /// </summary> /// <param name="assetBundleNameWithVariant">バリアント付きアセットバンドル名</param> /// <returns>パス</returns> public string GetAssetBundlePath(string assetBundleNameWithVariant) { string result; assetBundleNameWithVariant = assetBundleNameWithVariant.ToLower(); if (AssetBundleUtility.IsDeliveryStreamingAsset(assetBundleNameWithVariant)) { //配信ストリーミングアセット result = m_OutputPath + "/" + m_HashAlgorithm.GetAssetBundleFileName(null, assetBundleNameWithVariant); } else { //アセットバンドル result = m_OutputPath + "/" + m_HashAlgorithm.GetAssetBundleFileName(m_PlatformString, assetBundleNameWithVariant); } return(result); }
// AssetBundleManifestの初期化 public static AssetBundleLoadManifest DownloadManifest() { // 自分自身のオブジェクト生成 if (_myselfObject == null) { _myselfObject = new GameObject("AssetBundleManager", typeof(AssetBundleManager)); } // マニフェストファイルのダウンロード string manifestAssetBundleName = AssetBundleUtility.GetPlatformFolder(); _DownloadAssetBundle(manifestAssetBundleName, true); var loadManifest = new AssetBundleLoadManifest(manifestAssetBundleName, "AssetBundleManifest", typeof(AssetBundleManifest)); _inProgressList.Add(loadManifest); return(loadManifest); }
void CopyTemp2Data() { var tempPath = AssetBundleUtility.GetPersistentTempPath(); var files = GameUtility.GetAllFilesInFolder(tempPath); if (files.Length > 0) { foreach (string fromfile in files) { string tofile = fromfile.Replace(AssetBundleConfig.TempFolderName, AssetBundleConfig.AssetBundlesFolderName); GameUtility.SafeCopyFile(fromfile, tofile); GameUtility.SafeDeleteFile(fromfile); } GameUtility.SafeDeleteDir(tempPath); } }
private void Initialize() { if (_isInitialized) { return; } _isInitialized = true; string path = string.Format("BundleConfig/{0}/AssetBundleBundleInfo.json", AssetBundleUtility.GetPlatformName()); TextAsset textAsset = Resources.Load <TextAsset>(path); if (textAsset == null) { return; } _serverAssetBundleVersions = JsonConvert.DeserializeObject <Dictionary <string, ServerAssetBundleVersion> >(textAsset.text); //UnityEngine.AssetBundle.lo }