Skip to content

BaseMono

DucNV_2000 edited this page May 16, 2024 · 1 revision

After inheriting from BaseMono

  • Tick() Same Update()
  • LateTick() Same LateUpdate
  • FixedTick() Same FixedUpdate

All class that inherit from BaseMono when called Tick (LateTick or FixedTick) will be updated at only one MonoGlobal (inherited from Monobehaviour).

  • Note: Because BaseMono register Tick() at OnEnable(), classes that inherit from BaseMono when needing to use OnEnable() and update with Tick() are required to inherit OnEnable() from BaseMono.

  • Demo correct usage (Tick() will work)

public class Test : BaseMono
{
    public GameObject popup;

    public override void OnEnable()
    {
        base.OnEnable();
        popup.SetActive(true);
    }

    public override void Tick()
    {
        base.Tick();
        Debug.Log("Tick Update");
    }
}
  • Demo incorrect usage (Tick() will not work)
public class Test : BaseMono
{
    public GameObject popup;

    public void OnEnable()
    {
        popup.SetActive(true);
    }

    public override void Tick()
    {
        base.Tick();
        Debug.Log("Tick Update");
    }
}
  • If you do not inherit from BaseMono but still want to perform updates on MonoGlobal, you can register according to the example below
public class Player : MonoBehaviour
{
    private void Awake()
    {
        App.SubTick(CustomUpdate);
        App.SubFixedTick(CustomFixedUpdate);
        App.SubLateTick(CustomLateUpdate);
    }

    private void OnDisable()
    {
        App.UnSubTick(CustomUpdate);
        App.UnSubFixedTick(CustomFixedUpdate);
        App.UnSubLateTick(CustomLateUpdate);
    }

    private void CustomUpdate()
    {
        Debug.Log("Update");
    }

    private void CustomFixedUpdate()
    {
        Debug.Log("Fixed Update");
    }

    private void CustomLateUpdate()
    {
        Debug.Log("Late Update");
    }
}
Clone this wiki locally