From a80d9e64b60403c71ff7ff32c9e94e6833f50ace Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期三, 10 九月 2025 22:28:26 +0800
Subject: [PATCH] 0312 优化删除物品的通知
---
Main/ResModule/AssetBundle/AssetBundleUtility.cs | 77 ++++++++++++++++++--------------------
1 files changed, 36 insertions(+), 41 deletions(-)
diff --git a/Main/ResModule/AssetBundle/AssetBundleUtility.cs b/Main/ResModule/AssetBundle/AssetBundleUtility.cs
index abc9bc8..0337822 100644
--- a/Main/ResModule/AssetBundle/AssetBundleUtility.cs
+++ b/Main/ResModule/AssetBundle/AssetBundleUtility.cs
@@ -3,7 +3,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
-
+using Cysharp.Threading.Tasks;
public class AssetBundleUtility : SingletonMonobehaviour<AssetBundleUtility>
{
@@ -97,23 +97,23 @@
assetBundle = null;
}
- public IEnumerator Initialize()
+ public async UniTask Initialize()
{
- yield return StartCoroutine(Co_LoadMainfestFile("audio"));
- yield return StartCoroutine(Co_LoadMainfestFile("video"));
- yield return StartCoroutine(Co_LoadMainfestFile("mobeffectshader"));
- yield return StartCoroutine(Co_LoadMainfestFile("config"));
- yield return StartCoroutine(Co_LoadMainfestFile("maps"));
- yield return StartCoroutine(Co_LoadMainfestFile("ui"));
+ await Co_LoadMainfestFile("audio");
+ await Co_LoadMainfestFile("video");
+ await Co_LoadMainfestFile("mobeffectshader");
+ await Co_LoadMainfestFile("config");
+ await Co_LoadMainfestFile("maps");
+ await Co_LoadMainfestFile("ui");
- yield return StartCoroutine(Co_LoadAssetBundle(ResourcesPath.windowFileBundleName));
- yield return StartCoroutine(Co_LoadAssetBundle(ResourcesPath.uiprefabFileBundleName));
+ await Co_LoadAssetBundle(ResourcesPath.windowFileBundleName);
+ await Co_LoadAssetBundle(ResourcesPath.uiprefabFileBundleName);
initializedUIAssetBundle = true;
initialized = true;
}
- private IEnumerator Co_LoadMainfestFile(string _category)
+ private async UniTask Co_LoadMainfestFile(string _category)
{
var path = AssetVersionUtility.GetAssetFilePath(StringUtility.Contact(AssetVersionUtility.EncodeFileName(_category), "_assetbundle"), false);
var _assetBundle = AssetBundle.LoadFromFile(path);
@@ -121,14 +121,14 @@
if (_assetBundle == null)
{
Debug.LogErrorFormat("AssetBundleManifest鐨勫寘鏂囦欢涓虹┖鎴栬�呭姞杞藉嚭閿�. Path:{0}", path);
- yield break;
+ return;
}
AssetBundleManifest _assetBundleManifest = _assetBundle.LoadAsset<AssetBundleManifest>(ResourcesPath.AssetDependentFileAssetName);
if (_assetBundleManifest == null)
{
Debug.LogErrorFormat("AssetBundleManifest鐨勫寘鏂囦欢涓虹┖鎴栬�呭姞杞藉嚭閿�. Path:{0}", path);
- yield break;
+ return;
}
string[] _assetBundleNames = _assetBundleManifest.GetAllAssetBundles();
@@ -172,10 +172,10 @@
return;
}
- StartCoroutine(Co_DoLoadAsset(assetBundleName, assetName, callBack));
+ Co_DoLoadAsset(assetBundleName, assetName, callBack).Forget();
}
- private IEnumerator Co_LoadAssetBundle(string assetBundleName)
+ private async UniTask<AssetBundle> Co_LoadAssetBundle(string assetBundleName)
{
#if UNITY_5||UNITY_5_3_OR_NEWER
assetBundleName = assetBundleName.ToLower();
@@ -183,7 +183,7 @@
if (JudgeExistAssetBundle(assetBundleName))
{
- yield break;
+ return m_AssetBundleDict[assetBundleName];
}
if (m_LoadingAssetBundleList.Contains(assetBundleName))
@@ -191,9 +191,9 @@
while (!m_AssetBundleDict.ContainsKey(assetBundleName))
{
// Debug.Log(Time.frameCount + " ] 姝e湪鍔犺浇AssetBundle: " + assetBundleName + ", 璇风瓑寰�...");
- yield return null;
+ await UniTask.Yield();
}
- yield break;
+ return m_AssetBundleDict[assetBundleName];
}
m_LoadingAssetBundleList.Add(assetBundleName);
@@ -202,12 +202,13 @@
if (_assetBundleInfo == null)
{
Debug.LogErrorFormat("Co_LoadAssetBundle(): {0}鍑虹幇閿欒 => 涓嶅瓨鍦ˋssetBundleInfo. ", assetBundleName);
- yield break;
+ m_LoadingAssetBundleList.Remove(assetBundleName);
+ return null;
}
if (_assetBundleInfo.dependentBundles.Length > 0)
{
- yield return Co_LoadAssetBundleDependenice(_assetBundleInfo);
+ await Co_LoadAssetBundleDependenice(_assetBundleInfo);
}
var isBuiltin = assetBundleName.Contains("builtin");
@@ -216,44 +217,41 @@
Debug.LogFormat("Co_LoadAssetBundle(): 灏嗚鍔犺浇鐨刟ssetBundle鍖呰矾寰� => {0}", filePath);
var _request = AssetBundle.LoadFromFileAsync(filePath);
- while (!_request.isDone)
- {
- yield return null;
- }
+ await _request;
CacheAssetBundle(assetBundleName, _request.assetBundle);
m_LoadingAssetBundleList.Remove(assetBundleName);
+ return _request.assetBundle;
}
- private IEnumerator Co_LoadAssetBundleDependenice(AssetBundleInfo assetBundleInfo)
+ private async UniTask Co_LoadAssetBundleDependenice(AssetBundleInfo assetBundleInfo)
{
AssetBundle _assetBundle = null;
if (assetBundleInfo.dependentBundles == null
|| assetBundleInfo.dependentBundles.Length == 0)
{
- yield break;
+ return;
}
for (int i = 0; i < assetBundleInfo.dependentBundles.Length; ++i)
{
-
if (m_AssetBundleDict.TryGetValue(assetBundleInfo.dependentBundles[i], out _assetBundle) == false)
{
- yield return Co_LoadAssetBundle(assetBundleInfo.dependentBundles[i]);
+ await Co_LoadAssetBundle(assetBundleInfo.dependentBundles[i]);
}
else
{
if (_assetBundle == null)
{
- yield return Co_LoadAssetBundle(assetBundleInfo.dependentBundles[i]);
+ await Co_LoadAssetBundle(assetBundleInfo.dependentBundles[i]);
}
}
}
}
- private IEnumerator Co_DoLoadAsset(string assetBundleName, string assetName, Action<bool, UnityEngine.Object> callBack = null)
+ private async UniTask Co_DoLoadAsset(string assetBundleName, string assetName, Action<bool, UnityEngine.Object> callBack = null)
{
#if UNITY_5||UNITY_5_3_OR_NEWER
assetBundleName = assetBundleName.ToLower();
@@ -263,7 +261,7 @@
RunTimeABLoadLog.AddLog(assetBundleName, assetName, UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
#endif
- yield return Co_LoadAssetBundle(assetBundleName);
+ await Co_LoadAssetBundle(assetBundleName);
if (!m_AssetBundleDict.ContainsKey(assetBundleName))
{
@@ -271,7 +269,7 @@
{
callBack(false, null);
}
- yield break;
+ return;
}
string _checkTag = assetBundleName + "@" + assetName;
@@ -281,7 +279,7 @@
|| !m_AssetDict[assetBundleName].ContainsKey(assetName))
{
// Debug.Log(Time.frameCount + " ] 姝e湪鍔犺浇Asset: " + _checkTag + ", 璇风瓑寰�...");
- yield return null;
+ await UniTask.Yield();
}
if (callBack != null)
@@ -289,16 +287,13 @@
callBack(true, m_AssetDict[assetBundleName][assetName]);
}
- yield break;
+ return;
}
m_LoadingAssetList.Add(_checkTag);
var request = m_AssetBundleDict[assetBundleName].LoadAssetAsync(assetName);
- while (!request.isDone)
- {
- yield return null;
- }
+ await request;
if (request.asset != null)
{
@@ -319,14 +314,14 @@
m_LoadingAssetList.Remove(_checkTag);
}
- private IEnumerator Co_DoLoadAsset(AssetInfo assetInfo, Action<bool, UnityEngine.Object> callBack = null)
+ private async UniTask Co_DoLoadAsset(AssetInfo assetInfo, Action<bool, UnityEngine.Object> callBack = null)
{
if (assetInfo == null)
{
Debug.LogErrorFormat("Co_DoLoadAsset(): {0}, 鍑虹幇閿欒 => 瀛樺叆鐨凙ssetInfo涓簄ull. ", assetInfo);
- yield break;
+ return;
}
- yield return Co_DoLoadAsset(assetInfo.assetBundleName, assetInfo.name, callBack);
+ await Co_DoLoadAsset(assetInfo.assetBundleName, assetInfo.name, callBack);
}
#endregion
--
Gitblit v1.8.0