EntityIdToObject(EntityId)
Translates an EntityId to a reference to an object.
阅读时间1 分钟最后更新于 1 个月前
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
public static Object EntityIdToObject(EntityId entityId)
Parameters
Returns
Type | Description |
|---|---|
| Object |
Remarks
If the object is not loaded from disk, loads it from disk.

Editor Window to find an object, whose EntityId we will use to get and print the name of the object.
Examples
using UnityEngine;using UnityEditor;public class EntityIdToObjectExample : EditorWindow{ static Object source; [MenuItem("Example/ID To Name")] static void Init() { // Get existing open window or if none, make a new one: EntityIdToObjectExample window = (EntityIdToObjectExample)EditorWindow.GetWindow(typeof(EntityIdToObjectExample)); window.Show(); } void OnGUI() { source = EditorGUILayout.ObjectField("Entity Id:", source, typeof(Object), true); var id = source ? source.GetEntityId() : EntityId.None; if (GUILayout.Button("Find Name")) { Object obj = EditorUtility.EntityIdToObject(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(); }}