using System.Collections; using System.Collections.Generic; using UnityEngine; public class LogicEngine : SingletonMonobehaviour { List logicUpdates = new List(); public void Register(LogicUpdate logicUpdate) { if (!logicUpdates.Contains(logicUpdate)) { logicUpdates.Add(logicUpdate); } } public void UnRegister(LogicUpdate logicUpdate) { if (logicUpdates.Contains(logicUpdate)) { logicUpdates.Remove(logicUpdate); } } void Update() { for (var i = logicUpdates.Count - 1; i >= 0; i--) { var item = logicUpdates[i]; if (item.destroyDirty) { logicUpdates.RemoveAt(i); } else { try { item.Update(); } catch (System.Exception ex) { DebugEx.LogError(ex); } } } } }