guid | The GUID of an asset. |
string Path of the asset relative to the project folder.
Gets the corresponding asset path for the supplied GUID, or an empty string if the GUID can't be found.
返回的路径是相对于项目文件夹的路径,例如:“Assets/MyTextures/hello.png”。
using UnityEditor; using UnityEngine;
public class GUIDToAssetPathExample : MonoBehaviour { [MenuItem("APIExamples/GUIDToAssetPath")] static void MaterialPathsInProject() { var allMaterials = AssetDatabase.FindAssets("t: Material");
foreach (var guid in allMaterials) { var path = AssetDatabase.GUIDToAssetPath(guid); Debug.Log(path); } } }
See AssetDatabase.AssetPathToGUID for a version that returns a string instead of a UnityEditor.GUID.