Setup

Install UniFlux

https://github.com/xavierarpa/UniFlux.git
  • You can install via openupm CLI

openupm add com.xavierarpa.uniflux
  • You can install via npm

npm i com.xavierarpa.uniflux

Generate your Scritps

using UniFlux;
using UnityEngine;

public class Test : MonoFlux
{
    private void Start()
    {
        // Allows you to call any method subscribe with "0" Key
        "0".Dispatch();
    }
    [MethodFlux("0")] private void Tester()
    {
        Debug.Log("Hello world");
    }
}
using UniFlux;
using UnityEngine;

public class Test_2 : MonoFlux
{
    [MethodFlux("0")] private void Tester_2()
    {
        Debug.Log("Hello world 2");
    }
}

You can put both in a scene and see if they both receive the event

That's all !

Here another sample making subscriptions manually

using UniFlux;
public class Test : MonoBehaviour
{
  private void Start()
  {
    "KEY".Dispatch();
  }
  private void OnEnable() 
  { 
      "KEY".Store(true, OnExampleMethodIsCalled)
  }
  private void OnDisable() 
  { 
      "KEY".Store(false, OnExampleMethodIsCalled)
  }
  private void OnExampleMethodIsCalled()
  {
    Debug.Log("Hello World");
  }
}

public class Test_2 : MonoBehaviour
{
    private void OnEnable() 
    { 
      "KEY".Store(true, Tester_2)
    }
    private void OnDisable() 
    { 
      "KEY".Store(false, Tester_2)
    }
    private void Tester_2()
    {
      Debug.Log("Hello world 2");
    }
}

Last updated