LoginSignup
2
1

More than 3 years have passed since last update.

【Addressable Asset System】BuildPath/LoadPathのRemote/Localをスクリプト変更する処理覚え書き

Last updated at Posted at 2021-01-13

コード

    static void ChangeAssetGroupSetting(bool toRemote)
    {
        // カタログを生成するかどうかのフラグ切り替え
        AddressableAssetSettingsDefaultObject.Settings.BuildRemoteCatalog = toRemote;

        // 設定したAddressable Groupを全て取得
        foreach (var group in AddressableAssetSettingsDefaultObject.Settings.groups)
        {
            if (group.Default || group.ReadOnly)
            {
                // Built in DataとDefaultグループは処理対象から除外
                Debug.Log($"Skip: { group.Name }");
                continue;
            }

            Debug.Log($"Update: { group.Name }");
            var pathSetting = group.GetSchema<BundledAssetGroupSchema>();
            if (pathSetting != null)
            {
                if (toRemote)
                {
                    // サーバーからDLする設定に変更
                    pathSetting.BuildPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kRemoteBuildPath);
                    pathSetting.LoadPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kRemoteLoadPath);
                }
                else
                {
                    // ローカルに組み込む設定に変更
                    pathSetting.BuildPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kLocalBuildPath);
                    pathSetting.LoadPath.SetVariableByName(AddressableAssetSettingsDefaultObject.Settings, AddressableAssetSettings.kLocalLoadPath);
                }
            }
        }
    }

一言

正直、処理を書くよりも仕様を調べることの方が疲れた。
公式でサンプル乗っけといてほしい。

もし公式マニュアル・リファレンス探してる人がいる場合はこちら(英語)
https://docs.unity.cn/Packages/com.unity.addressables@1.9/manual

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1