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 13:27:45 浏览: 172
这段代码也是用于加载 Unity 引擎中的 Asset Bundle 资源文件,相比于之前的代码,这个函数会将整个 Asset Bundle 文件加载到内存中,并通过回调函数将其返回,而不仅仅是加载其中指定名称的资源文件。其中的泛型类型 T 用于指定要加载的资源类型,例如可以是音频、图片、场景等等。具体来说,这段代码也会从应用程序的 StreamingAssets 路径中获取指定的 Asset Bundle 文件,然后加载其中指定名称的资源文件并返回,并包括了回调函数的处理,以及最后释放 Asset Bundle 的资源。
相关问题
类型“IEnumerator<T>”需要 1 个类型参数
这个错误提示是因为在定义一个实现 IEnumerator<T> 接口的类或方法时,没有指定泛型类型参数 T。
例如,以下代码中的 MyList 类定义实现了 IEnumerator 接口,但没有指定泛型类型参数 T:
```csharp
class MyList : IEnumerator
{
//...
}
```
应该将其改为:
```csharp
class MyList<T> : IEnumerator<T>
{
//...
}
```
这样就指定了泛型类型参数 T,可以在类中使用该类型。
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() 方法中出现了问题。可能是该方法中使用了一个没有实例化的对象。你需要检查代码中是否有未正确初始化的对象或变量。
阅读全文
相关推荐
















