assetPath | 要加载的资源的路径。 |
localId | 要加载的对象的本地标识符。这允许您加载特定对象及其依赖项,而不是整个资源。 |
AssetDatabaseLoadOperation 一个 UnityEditor.AssetDatabaseLoadOperation,您可以使用它来跟踪操作的进度。
异步加载资源文件中的特定对象及其依赖项。
所有路径相对于项目文件夹,例如:“Assets/MyTextures/hello.png”。
其他资源:AssetDatabase.TryGetGUIDAndLocalFileIdentifier,GlobalObjectId.targetObjectId。
using UnityEngine; using UnityEditor; using System.Collections;
public class MyPlayer : MonoBehaviour { public IEnumerator Start() { // This will load all objects in the fbx and return a single Mesh object. Mesh m = AssetDatabase.LoadAssetAtPath<Mesh>("Assets/test.fbx");
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(m, out string guid, out long localId);
// At some point after the Mesh may or may not have unloaded we can reload just the mesh AssetDatabaseLoadOperation op = AssetDatabase.LoadObjectAsync("Assets/test.fbx", localId);
// yield until the operation is completed while (!op.isDone) yield return null;
Mesh reloadedMesh = (Mesh)op.LoadedObject; } }