Created
February 17, 2020 10:26
-
-
Save Unity-Javier/50408443ddda2f64d029eb3a5e71cfe4 to your computer and use it in GitHub Desktop.
Get the path to the Library folder (or in-memory DB) for all assets in a project
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.IO; | |
using System.Text; | |
using UnityEditor; | |
using UnityEditor.Experimental; | |
using UnityEngine; | |
public class DumpAllAssetPaths : MonoBehaviour | |
{ | |
[MenuItem("AssetDatabase/OutputAllLibraryPaths")] | |
public static void OutputPathToAssets() | |
{ | |
var findAssetsResult = AssetDatabase.GetAllAssetPaths(); | |
StringBuilder assetPathInfo = new StringBuilder(); | |
foreach (var assetPath in findAssetsResult) | |
{ | |
var guidString = AssetDatabase.AssetPathToGUID(assetPath); | |
var hash = AssetDatabaseExperimental.GetArtifactHash(guidString); | |
AssetDatabaseExperimental.GetArtifactPaths(hash, out var paths); | |
assetPathInfo.Append(AssetDatabase.GUIDToAssetPath(guidString)); | |
assetPathInfo.AppendLine(); | |
foreach (var curVirtualPath in paths) | |
{ | |
//.info files are the asset previews which you can see as part | |
//of the asset icon | |
if(curVirtualPath.EndsWith(".info")) | |
continue; | |
//The virtual path redirects somewhere, so we get the | |
//actual path on disk (or on the in memory database, accordingly) | |
var curPath = Path.GetFullPath(curVirtualPath); | |
assetPathInfo.Append("\t" + curPath); | |
assetPathInfo.AppendLine(); | |
} | |
} | |
Debug.Log("Path info for all assets:\n"+assetPathInfo.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment