-
-
Save todorok1/6ae892f99f1d1d553d330203ccfa6279 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第112回 セーブデータとフラグ情報をやりとりするクラス
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 UnityEngine; | |
| using System; | |
| namespace SimpleRpg | |
| { | |
| /// <summary> | |
| /// セーブデータとフラグ情報をやりとりするクラスです。 | |
| /// </summary> | |
| [Serializable] | |
| public class SaveInfoFlagController : MonoBehaviour | |
| { | |
| /// <summary> | |
| /// セーブデータ用のフラグ情報を返します。 | |
| /// </summary> | |
| public SaveInfoFlag GetSaveInfoFlag() | |
| { | |
| SaveInfoFlag saveInfoFlag = new() | |
| { | |
| flagStates = FlagManager.Instance.GetFlagStateList() | |
| }; | |
| return saveInfoFlag; | |
| } | |
| /// <summary> | |
| /// セーブデータから読み取ったフラグ情報をセットします。 | |
| /// </summary> | |
| /// <param name="saveInfoFlag">フラグ情報</param> | |
| public void SetSaveInfoFlag(SaveInfoFlag saveInfoFlag) | |
| { | |
| FlagManager.Instance.InitializeFlagList(); | |
| if (saveInfoFlag == null) | |
| { | |
| SimpleLogger.Instance.LogWarning("セーブデータ内のフラグ情報がnullです。"); | |
| return; | |
| } | |
| if (saveInfoFlag.flagStates == null) | |
| { | |
| SimpleLogger.Instance.LogWarning("フラグ情報のフラグリストがnullです。"); | |
| return; | |
| } | |
| foreach (var flagState in saveInfoFlag.flagStates) | |
| { | |
| if (flagState == null || string.IsNullOrEmpty(flagState.flagName)) | |
| { | |
| SimpleLogger.Instance.LogWarning("フラグ情報のフラグ名がnullまたは空です。"); | |
| continue; | |
| } | |
| FlagManager.Instance.SetFlagState(flagState.flagName, flagState.state); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment