以下の内容はhttps://baba-s.hatenablog.com/entry/2019/09/02/083000より取得しました。


【Unity】シンプルなメッセージバス「BasicEventBus」紹介

はじめに

「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( "プレイヤーが復活" );
    }
}



以上の内容はhttps://baba-s.hatenablog.com/entry/2019/09/02/083000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14