assetPath | 要加载的资源的文件系统路径。 |
如果 assetPath
中的主资源对象已加载到内存中,则返回 true。
所有路径相对于项目文件夹,例如:"Assets/MyTextures/hello.png"。
其他资源: AssetDatabase.LoadMainAssetAtPath, Resources.UnloadAsset, EditorUtility.UnloadUnusedAssetsImmediate.
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)); } }