/// <summary> /// Internal method which adds a new event with three arguments which will be executed in the future. /// </summary> /// <param name="delay">The delay from the current time to execute the event.</param> /// <param name="invokeLocation">Specifies where the event shoud be invoked.</param> /// <param name="action">The delegate to execute after the specified delay.</param> /// <param name="value1">The first value to use when invoking the delegate.</param> /// <param name="value2">The second value to use when invoking the delegate.</param> /// <param name="value3">The third value to use when invoking the delegate.</param> /// <returns>The ScheduledEventBase instance, useful if the event should be cancelled.</returns> private ScheduledEventBase AddEventInternal <T, U, V>(float delay, ScheduledEventBase.InvokeLocation invokeLocation, Action <T, U, V> action, T value1, U value2, V value3) { if (delay == 0) { action(value1, value2, value3); return(null); } else { var scheduledEvent = ObjectPool.Get <ScheduledEvent <T, U, V> >(); // A delay of -1 indicates that the event reoccurs forever and must manually be cancelled. scheduledEvent.Initialize((delay == -1 ? -1 : Time.time + delay), invokeLocation, action, value1, value2, value3); AddScheduledEvent(scheduledEvent); return(scheduledEvent); } }
/// <summary> /// Internal method which adds a new event to be executed in the future. /// </summary> /// <param name="delay">The delay from the current time to execute the event.</param> /// <param name="invokeLocation">Specifies where the event shoud be invoked.</param> /// <param name="action">The delegate to execute after the specified delay.</param> /// <returns>The ScheduledEventBase instance, useful if the event should be cancelled.</returns> private ScheduledEventBase AddEventInternal(float delay, ScheduledEventBase.InvokeLocation invokeLocation, Action action) { // Don't add the event if the game hasn't started. if (enabled == false) { return(null); } if (delay == 0) { action(); return(null); } else { var scheduledEvent = ObjectPool.Get <ScheduledEvent>(); // A delay of -1 indicates that the event reoccurs forever and must manually be cancelled. scheduledEvent.Initialize((delay == -1 ? -1 : Time.time + delay), invokeLocation, action); AddScheduledEvent(scheduledEvent); return(scheduledEvent); } }
/// <summary> /// Removes the active event at the specified index. /// </summary> /// <param name="index">The index of the active event that should be removed.</param> /// <param name="location">The location that the event is invoked.</param> private void RemoveActiveEvent(int index, ScheduledEventBase.InvokeLocation location) { if (location == ScheduledEventBase.InvokeLocation.Update) { m_ActiveUpdateEvents[index].Active = false; for (int i = index + 1; i < m_ActiveUpdateEventCount; ++i) { m_ActiveUpdateEvents[i - 1] = m_ActiveUpdateEvents[i]; } m_ActiveUpdateEventCount--; m_ActiveUpdateEvents[m_ActiveUpdateEventCount] = null; } else { m_ActiveFixedUpdateEvents[index].Active = false; for (int i = index + 1; i < m_ActiveFixedUpdateEventCount; ++i) { m_ActiveFixedUpdateEvents[i - 1] = m_ActiveFixedUpdateEvents[i]; } m_ActiveFixedUpdateEventCount--; m_ActiveFixedUpdateEvents[m_ActiveFixedUpdateEventCount] = null; } }