facebook twitter hatena line email

「Unity/Addressable」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(Addressableでビルドしたものを、Addressableを取得)
(同じ利用者による、間の41版が非表示)
行1: 行1:
==Addressableとは==
+
[[Unity/Addressable/基本]]
外部サーバーで使えるResources
+
  
==インストール==
+
[[Unity/Addressable/ローカルサーバー]]
#Unityメインメニュー/Window/Package Manager/Unity Registryが選択"addressable"を検索
+
#Addressablesをinstall
+
  
==Addressableの作り方==
+
[[Unity/Addressable/シーンロード]]
#例として、プレハブを作るのでAssetsの下にResourcesフォルダがなければ作る。
+
#適当にプレハブをAssets/Resourcesの下につくる。(例:ButtonGroup)
+
#inspectorにaddressableのチェックがあるので、チェックを付ける
+
#チェックをつけると、addressableのpathが生成される(例:ButtonGroup)
+
#Resources_movedに勝手に移動される。もしくは、作られたファイルをResources以外のdirに入れる。
+
#以下SampleScene.csをシーンに連携する
+
 
+
<pre>
+
using System.Collections;
+
using UnityEngine;
+
using UnityEngine.AddressableAssets;
+
using UnityEngine.ResourceManagement.AsyncOperations;
+
public class SampleScene : MonoBehaviour
+
{
+
    void Start()
+
    {
+
        StartCoroutine(Load());
+
    }
+
    IEnumerator Load()
+
    {
+
        // プレハブ:GameObject、画像:Image、スプライト:Sprite
+
        var handle = Addressables.LoadAssetAsync<GameObject>("ButtonGroup");
+
        yield return handle;
+
        if (handle.Status == AsyncOperationStatus.Succeeded)
+
        {
+
            var instance = Instantiate(handle.Result, GameObject.Find("Canvas").transform);
+
        }
+
    }
+
}
+
</pre>
+
 
+
プレビュー実行すると、シーンのCanvasの下に、Addressableで作った、プレハブが表示される。
+
 
+
==="Exception encountered in operation CompletedOperation, status=Failed, result= : Exception of type"エラーが出るとき===
+
Addressable化したもののパスが合ってるか確認、PlayModeScript(後述)が、サーバーから取得するようになってないか。
+
 
+
==設定確認==
+
#Unityメインメニュー/Window/Addressable/Groups/Profile/ManageProfiles
+
<pre>
+
BuildTarget:[UnityEditor.EditorUserBuildSettings.activeBuildTarget]
+
LocalBuildPath:[UnityEngine.AddressableAssets.Addressables.BuildPath]/[BuildTarget]
+
LocalLoadPath:{UnityEngine.AddressableAssets.Addressables.RuntimePath}/[BuildTarget]
+
RemoteBuildPath:ServerData/[BuildTarget]
+
RemoteLoadPath:http://localhost/[BuildTarget]
+
</pre>
+
 
+
===設定変更===
+
設定変更したい場合は、
+
#Unityメインメニュー/Window/Addressable/Groups/ManageProfiles/Create/NewProfileを選択し、
+
#各項目を入力していく
+
 
+
==プレイモード選択==
+
#Unityメインメニュー/Window/Addressable/Groups/PlayModeScriptを選択
+
 
+
*Use Asset Database (fastest):Unity内のアセットから
+
*Simulate Groups (Advanced):依存関係を分析して取得
+
*Use Existing Build(requires built groups):パックプレイモードで、サーバーから取得
+
 
+
==Addressableでビルドしたものを、Addressableを取得==
+
#上記のPlayModeScriptを"Use Existing Build"へ
+
#Addressableをビルドする(Unityメインメニュー/Window/Asset Management/Addressables/Groups/Build/New Build/Default Build Script
+
#プレビュー実行
+
 
+
ちなみにBuildファイルは
+
Library/com.unity.addressables/aa/WebGL/WebGL/
+
 
+
とか、
+
 
+
ServerData/WebGL
+
 
+
とかにできる。
+
 
+
==Addressableの削除==
+
#Unityメインメニュー/Window/Asset Management/Addressables/Groups
+
#Build/CleanBuild/AllとContent BuildersとBuild Pipeline Cache
+
 
+
==Addressableの再生成==
+
#Unityメインメニュー/Window/Asset Management/Addressables/Groups
+
#Build/New Build/Default Build Script
+
 
+
プロジェクト以下/ServerData/WebGL/とかにできる
+
<pre>
+
ServerData/WebGL/catalog_v1.0.hash
+
ServerData/WebGL/catalog_v1.0.json
+
ServerData/WebGL/localization-assets-shared_assets_all.bundle
+
ServerData/WebGL/localization-string-tables-chinese(traditional)(zh-tw)_assets_all.bundle
+
ServerData/WebGL/localization-string-tables-english(unitedstates)(en-us)_assets_all.bundle
+
ServerData/WebGL/localization-string-tables-japanese(japan)(ja-jp)_assets_all.bundle
+
</pre>
+
 
+
==ビルド時のパスを確認==
+
#Assets/AddressableAssetsData/AssetGroups/Default Local Group
+
#BuildPathとLoadPathに何を設定してるか確認。
+
 
+
*LocalBuildPath:Library/com.unity.addressables/aa/WebGL/WebGL
+
*LocalLoadPath:{UnityEngine.AddressableAssets.Addressables.RuntimePath}/WebGL
+
*RemoteBuildPath:ServerData/WebGL
+
*RemoteLoadPath:http://localhost/WebGL
+
 
+
==AddressablesのRemoteLoadPathの変更==
+
#Window/Asset Management/Addressables/Groups
+
#Profile:WebGLを選択
+
#ManageProfiles
+
#RemoteLoadPathを変更する
+
 
+
https://qiita.com/tetr4lab/items/1b26755089820b041b4f
+
 
+
==参考==
+
https://robamemo.hatenablog.com/entry/2021/01/08/195415
+
 
+
https://light11.hatenadiary.com/entry/2019/12/26/225232
+
 
+
https://light11.hatenadiary.com/entry/2020/07/29/202755
+

2022年9月7日 (水) 16:53時点における版

Unity/Addressable/基本

Unity/Addressable/ローカルサーバー

Unity/Addressable/シーンロード