コード例 #1
0
        /// <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();
            }
        }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
 /// <summary>
 /// Unregister the specified LateUpdate Call.
 /// </summary>
 public static void UnregisterLateUpdate(ILateUpdateable lateUpdateable)
 {
     if (lateUpdateable == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         _lateUpdateablesList.Remove(lateUpdateable);
     }
 }
コード例 #4
0
 /// <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();
     }
 }
コード例 #5
0
        /// <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();
        }