internal void Start() { while (startQueue.Count > 0) { ScriptingComponent sc = startQueue.Dequeue(); var act = GetMessage(sc, "Start"); if (act != null) { act.Invoke(); } var mess = GetMessage(sc, "Update"); if (mess != null) { updates.Add(new Message(sc, mess)); } mess = GetMessage(sc, "PreRender"); if (mess != null) { preRender.Add(new Message(sc, mess)); } mess = GetMessage(sc, "PostRender"); if (mess != null) { postRender.Add(new Message(sc, mess)); } mess = GetMessage(sc, "OnDestroy"); if (mess != null) { onDestroy.Add(new Message(sc, mess)); } } }
Action GetMessage(ScriptingComponent sc, string name) { MethodInfo method = sc.Type.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance); Action message = null; if (method != null && method.GetGenericArguments().Length == 0) { message = (Action)Delegate.CreateDelegate(typeof(Action), sc, method); } return(message); }
internal void Awake() { while (awakeQueue.Count > 0) { ScriptingComponent sc = awakeQueue.Dequeue(); var act = GetMessage(sc, "Awake"); if (act != null) { act.Invoke(); } sc.IsInstalized = true; startQueue.Enqueue(sc); } }
public Message(ScriptingComponent sc, Action method) { Method = method; ScriptingObject = sc; }
internal void RemoveScript(ScriptingComponent sc) { scripts.Remove(sc); updates.RemoveAll((m) => m.ScriptingObject == sc); preRender.RemoveAll((m) => m.ScriptingObject == sc); }
internal void AddScript(ScriptingComponent sc) { scripts.Add(sc); awakeQueue.Enqueue(sc); }