Version: 2020.2

AssetDatabase.GUIDFromAssetPath

切换到手册
public static GUID GUIDFromAssetPath (string path);

参数

path Filesystem path for the asset. All paths are relative to the project folder.

返回

GUID The GUID of the asset. An all-zero GUID denotes an invalid asset path.

描述

获取 path 下资源的 GUID。

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

using UnityEngine;
using UnityEditor;

public static class Example { [MenuItem("AssetDatabase/GUIDFromAssetPath")] static void Doit() { GUID t = AssetDatabase.GUIDFromAssetPath("Assets/texture.jpg"); Debug.Log(t.ToString()); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961