示例#1
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>
        /// <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 STask DoWhen(SAction action, SCondition condition, float startAfter = 0)
        {
            STask task = new STask(TaskType.OnCondition, action, startAfter, condition);

            AddTask(task);
            return(task);
        }
示例#2
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="useLateUpdate">Optional: If true, the task will be executed on LateUpdate instead of Update</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 STask DoUntil(SAction action, SCondition condition, float every = 0, float startAfter = 0, bool useLateUpdate = false, float timeout = -1)
        {
            STask task = new STask(TaskType.Until, action, after: startAfter, condition, every, useLateUpdate: useLateUpdate, timeout: timeout);

            AddTask(task);
            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 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);
        }
示例#5
0
        public STask(TaskType type, SAction action, float after = 0, SCondition condition = null, float every = -1, bool completeAfterLastFrame = false, bool useLateUpdate = false, float timeout = -1)
        {
            this.action    = action;
            this._after    = after;
            this.condition = condition;
            this._every    = every;
            this._taskType = type;
            this._completeAfterLastFrame = completeAfterLastFrame;
            this._useLateUpdate          = useLateUpdate;
            this._timeout = timeout;

            _isCompletionScheduled = false;
            _isLooped     = type == TaskType.Until || type == TaskType.Looped;
            _loopStarted  = false;
            IsDone        = false;
            ElapsedTime   = 0;
            ElapsedFrames = 0;
        }
示例#6
0
 public DoUntilTask(STaskSettings settings) : base(settings)
 {
     _condition = settings.condition;
 }
示例#7
0
 public DoWhenTask(STaskSettings settings) : base(settings)
 {
     this.condition = settings.condition;
 }