表示按需加载资源 (ODR) 的请求。它是一个 AsyncOperation,可在协同程序中生成。
注意:仅适用于 iOS。
Creating an OnDemandResourcesRequest is equivalent to calling NSBundleResourceRequest.beginAccessingResourcesWithCompletionHandler. The request will keep the on demand resource alive until either Dispose() is called or the request object is collected by a garbage collector, which is the equivalent of calling NSBundleResourceRequest.endAccessingResources class.
using UnityEngine; using UnityEngine.iOS; using System; using System.Collections;
public static class Loader { public static IEnumerator LoadAsset(string resourceName) { // Create the request var request = OnDemandResources.PreloadAsync(new string[] { "Asset's ODR tag" });
// Wait until request is completed yield return request;
// Check for errors if (request.error != null) throw new Exception("ODR request failed: " + request.error);
// Get path to the resource and use it var path = request.GetResourcePath(resourceName); Debug.Log(path);
// Call Dispose() when resource is no longer needed. request.Dispose(); } }
| error | 在操作完成后返回错误。 | 
| loadingPriority | 设置请求的优先级。 | 
| Dispose | 释放按需加载资源 (ODR) 请求使其保持活动状态的所有资源。 | 
| GetResourcePath | 获取指向按需加载资源 (ODR) 请求中可用资源的文件系统路径。 | 
| allowSceneActivation | 允许在场景准备就绪后立即激活场景。 | 
| isDone | 操作是否已完成?(只读) | 
| priority | Priority 允许您调整执行异步操作调用的顺序。 | 
| progress | 获取操作进度。(只读) |