/// <summary> /// Add this activity to the scheduler. /// </summary> /// <param name="activity">The activity to be added.</param> /// <param name="processLast"> /// Specifies whether the activity should be run last. /// </param> /// <remarks> /// Adding an activity schedules that activity to run at some point in the /// future. /// <para> /// Sometimes it's useful to make sure that an activity is run after all other /// activities have been run. To do this set processLast to true when adding the /// activity. /// </para> /// </remarks> public virtual void AddActivity(PActivity activity, bool processLast) { if (activities.Contains(activity)) { return; } activitiesChanged = true; if (processLast) { activities.Insert(0, activity); } else { activities.Add(activity); } activity.ActivityScheduler = this; if (!ActivityTimer.Enabled) { StartActivityTimer(); } }
/// <summary> /// Process all scheduled activities for the given time. Each activity is /// given one "step", equivalent to one frame of animation. /// </summary> /// <param name="currentTime">The time for which to process each activity.</param> public virtual void ProcessActivities(long currentTime) { int size = activities.Count; if (size > 0) { processingActivities.Clear(); processingActivities.AddRange(activities); for (int i = size - 1; i >= 0; i--) { PActivity each = processingActivities[i]; each.ProcessStep(currentTime); } } }
/// <summary> /// Remove this activity from the scheduler. /// </summary> /// <param name="activity">The activity to be removed.</param> /// <remarks> /// Once an activity has been removed from the scheduler, it will no longer be /// run. /// </remarks> public virtual void RemoveActivity(PActivity activity) { if (!activities.Contains(activity)) { return; } activitiesChanged = true; activities.Remove(activity); if (activities.Count == 0) { StopActivityTimer(); } }
/// <summary> /// Add this activity to the scheduler. /// </summary> /// <param name="activity">The activity to be added.</param> /// <remarks> /// Adding an activity schedules that activity to run at some point in the /// future. /// </remarks> public virtual void AddActivity(PActivity activity) { AddActivity(activity, false); }
/// <summary> /// Schedules this activity to start after the first activity has finished. /// </summary> /// <param name="first">The activity to start after.</param> /// <remarks> /// Note that no link is created between these activities, if the startTime or duration /// of the first activity is later changed this activities start time will not be updated /// to reflect that change. /// </remarks> public virtual void StartAfter(PActivity first) { StartTime = first.StartTime + first.Duration; }