Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

AssetBundle.LoadFromFileAsync

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function LoadFromFileAsync(path: string, crc: uint = 0, offset: ulong = 0): AssetBundleCreateRequest;
public static AssetBundleCreateRequest LoadFromFileAsync(string path, uint crc = 0, ulong offset = 0);

Parámetros

path Path of the file on disk.
crc An 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.
offset An optional byte offset. This value specifies where to start reading the AssetBundle from.

Valor de retorno

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

Descripción

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.

public class LoadFromFileAsyncExample extends MonoBehaviour {
	function Start() {
		var bundleLoadRequest = AssetBundle.LoadFromFileAsync(Path.Combine(Application.streamingAssetsPath, "myassetBundle"));
		bundleLoadRequestvar myLoadedAssetBundle: var = bundleLoadRequest.assetBundle;
		if (myLoadedAssetBundle == null) {
			Debug.Log("Failed to load AssetBundle!");
			return;
		}
		var assetLoadRequest = myLoadedAssetBundle.LoadAssetAsync.<GameObject>("MyObject");
		yield return assetLoadRequest;
		var prefab: GameObject = assetLoadRequest.asset as GameObject;
		Instantiate(prefab);
		myLoadedAssetBundle.Unload(false);
	}
}
using UnityEngine;
using System.Collections;

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); } }