Пример #1
0
        /// <summary>
        /// Schedules a task so it's executed after some time
        /// </summary>
        /// <param name="action">The action to be executed</param>
        /// <param name="after">The time (in seconds) to wait before executing the task</param>
        /// <param name="updateType">Optional: The update method this task should use (Update/LateUpdate/FixedUpdate)</param>
        /// <returns>The STask. You can save this task to stop it before it's finished and to subscribe to events such us OnComplete</returns>
        public static DoTask Do(SAction action, float after, UpdateType updateType = UpdateType.Update)
        {
            STaskSettings settings = new STaskSettings()
            {
                action = action,
                delay  = after,
            };

            DoTask task = new DoTask(settings);

            AddTask(task, updateType);
            return(task);
        }
Пример #2
0
        /// <summary>
        /// Performs a task after a given number of frames has passed
        /// </summary>
        /// <param name="action">The action to be executed</param>
        /// <param name="frames">The number of frames to wait</param>
        /// <param name="startAfter">Optional: The time (in seconds) to wait before starting to count the frames</param>
        /// <param name="updateType">Optional: The update method this task should use (Update/LateUpdate/FixedUpdate)</param>
        /// <returns>The STask. You can save this task to stop it before it's finished and to subscribe to events such us OnComplete</returns>
        public static DoAfterFramesTask DoAfterFrames(SAction action, int frames, float startAfter = 0, UpdateType updateType = UpdateType.Update)
        {
            STaskSettings settings = new STaskSettings()
            {
                action       = action,
                targetFrames = frames,
                delay        = startAfter,
            };

            DoAfterFramesTask task = new DoAfterFramesTask(settings);

            AddTask(task, updateType);
            return(task);
        }
Пример #3
0
        /// <summary>
        /// Performs a task when a condition is met
        /// </summary>
        /// <param name="action">The action to be executed</param>
        /// <param name="condition">The condition for this task to stop</param>
        /// <param name="startAfter">Optional: The time (in seconds) to wait before starting the task</param>
        /// <param name="updateType">Optional: The update method this task should use (Update/LateUpdate/FixedUpdate)</param>
        /// <returns>The STask. You can save this task to stop it before it's finished and to subscribe to events such us OnComplete</returns>
        public static DoWhenTask DoWhen(SAction action, SCondition condition, float startAfter = 0, UpdateType updateType = UpdateType.Update)
        {
            STaskSettings settings = new STaskSettings()
            {
                action    = action,
                condition = condition,
                delay     = startAfter,
            };

            DoWhenTask task = new DoWhenTask(settings);

            AddTask(task, updateType);
            return(task);
        }
Пример #4
0
        /// <summary>
        /// Performs a task every few seconds until manually stopped
        /// </summary>
        /// <param name="action">The action to be executed</param>
        /// <param name="every">The time (in seconds) to wait between executions</param>
        /// <param name="startAfter">Optional: The time (in seconds) to wait before starting the task</param>
        /// <param name="updateType">Optional: The update method this task should use (Update/LateUpdate/FixedUpdate)</param>
        /// <returns>The STask. You can save this task to stop it before it's finished and to subscribe to events such us OnComplete</returns>
        public static DoRepeatingTask DoRepeating(SAction action, float every, float startAfter = 0, float maxDuration = -1, UpdateType updateType = UpdateType.Update)
        {
            STaskSettings settings = new STaskSettings()
            {
                action      = action,
                frequency   = every,
                delay       = startAfter,
                maxDuration = maxDuration,
            };

            DoRepeatingTask task = new DoRepeatingTask(settings);

            AddTask(task, updateType);
            return(task);
        }
Пример #5
0
        /// <summary>
        /// Performs a task until a condition is met
        /// </summary>
        /// <param name="action">The action to be executed</param>
        /// <param name="condition">The condition for this task to stop</param>
        /// <param name="every">Optional: The time (in seconds) to wait between executions</param>
        /// <param name="startAfter">Optional: The time (in seconds) to wait before starting the task</param>
        /// <param name="updateType">Optional: The update method this task should use (Update/LateUpdate/FixedUpdate)</param>
        /// <param name="timeout">Optional: A maximum duration (in seconds) for this task. If set, the task will stop even if the condition isn't met. Note that the action won't be executed.</param>
        /// <returns>The STask. You can save this task to stop it before it's finished and to subscribe to events such us OnComplete</returns>
        public static DoUntilTask DoUntil(SAction action, SCondition condition, float every = 0, float startAfter = 0, float timeout = -1, UpdateType updateType = UpdateType.Update)
        {
            STaskSettings settings = new STaskSettings()
            {
                action      = action,
                condition   = condition,
                frequency   = every,
                delay       = startAfter,
                maxDuration = timeout,
            };

            DoUntilTask task = new DoUntilTask(settings);

            AddTask(task, updateType);
            return(task);
        }
Пример #6
0
 public DoUntilTask(STaskSettings settings) : base(settings)
 {
     _condition = settings.condition;
 }
Пример #7
0
 public DoWhenTask(STaskSettings settings) : base(settings)
 {
     this.condition = settings.condition;
 }