-
-
Save todorok1/fad591811b33ac9aa1ebdb5afd44730b to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第86回 イベントのまとまりを制御するクラス
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; | |
| namespace SimpleRpg | |
| { | |
| /// <summary> | |
| /// イベントのまとまりを制御するクラスです。 | |
| /// </summary> | |
| public class EventFileData : MonoBehaviour | |
| { | |
| /// <summary> | |
| /// イベントページのリストです。 | |
| /// </summary> | |
| List<EventPage> _eventPages; | |
| /// <summary> | |
| /// 対象のイベントページの処理を開始します。 | |
| /// </summary> | |
| /// <param name="rpgEventTrigger">イベントの開始方法</param> | |
| public void ExecuteEvent(RpgEventTrigger rpgEventTrigger) | |
| { | |
| SetUpEventPages(); | |
| var targetPage = GetEventPage(rpgEventTrigger); | |
| if (targetPage == null) | |
| { | |
| SimpleLogger.Instance.Log($"実行可能なイベントページが見つかりませんでした。イベントのトリガー : {rpgEventTrigger}"); | |
| return; | |
| } | |
| targetPage.StartEvent(this); | |
| } | |
| /// <summary> | |
| /// イベントページのリストをセットアップします。 | |
| /// </summary> | |
| void SetUpEventPages() | |
| { | |
| if (_eventPages == null) | |
| { | |
| var pages = GetComponentsInChildren<EventPage>(); | |
| _eventPages = new List<EventPage>(pages); | |
| } | |
| } | |
| /// <summary> | |
| /// 実行対象のイベントページを取得します。 | |
| /// </summary> | |
| /// <param name="rpgEventTrigger">イベントの開始方法</param> | |
| EventPage GetEventPage(RpgEventTrigger rpgEventTrigger) | |
| { | |
| EventPage targetPage = null; | |
| // Hierarchyウィンドウで下から順にイベントページを確認し、条件に合致する最初のページを返します。 | |
| for (int i = _eventPages.Count - 1; i >= 0; i--) | |
| { | |
| var page = _eventPages[i]; | |
| if (page == null) | |
| { | |
| SimpleLogger.Instance.LogWarning("イベントページがnullです。"); | |
| continue; | |
| } | |
| if (page.IsMatchedConditions() && page.IsMatchedTrigger(rpgEventTrigger)) | |
| { | |
| targetPage = page; | |
| break; | |
| } | |
| } | |
| return targetPage; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment