Version: 2019.2

AssetDatabase.TryGetGUIDAndLocalFileIdentifier

マニュアルに切り替える
Obsolete public static bool TryGetGUIDAndLocalFileIdentifier (Object obj, out string guid, out int localId);
Obsolete public static bool TryGetGUIDAndLocalFileIdentifier (int instanceID, out string guid, out int localId);
public static bool TryGetGUIDAndLocalFileIdentifier (Object obj, out string guid, out long localId);
public static bool TryGetGUIDAndLocalFileIdentifier (int instanceID, out string guid, out long localId);

パラメーター

instanceIDInstanceID of the object to retrieve information for.
objThe object to retrieve GUID and File Id for.
guidThe GUID of the asset.
localIdThe local file identifier of this asset.

戻り値

bool True if the guid and file id were successfully found, false if not.

説明

警告 長い localIdパラメーターでオーバーロードを使用します。整数 localIdパラメーターでオーバーロードを使用すると、"localId''で整数オーバーフローが発生する可能性があります。これは、API に渡されたオブジェクトがプレハブの一部である場合に発生する可能性があります。

Get the GUID and local file id from an object instance id.

When Unity serializes an asset reference it points to two things: the GUID and file ID. GUID is a unique hash, and file ID is a value relative to the asset. Both of these values are used when a serialized asset references another asset.

If working with a text serialized project (see Editor Settings) it is possible to manually modify this information. A common use is moving C# script files from a project to a DLL while keeping any GameObjects using these scripts intact. As an example, suppose your project contains a C# MonoBehaviour, a Scene, and a GameObject with this script attached. When serialized the Unity Scene file will contain something that looks like this (reduced to the relevant parts):

/* example .unity Scene contents:

--- !u!1 &65078845 GameObject: m_Component: -component: {fileID : 65078850} --- !u!114 &65078850 MonoBehaviour: m_Script: {fileID : 11500000, guid : 9cbd8cdf99d44b58972fbc7f6f38088f, type : 3}

*/
using System.Text;
using UnityEngine;
using UnityEditor;

class ShowAssetIds { [MenuItem("Assets/Show Asset Ids")] static void MenuShowIds() { var stringBuilder = new StringBuilder();

foreach (var obj in AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(Selection.activeObject))) { string guid; long file;

if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out guid, out file)) { stringBuilder.AppendFormat("Asset: " + obj.name + "\n Instance ID: " + obj.GetInstanceID() + "\n GUID: " + guid + "\n File ID: " + file); } }

Debug.Log(stringBuilder.ToString()); } }