Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AssetBundle.LoadFromFileAsync

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method LoadFromFileAsync(path: string, crc: uint = 0, offset: ulong = 0): AssetBundleCreateRequest;
public static AssetBundleCreateRequest LoadFromFileAsync(string path, uint crc = 0, ulong offset = 0);

Parameters

pathPath of the file on disk.
crcAn optional CRC-32 checksum of the uncompressed content. If this is non-zero, then the content will be compared against the checksum before loading it, and give an error if it does not match.
offsetAn optional byte offset. This value specifies where to start reading the AssetBundle from.

Returns

AssetBundleCreateRequest Asynchronous create request for an AssetBundle. Use assetBundle property to get an AssetBundle once it is loaded.

Description

Asynchronously loads an AssetBundle from a file on disk.

The function supports bundles of any compression type. In case of lzma compression, the data will be decompressed to the memory. Uncompressed and chunk-compressed bundles can be read directly from disk.

This is the fastest way to load an AssetBundle.

// Load asset bundles in the background whilst other tasks can be made.
#pragma strict

import System.IO;

public class LoadFromFileAsyncExample extends MonoBehaviour {

function Start() { var bundleLoadRequest = AssetBundle.LoadFromFileAsync(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); yield bundleLoadRequest;

var myLoadedAssetBundle = bundleLoadRequest.assetBundle; if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); return; }

var assetLoadRequest = myLoadedAssetBundle.LoadAssetAsync.<GameObject>("MyObject"); yield assetLoadRequest;

var prefab: GameObject = assetLoadRequest.asset as GameObject; Instantiate(prefab);

myLoadedAssetBundle.Unload(false);

} }
using UnityEngine;
using System.Collections;
using System.IO;

public class LoadFromFileAsyncExample : MonoBehaviour { IEnumerator Start() { var bundleLoadRequest = AssetBundle.LoadFromFileAsync(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); yield return bundleLoadRequest;

var myLoadedAssetBundle = bundleLoadRequest.assetBundle; if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); yield break; }

var assetLoadRequest = myLoadedAssetBundle.LoadAssetAsync<GameObject>("MyObject"); yield return assetLoadRequest;

GameObject prefab = assetLoadRequest.asset as GameObject; Instantiate(prefab);

myLoadedAssetBundle.Unload(false); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961