Version: 2021.3

AssetDatabase.IsMainAssetAtPathLoaded

切换到手册
public static bool IsMainAssetAtPathLoaded (string assetPath);

参数

assetPath 要加载的资源的文件系统路径。

描述

如果在内存中加载 assetPath 下的主资源对象,则返回 true。

所有路径均是相对于项目文件夹的路径,例如:"Assets/MyTextures/hello.png"。

另请参阅:AssetDatabase.LoadMainAssetAtPathResources.UnloadAsset

using UnityEditor;
using UnityEngine;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Is Main Asset At Path Loaded")] static void IsMainAssetAtPathLoadedExample() { //Create a material and unload it var materialPath = "Assets/Materials/NewMat0.mat"; var material = new Material(Shader.Find("Standard")); AssetDatabase.CreateAsset(material, materialPath); Resources.UnloadAsset(material);

//This will be false Debug.Log(AssetDatabase.IsMainAssetAtPathLoaded(materialPath)); //Load material into memory AssetDatabase.LoadAssetAtPath(materialPath, typeof(Object)); //This will be true Debug.Log(AssetDatabase.IsMainAssetAtPathLoaded(materialPath)); } }