public IEnumerator LoadAssetBundleByAll<T>(UIInfo uIInfo,Action<AssetBundle> loadCGCallBack, Action loadCallBack = null) where T : UnityEngine.Object { UnityWebRequest unityWeb = UnityWebRequestAssetBundle.GetAssetBundle(Application.streamingAssetsPath + "/" + uIInfo.groupName); yield return unityWeb.SendWebRequest(); if (unityWeb.error != null) { yield break; } AssetBundle ab = DownloadHandlerAssetBundle.GetContent(unityWeb); T obj = ab.LoadAsset<T>(uIInfo.objName); if (loadCGCallBack != null) { loadCGCallBack(ab); loadCGCallBack = null; } if (loadCallBack != null) { loadCallBack(); loadCallBack = null; } ab.Unload(false); yield return null; }
时间: 2024-02-15 11:27:45 浏览: 164
这段代码也是用于加载 Unity 引擎中的 Asset Bundle 资源文件,相比于之前的代码,这个函数会将整个 Asset Bundle 文件加载到内存中,并通过回调函数将其返回,而不仅仅是加载其中指定名称的资源文件。其中的泛型类型 T 用于指定要加载的资源类型,例如可以是音频、图片、场景等等。具体来说,这段代码也会从应用程序的 StreamingAssets 路径中获取指定的 Asset Bundle 文件,然后加载其中指定名称的资源文件并返回,并包括了回调函数的处理,以及最后释放 Asset Bundle 的资源。
相关问题
NullReferenceException: Object reference not set to an instance of an object. at YooAsset.ResourcePackage.ConvertLocationToAssetInfo (System.String location, System.Type assetType) [0x00000] in <00000000000000000000000000000000>:0 at YooAsset.ResourcePackage.LoadRawFileAsync (System.String location) [0x00000] in <00000000000000000000000000000000>:0 at CosmosAR.FsmSceneResInitialize+<Prepare>d__6.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 at CosmosAR.FsmSceneARInitialize+<Prepare>d__5.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 CosmosAR.<Prepare>d__5:MoveNext() UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
这是一个 NullReferenceException 异常,通常是因为尝试使用一个空对象的属性或方法所导致的。根据该异常信息中提供的堆栈跟踪,可以看到在 YooAsset.ResourcePackage.ConvertLocationToAssetInfo() 方法中出现了问题。可能是该方法中使用了一个没有实例化的对象。你需要检查代码中是否有未正确初始化的对象或变量。
TypeLoadException: Could not load type 'UnityEngine.AudioSource' from assembly 'UnityEngine.AudioModule'.;System.AppDomain.Load (System.Byte[] rawAssembly, System.Byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence, System.Boolean refonly) (at <00000000000000000000000000000000>:0) CosmosAR.FsmOpenSceneResInitialize+<Prepare>d__5.MoveNext () (at <00000000000000000000000000000000>:0) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <00000000000000000000000000000000>:0)
这似乎是一个Unity游戏引擎的错误,可能是由于Unity的AudioModule模块无法加载UnityEngine.AudioSource类型引起的。建议检查您的Unity项目中是否存在任何缺失的依赖项或损坏的脚本,并尝试重新导入AudioModule模块或更新Unity版本。如果问题仍然存在,可以尝试在Unity论坛或社区中寻求帮助。
阅读全文