Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

SystemsExecutor

pointcache edited this page Jan 15, 2017 · 3 revisions

This class sends ordered alternative Magic methods, ensuring that the execution order goes from top to bottom, for all its children. This is used on Systems stack.

It uses internal configs UpdateAllowed flag, setting it to false will lead to all gameplay systems being halt. This will effectively pause the game (but not the physics engine) if your systems use only Ordered events.

OrderedFixedUdpate (as unity FixedUpdate) always runs before Update if they run in the same frame.

public class SystemsExecutor : MonoBehaviour
{
    void OnEnable()
    {
        sendMessageRecursive("OrderedOnEnable", transform);
    }
    void FixedUpdate()
    {
        if(Pool<InternalConfig>.First.UpdateAllowed)
            sendMessageRecursive("OrderedFixedUpdate", transform);
    }

    void Update()
    {
        if(Pool<InternalConfig>.First.UpdateAllowed)
            sendMessageRecursive("OrderedUpdate", transform);
    }

    void sendMessageRecursive(string message, Transform tr)
    {
        int count = tr.childCount;
        for (int i = 0; i < count; i++)
        {
            tr.GetChild(i).SendMessage(message, SendMessageOptions.DontRequireReceiver);
            if (count > 0)
                sendMessageRecursive(message, tr.GetChild(i));
        }
    }
}
Clone this wiki locally