Hello,
We are releasing a preview build for iOS 9 On Demand Resources (ODR) support. We’re planning to release this later in 5.2 cycle. For now the build is based on recent 5.2f1 build with some fixes scheduled for 5.2f2. Download link:
http://beta.unity3d.com/download/e7d4cd3ec86a/download.html
For actual ODR usage you can check or use either an AssetBundle demo located here:
https://oc.unity3d.com/index.php/s/0MsX11aQNR3y30N
or see an example bellow. Note that you need Xcode 7 and iOS 9 for this.
*** AssetBundle demo ***
-
Extract assetbundle-demo-odr.zip and open demo folder in Unity.
-
Switch platform to iOS
-
Build asset bundles through menu option “AssetBundles->Build AssetBundles”.
-
Set “Enable on demand resources” iOS player setting.
-
Make the build. Make sure it’s not a development player.
-
Open and run built Xcode project.
-
If everything goes right, in the log you should see messages like:
[AssetBundleManager] Requesting bundle iOS through ODR
[AssetBundleManager] Requesting bundle cube.unity3d through ODR
[AssetBundleManager] Requesting bundle material.unity3d through ODR
[AssetBundleManager] Requesting bundle texture.unity3d through ODR
And on a screen you should see a pink texture with Unity logo. -
If you get errors like this: “This AssetBundle was not created with UncompressedAssetBundle flag, expected id ‘UnityRaw’, got ‘UnityWeb’”, then make sure that platform is set to iOS, delete AssetBundles/iOS folder in demo project folder and rebuild the bundles.
-
If you want to run scenes in the editor, then first you need to launch asset bundle server through menu option “AssetBundles->Launch AssetBundleServer”.
See LoadAssets.cs for an example of how asset bundles are retrieved through ODR. If you’d like to use the same infrastructure for your project, then just copy demo/Assets/AssetBundleManager folder to your project.
*** A quick start guide for ODR ***
To Use ODR, first enable ODR feature in iOS player settings: “Enable on demand resources”, and then add a callback to report a list of ODR resources you want to include in the build. For this add a new editor script. Script example:
using UnityEditor.iOS;
#if ENABLE_IOS_ON_DEMAND_RESOURCES
public class BuildODR
{
[UnityEditor.InitializeOnLoadMethod]
static void SetupODRBuild()
{
BuildPipeline.collectOnDemandResources += CollectOnDemandResources;
}
static OnDemandResource[ ] CollectOnDemandResources()
{
return new OnDemandResource[ ]
{
new OnDemandResource(){ tags = new [ ]{ “resource_tag” }, path = “Path/Relative/To/Project/asset.data” },
new OnDemandResource(){ tags = new [ ]{ “cube.unity3d” }, path = “AssetBundles/iOS/cube.unity3d” },
};
}
}
#endif
An example of actually using those resources:
using UnityEngine.iOS;
// Coroutine that can be asynchronously executed with StartCoroutine(LoadAsset(“asset.data”));
public static IEnumerator LoadAsset(string resourceName)
{
// Create the request
var request = OnDemandResources.PreloadAsync(new string[ ] { “resource_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);
// Call Dispose() when resource is no longer needed. This will release a pin on ODR resource.
request.Dispose();
}