Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created June 30, 2025 08:03
Show Gist options
  • Select an option

  • Save todorok1/ba9ad3531c6a38359d5fcceaee2da346 to your computer and use it in GitHub Desktop.

Select an option

Save todorok1/ba9ad3531c6a38359d5fcceaee2da346 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第90回 メッセージに関するイベントを処理するクラス
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SimpleRpg
{
/// <summary>
/// メッセージに関するイベントを処理するクラスです。
/// </summary>
public class EventProcessMessage : EventProcessBase, IMessageCallback
{
/// <summary>
/// このプロセスの終了後にメッセージウィンドウを開いたままにするかどうかのフラグです。
/// </summary>
[SerializeField]
bool _keepWindowOpen = false;
/// <summary>
/// 表示するメッセージです。
/// 1つの要素につき1画面のメッセージを表示します。
/// </summary>
[SerializeField][TextArea]
List<string> _messages;
/// <summary>
/// マップ上で表示するメッセージウィンドウを制御するクラスへの参照です。
/// </summary>
MapMessageWindowController _messageWindowController;
/// <summary>
/// イベントの処理を実行します。
/// </summary>
public override void Execute()
{
SetUpReference();
if (_messageWindowController == null)
{
SimpleLogger.Instance.LogError("MapMessageWindowControllerが見つかりません。");
CallNextProcess();
return;
}
StartCoroutine(ShowMessageProcess());
}
/// <summary>
/// メッセージのコントローラへの参照をセットします。
/// </summary>
void SetUpReference()
{
_messageWindowController = FindAnyObjectByType<MapMessageWindowController>();
}
/// <summary>
/// メッセージを表示します。
/// </summary>
IEnumerator ShowMessageProcess()
{
_messageWindowController.SetUpController(this);
_messageWindowController.ShowPager();
_messageWindowController.ShowWindow();
foreach (var message in _messages)
{
_messageWindowController.ShowGeneralMessage(message, 0f);
// キー入力を待ちます。
_messageWindowController.StartKeyWait();
while (_messageWindowController.IsWaitingKeyInput)
{
yield return null;
}
}
if (!_keepWindowOpen)
{
_messageWindowController.HideWindow();
_messageWindowController.HidePager();
}
CallNextProcess();
}
/// <summary>
/// メッセージの表示が完了したことを通知するコールバックです。
/// </summary>
public void OnFinishedShowMessage()
{
}
/// <summary>
/// 別のプロセスからメッセージを設定します。
/// </summary>
public void SetMessageFromProcess(List<string> messages)
{
_messages = messages;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment