Unity/Addressable/複数ロード
提供: 初心者エンジニアの簡易メモ
準備
- Unityメインメニュー/Window/Asset Management/Addressables/Groupsを選択
- ロードしたいオブジェクトのlabels部分にラベル名を追加(例:"TestLabel")
サンプル
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.UI; public class AssetLabelsLoadScene : MonoBehaviour { [SerializeField] Button loadButton; [SerializeField] GameObject canvas; GameObject instance; void Start() { loadButton.onClick.AddListener(() => { if (instance == null) { StartCoroutine(Load()); } }); } IList<GameObject> list; IEnumerator Load() { var handle = Addressables.LoadAssetsAsync<GameObject>("TestLabel", null); yield return handle; if (handle.Status == AsyncOperationStatus.Succeeded) { list = handle.Result; foreach (var value in list) { Debug.Log(value.name); } } } }