Skip to content

Instantly share code, notes, and snippets.

@FreyaHolmer
Forked from Unity-Javier/LibraryPathsForAsset.cs
Last active July 30, 2024 08:07
Show Gist options
  • Save FreyaHolmer/dcb561b845a3cc914ca66d13a9f13a33 to your computer and use it in GitHub Desktop.
Save FreyaHolmer/dcb561b845a3cc914ca66d13a9f13a33 to your computer and use it in GitHub Desktop.
Adds a context menu to assets in the project browser to print the file path location of their imported serialized assets
using System;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEditor.Experimental;
using UnityEngine;
public static class LibraryPathsForAsset {
[MenuItem( "Assets/Print library paths", false, priority = 70, secondaryPriority = 1 )]
public static void OutputLibraryPathsForAsset() {
// Iterate over all selected assets
foreach( string guidStr in Selection.assetGUIDs ) {
GUID guid = new(guidStr);
ArtifactKey key = new(guid);
ArtifactID id = AssetDatabaseExperimental.LookupArtifact( key );
string assetPath = AssetDatabase.GUIDToAssetPath( guid );
if( AssetDatabaseExperimental.GetArtifactPaths( id, out string[] paths ) == false ) {
Debug.LogWarning( $"Failed to load artifacts for {assetPath}" );
continue;
}
// print all associated paths
Debug.Log( new StringBuilder()
.AppendLine( $"Files of {assetPath}:" )
.AppendJoin( Environment.NewLine,
paths.Select( v => '\t' + Path.GetFullPath( v ) )
)
);
}
}
[MenuItem( "Assets/Print library paths", true )]
public static bool OutputLibraryPathsForAssetValidate() => Selection.assetGUIDs.Length > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment