コガネブログ

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

【Unity】Addressable Asset System の BundledAssetGroupSchema の Build Path と Load Path を変更するエディタ拡張

概要

使用例

using System.Linq;
using UnityEditor;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    public static void Hoge()
    {
        var list = AssetDatabase
                .FindAssets( "t:BundledAssetGroupSchema" )
                .Select( c => AssetDatabase.GUIDToAssetPath( c ) )
                .Select( c => AssetDatabase.LoadAssetAtPath<BundledAssetGroupSchema>( c ) )
            ;

        var settings = AddressableUtils.GetSettings();

        foreach ( var n in list )
        {
            UpdatePath( settings, n );
        }
    }

    private static void UpdatePath
    (
        AddressableAssetSettings settings,
        BundledAssetGroupSchema  schema
    )
    {
        schema.BuildPath.SetVariableByName( settings, "BuildTarget" );
        schema.LoadPath.SetVariableByName( settings, "BuildTarget" );
        //schema.BuildPath.SetVariableByName( settings, AddressableAssetSettings.kLocalBuildPath );
        //schema.LoadPath.SetVariableByName( settings, AddressableAssetSettings.kLocalLoadPath );
        //schema.BuildPath.SetVariableByName( settings, AddressableAssetSettings.kRemoteBuildPath );
        //schema.LoadPath.SetVariableByName( settings, AddressableAssetSettings.kRemoteLoadPath );
    }
}