Skip to content

Commit

Permalink
feat: Find object by instance id
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarianZ committed Sep 1, 2024
1 parent ce91d3c commit 0170d0b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Editor/Scripts/AssetQuickAccessWindow.BottomContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,31 @@ private void DrawBottomTips()
private void DrawFindObjectContent()
{
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Path/Guid", GUILayout.Width(60));
EditorGUILayout.LabelField("Path/Guid/InstanceId", GUILayout.Width(120));
_assetIdentifier = EditorGUILayout.TextField(_assetIdentifier);
EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(_assetIdentifier));
if (GUILayout.Button("Find", GUILayout.Width(60)))
{
FindObjectByPathOrGuid();
FindObject();
}
EditorGUI.EndDisabledGroup();
GUILayout.EndHorizontal();
}

private void FindObjectByPathOrGuid()
private void FindObject()
{
Assert.IsTrue(!string.IsNullOrEmpty(_assetIdentifier));

if (int.TryParse(_assetIdentifier, out int instanceId))
{
UObject obj = EditorUtility.InstanceIDToObject(instanceId);
if (obj)
{
EditorGUIUtility.PingObject(obj);
return;
}
}

string filePath = AssetDatabase.GUIDToAssetPath(_assetIdentifier);
if (string.IsNullOrEmpty(filePath))
{
Expand Down

0 comments on commit 0170d0b

Please sign in to comment.