Version: 2023.1

AssetBundle

class in UnityEngine

/

继承自:Object

切换到手册

描述

API for accessing the content of AssetBundle files.

This class exposes an API, via static methods, for loading and managing AssetBundles.

This same class offers non-static methods and properties that expose the contents of a specific loaded AssetBundle, including the ability to load an Asset from within an AssetBundle.

Create AssetBundles by calling BuildPipeline.BuildAssetBundles or using the Addressables package. The build process generates one or more AssetBundle files, and each AssetBundle file contains a serialized instance of this class.

Note: AssetBundle.LoadAsset, and the other Load methods, do not support loading Scenes from AssetBundles. Instead, once a streamed scene AssetBundle has been loaded you can call SceneManager.LoadScene or SceneManager.LoadSceneAsync.

See Also: Intro to AssetBundles, UnityWebRequestAssetBundle.GetAssetBundle, BuildPipeline.BuildAssetBundles.

using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

public class SampleBehaviour : MonoBehaviour { IEnumerator Start() { var uwr = UnityWebRequestAssetBundle.GetAssetBundle("https://myserver/myBundle.unity3d"); yield return uwr.SendWebRequest();

// Get an asset from the bundle and instantiate it. AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); var loadAsset = bundle.LoadAssetAsync<GameObject>("Assets/Players/MainPlayer.prefab"); yield return loadAsset;

Instantiate(loadAsset.asset); } }

静态变量

memoryBudgetKBControls the size of the shared AssetBundle loading cache. Default value is 1MB.

变量

isStreamedSceneAssetBundleReturn true if the AssetBundle contains Unity Scene files

公共函数

Contains检查 AssetBundle 是否包含特定对象。
GetAllAssetNamesReturn all Asset names in the AssetBundle.
GetAllScenePathsReturn all the names of Scenes in the AssetBundle.
LoadAllAssetsLoads all Assets contained in the AssetBundle synchronously.
LoadAllAssetsAsyncLoads all Assets contained in the AssetBundle asynchronously.
LoadAssetSynchronously loads an Asset from the AssetBundle.
LoadAssetAsyncAsynchronously loads an Asset from the bundle.
LoadAssetWithSubAssetsLoads Asset and sub Assets from the AssetBundle synchronously.
LoadAssetWithSubAssetsAsyncLoads Asset and sub Assets from the AssetBundle asynchronously.
Unload卸载 AssetBundle 释放其数据。
UnloadAsync卸载捆绑包中的资源。

静态函数

GetAllLoadedAssetBundlesGet an enumeration of all the currently loaded AssetBundles.
LoadFromFile从磁盘上的文件同步加载 AssetBundle。
LoadFromFileAsync从磁盘上的文件异步加载 AssetBundle。
LoadFromMemorySynchronously load an AssetBundle from a memory region.
LoadFromMemoryAsyncAsynchronously load an AssetBundle from a memory region.
LoadFromStream从托管 Stream 同步加载 AssetBundle。
LoadFromStreamAsync从托管 Stream 异步加载 AssetBundle。
RecompressAssetBundleAsync异步将下载/存储的 AssetBundle 从一个 BuildCompression 再压缩为另一个。
UnloadAllAssetBundles卸载当前已加载的所有 AssetBundle。

继承的成员

变量

hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。