Version: 2020.3

AssetDatabase.GUIDToAssetPath

切换到手册
public static string GUIDToAssetPath (string guid);
public static string GUIDToAssetPath (GUID guid);

参数

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.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961