-
-
Save todorok1/9b3995bcabb9fa5eb794e6d5142220a8 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第30回 ゲーム内の敵キャラクターのデータを管理するクラス
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using UnityEngine.AddressableAssets; | |
| using UnityEngine.ResourceManagement.AsyncOperations; | |
| namespace SimpleRpg | |
| { | |
| /// <summary> | |
| /// ゲーム内の敵キャラクターのデータを管理するクラスです。 | |
| /// </summary> | |
| public static class EnemyDataManager | |
| { | |
| /// <summary> | |
| /// 読み込んだ敵キャラクターのデータの一覧です。 | |
| /// </summary> | |
| static List<EnemyData> _enemyData = new(); | |
| /// <summary> | |
| /// 敵キャラクターのデータをロードします。 | |
| /// </summary> | |
| public static async void LoadEnemyData() | |
| { | |
| AsyncOperationHandle<IList<EnemyData>> handle = Addressables.LoadAssetsAsync<EnemyData>(AddressablesLabels.Enemy, null); | |
| await handle.Task; | |
| _enemyData = new List<EnemyData>(handle.Result); | |
| handle.Release(); | |
| } | |
| /// <summary> | |
| /// IDから敵キャラクターのデータを取得します。 | |
| /// </summary> | |
| public static EnemyData GetEnemyDataById(int enemyId) | |
| { | |
| return _enemyData.Find(enemy => enemy.enemyId == enemyId); | |
| } | |
| /// <summary> | |
| /// 全てのデータを取得します。 | |
| /// </summary> | |
| public static List<EnemyData> GetAllData() | |
| { | |
| return _enemyData; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment