Exemple #1
0
        /// <summary>
        /// Adds a custom update loop.
        /// </summary>
        /// <param name="updateLoop">The custom update loop implementation.</param>
        /// <param name="parentLoop">Which Unity update loop should this be run under?</param>
        /// <param name="priority">A priority that decides whether this update loop runs before or after other custom update loops.</param>
        public static void AddCustomUpdateLoop(ICustomUpdateLoop updateLoop, UpdateLoop parentLoop = UpdateLoop.Update, int priority = 0)
        {
            if (_idToUpdateLoop == null)
            {
                _idToUpdateLoop      = new Dictionary <int, ICustomUpdateLoop>(4);
                _idToUnityUpdateLoop = new Dictionary <int, UpdateLoop>(4);
                _customUpdateLoops   = new Dictionary <int, PrioritizedList <ICustomUpdateLoop> >(3);
            }

            PrioritizedList <ICustomUpdateLoop> customLoops;

            if (!_customUpdateLoops.TryGetValue((int)parentLoop, out customLoops))
            {
                _customUpdateLoops[(int)parentLoop] = customLoops = new PrioritizedList <ICustomUpdateLoop>(4);
            }

            var id = updateLoop.Event.Id;

            if (_idToUpdateLoop.ContainsKey(id))
            {
                Debug.LogErrorFormat("An update loop with ID '{0}' is already registered.", id);
                return;
            }

            _idToUpdateLoop[id]      = updateLoop;
            _idToUnityUpdateLoop[id] = parentLoop;
            customLoops.Add(updateLoop, priority);
        }
Exemple #2
0
        /// <summary>
        /// Removes a custom update loop.
        /// </summary>
        /// <param name="updateLoop">The update loop to remove.</param>
        public static void RemoveCustomUpdateLoop(ICustomUpdateLoop updateLoop)
        {
            if (_customUpdateLoops == null)
            {
                return;
            }

            var id = updateLoop.Event.Id;

            UpdateLoop unityUpdateLoop;

            if (!_idToUnityUpdateLoop.TryGetValue(id, out unityUpdateLoop))
            {
                return;
            }

            PrioritizedList <ICustomUpdateLoop> customLoops;

            if (!_customUpdateLoops.TryGetValue((int)unityUpdateLoop, out customLoops))
            {
                return;
            }


            customLoops.Remove(updateLoop);
            _idToUpdateLoop.Remove(id);
            _idToUnityUpdateLoop.Remove(id);
        }