OnDemandResourcesRequest
Represents a request for On Demand Resources (ODR). It's an AsyncOperation and can be yielded in a coroutine.
Read time 1 minuteLast updated 7 days ago
Definition
- Type: Class
- Namespace: UnityEngine.iOS
- Assembly: UnityEngine.CoreModule
- Inherits from: AsyncOperation
- Implements: IDisposable
public sealed class OnDemandResourcesRequest : AsyncOperation, IDisposable
Remarks
NOTE: only available on iOS.
Creating an OnDemandResourcesRequest is equivalent to calling NSBundleResourceRequest.beginAccessingResourcesWithCompletionHandler. The request will keep the on demand resource alive until either OnDemandResourcesRequest.Dispose() is called or the request object is collected by a garbage collector, which is the equivalent of calling NSBundleResourceRequest.endAccessingResources.
Examples
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(); }}
Properties
Property | Description |
|---|---|
| error | Returns an error after operation is complete. |
| loadingPriority | Sets the priority for request. |
Methods
Method | Description |
|---|---|
| Dispose | Release all resources kept alive by On Demand Resources (ODR) request. |
| GetResourcePath | Gets file system's path to the resource available in On Demand Resources (ODR) request. |