/// <summary> /// Called when the component is enabled. /// </summary> protected virtual void OnEnable() { // interface references aren't serialized when unity hot-reloads if (Application.isEditor) { // ReSharper disable SuspiciousTypeConversion.Global if (_updateable == null) { _updateable = this as IUpdateable; } if (_lateUpdateable == null) { _lateUpdateable = this as ILateUpdateable; } if (_fixedUpdateable == null) { _fixedUpdateable = this as IFixedUpdateable; } if (_customUpdateable == null) { _customUpdateable = this as ICustomUpdateable; } // ReSharper restore SuspiciousTypeConversion.Global } // We don't want Update calls before Start has been called. if (_startWasCalled) { StartListening(); } }
/// <summary> /// Determine if the specified lateUpdateable is being registered. /// </summary> public static bool IsRegistered(ILateUpdateable lateUpdateable) { for (int i = 0; i < _lateUpdateablesList.Count; i++) { if (lateUpdateable == _lateUpdateablesList [i]) { return(true); } } return(false); }
/// <summary> /// Unregister the specified LateUpdate Call. /// </summary> public static void UnregisterLateUpdate(ILateUpdateable lateUpdateable) { if (lateUpdateable == null) { throw new ArgumentNullException(); } else { _lateUpdateablesList.Remove(lateUpdateable); } }
/// <summary> /// Register the specified LateUpdate Call. /// Can invoke the sort by setting the autoSort as true (default is false). /// </summary> public static void RegisterLateUpdate(ILateUpdateable lateUpdateable, bool autoSort = false) { if (lateUpdateable == null) { throw new ArgumentNullException(); } else { _lateUpdateablesList.Add(lateUpdateable); } if (autoSort) { Sort(); } }
/// <summary> /// Start is called on the frame when a script is enabled just before any of the Update methods is called the first time. /// </summary> protected virtual void Start() { // ReSharper disable SuspiciousTypeConversion.Global _updateable = this as IUpdateable; _lateUpdateable = this as ILateUpdateable; _fixedUpdateable = this as IFixedUpdateable; // ReSharper restore SuspiciousTypeConversion.Global if (_updateable == null && _lateUpdateable == null && _fixedUpdateable == null) { Debug.LogWarning("This component doesn't implement any update interfaces."); } _startWasCalled = true; StartListening(); }