Version: 2019.3
public static Object InstanceIDToObject (int instanceID);

説明

インスタンス ID をオブジェクト参照へと変換します

オブジェクトがディスクから読み込まれていない場合はディスクから読み込みます。


Editor Window to enter the instance ID and print the name of the object.

using UnityEngine;
using UnityEditor;

public class InstanceIDToObjectExample : EditorWindow { static int id;

[MenuItem("Example/ID To Name")] static void Init() { // Get existing open window or if none, make a new one: InstanceIDToObjectExample window = (InstanceIDToObjectExample)EditorWindow.GetWindow(typeof(InstanceIDToObjectExample)); window.Show(); }

void OnGUI() { id = EditorGUILayout.IntField("Instance ID:", id); if (GUILayout.Button("Find Name")) { Object obj = EditorUtility.InstanceIDToObject(id); if (!obj) Debug.LogError("No object could be found with instance id: " + id); else Debug.Log("Object's name: " + obj.name); } }

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