-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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