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