コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】Addressable Asset System でビルドできるファイルかどうかを確認する方法

概要

using UnityEditor;
using UnityEngine;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var path          = AssetDatabase.GetAssetPath( Selection.activeObject );
        var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath( path );
        var isFolder      = AssetDatabase.IsValidFolder( path );
        var isValid       = mainAssetType != typeof( DefaultAsset ) || isFolder;

        Debug.Log( isValid );
    }
}
  • MainAssetType が DefaultAsset ではない、もしくはフォルダであれば
    Addressable Asset System でビルドできる
  • 参考:GenerateLocationListsTask.cs の以下の処理
if (entry.MainAssetType == typeof(DefaultAsset) && !AssetDatabase.IsValidFolder(entry.AssetPath))
    throw new Exception($"Cannot recognize file type for entry located at '{entry.AssetPath}'. Asset import failed or using an unsupported file type.");