Skip to content
This repository was 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.

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