はじめに
「BasicEventBus」を Unity プロジェクトに導入することで
シンプルなメッセージバスを使用できるようになります
使用例
送信側のスクリプト
using pEventBus; using UnityEngine; public struct PlayerRespawnSignal : IEvent { } public class Player : MonoBehaviour { private void Start() { EventBus<PlayerRespawnSignal>.Raise( new PlayerRespawnSignal() ); } }
受信側のスクリプト
using pEventBus; using UnityEngine; public class GameScene : MonoBehaviour, IEventReceiver<PlayerRespawnSignal> { private void OnEnable() { EventBus.Register( this ); } private void OnDisable() { EventBus.UnRegister( this ); } public void OnEvent( PlayerRespawnSignal data ) { Debug.Log( "プレイヤーが復活" ); } }