Version: 2017.1

OnDemandResourcesRequest

class in UnityEngine.iOS

/

继承自:AsyncOperation

切换到手册

描述

表示按需加载资源 (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操作是否已完成?(只读)
priorityPriority 允许您调整执行异步操作调用的顺序。
progress获取操作进度。(只读)