Created
September 5, 2018 09:05
-
-
Save monry/f685a25afae495bd93ae1c7ea49d6ece to your computer and use it in GitHub Desktop.
Method to return AssetImporter instance of all selected Asset in Unity Project View
This file contains hidden or 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
public static IEnumerable<AssetImporter> CollectAssetImporters() | |
{ | |
if (Selection.objects.Length == 0) | |
{ | |
throw new InvalidOperationException("Please select target assets or directories."); | |
} | |
return Selection | |
.objects | |
// 選択済要素をパスに変換 | |
.Select(AssetDatabase.GetAssetPath) | |
// ディレクトリのみに絞り込み | |
.Where(AssetDatabase.IsValidFolder) | |
// ディレクトリ以下の全アセットを検索 | |
.SelectMany(x => AssetDatabase.FindAssets("*", new[] {x})) | |
// GUID が返ってくるので、パスに変換 | |
.Select(AssetDatabase.GUIDToAssetPath) | |
// ディレクトリを除外 | |
.Where(x => !AssetDatabase.IsValidFolder(x)) | |
// 選択済要素のウチ、ディレクトリ以外の要素をリストに追加 | |
.Concat( | |
Selection | |
.objects | |
.Select(AssetDatabase.GetAssetPath) | |
.Where(x => !AssetDatabase.IsValidFolder(x)) | |
) | |
.Select(AssetImporter.GetAtPath); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
最終行の
.Select
を外せばパス一覧が取得出来る。