Skip to content

Commit ce91d3c

Browse files
committed
feat: Copy object instance id
1 parent 950d75a commit ce91d3c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Editor/Scripts/AssetHandle.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ public void CopyTypeFullNameToSystemBuffer()
252252
GUIUtility.systemCopyBuffer = GetAssetTypeFullName();
253253
}
254254

255+
public void CopyInstanceIdToSystemBuffer()
256+
{
257+
GUIUtility.systemCopyBuffer = GetAssetInstanceId().ToString();
258+
}
259+
255260
public string GetAssetName()
256261
{
257262
switch (Category)
@@ -333,13 +338,35 @@ public string GetAssetTypeFullName()
333338
return null;
334339

335340
case AssetCategory.ExternalFile:
341+
case AssetCategory.Url:
336342
return null;
337343

338344
default:
339345
throw new ArgumentOutOfRangeException(nameof(Category), Category, null);
340346
}
341347
}
342348

349+
public int GetAssetInstanceId()
350+
{
351+
switch (Category)
352+
{
353+
case AssetCategory.ProjectAsset:
354+
case AssetCategory.SceneObject:
355+
if (_asset)
356+
{
357+
return _asset.GetInstanceID();
358+
}
359+
return 0;
360+
361+
case AssetCategory.ExternalFile:
362+
case AssetCategory.Url:
363+
return 0;
364+
365+
default:
366+
throw new ArgumentOutOfRangeException(nameof(Category), Category, null);
367+
}
368+
}
369+
343370
public string GetDisplayName()
344371
{
345372
if (Asset)

Editor/Scripts/AssetQuickAccessWindow.ListContent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ private void ShowProjectAssetContextMenu(AssetHandle assetHandle)
233233
genericMenu.AddItem(new GUIContent("Copy Path"), false, assetHandle.CopyPathToSystemBuffer);
234234
genericMenu.AddItem(new GUIContent("Copy Guid"), false, assetHandle.CopyGuidToSystemBuffer);
235235
genericMenu.AddItem(new GUIContent("Copy Type"), false, assetHandle.CopyTypeFullNameToSystemBuffer);
236+
genericMenu.AddItem(new GUIContent("Copy Instance ID"), false, assetHandle.CopyInstanceIdToSystemBuffer);
236237
genericMenu.AddItem(new GUIContent("Show in Folder"), false, assetHandle.ShowInFolder);
237238
}
238239
else
@@ -254,6 +255,7 @@ private void ShowSceneObjectContextMenu(AssetHandle assetHandle)
254255
genericMenu.AddItem(new GUIContent("Open"), false, assetHandle.OpenAsset);
255256
genericMenu.AddItem(new GUIContent("Copy Hierarchy Path"), false, assetHandle.CopyPathToSystemBuffer);
256257
genericMenu.AddItem(new GUIContent("Copy Type"), false, assetHandle.CopyTypeFullNameToSystemBuffer);
258+
genericMenu.AddItem(new GUIContent("Copy Instance ID"), false, assetHandle.CopyInstanceIdToSystemBuffer);
257259
}
258260
else if (assetHandle.Scene)
259261
{

0 commit comments

Comments
 (0)