Skip to content

Instantly share code, notes, and snippets.

@starikcetin
Created June 11, 2023 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starikcetin/9343f311071ea65430a78b3815e9ebc7 to your computer and use it in GitHub Desktop.
Save starikcetin/9343f311071ea65430a78b3815e9ebc7 to your computer and use it in GitHub Desktop.
Unity Project Window GUID Tools
using System.Text;
using UnityEditor;
using UnityEngine;
public static class GuidTools
{
[MenuItem("Assets/GUID Tools/Log GUIDs")]
private static void LogGuids()
{
var guids = Selection.assetGUIDs;
var sb = new StringBuilder();
sb.AppendLine($"GUIDs of the selected assets ({guids.Length} items):");
foreach (var guid in guids)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
sb.AppendLine($"{path}: {guid}");
}
Debug.Log(sb.ToString());
}
[MenuItem("Assets/GUID Tools/Log and Copy GUID", validate = false)]
private static void LogAndCopyGuid()
{
var selection = Selection.activeObject;
var path = AssetDatabase.GetAssetPath(selection);
var guid = AssetDatabase.GUIDFromAssetPath(path);
Debug.Log($"Copying the GUID of the selected asset ({path}): {guid}");
EditorGUIUtility.systemCopyBuffer = guid.ToString();
}
[MenuItem("Assets/GUID Tools/Log and Copy GUID", validate = true)]
private static bool LogAndCopyGuid_Validate()
{
return Selection.count == 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment