assetPath | 要加载的资源的文件系统路径。 |
如果在内存中加载 assetPath
下的主资源对象,则返回 true。
所有路径均是相对于项目文件夹的路径,例如:"Assets/MyTextures/hello.png"。
另请参阅:AssetDatabase.LoadMainAssetAtPath、Resources.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)); } }