Exemplo n.º 1
0
        /// <summary>
        /// 运行任务
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="deltaTime">一帧的时间</param>
        /// <returns>是否完成</returns>
        private bool RunTask(TimeTask task, ref float deltaTime)
        {
            var action = task.TimeLine[task.TimeLineIndex];

            switch (action.Type)
            {
            case TimeTaskActionTypes.DelayFrame:
                return(TaskDelayFrame(task, ref deltaTime));

            case TimeTaskActionTypes.DelayTime:
                return(TaskDelayTime(task, ref deltaTime));

            case TimeTaskActionTypes.LoopFunc:
                return(TaskLoopFunc(task, ref deltaTime));

            case TimeTaskActionTypes.LoopTime:
                return(TaskLoopTime(task, ref deltaTime));

            case TimeTaskActionTypes.LoopFrame:
                return(TaskLoopFrame(task, ref deltaTime));

            default:
                return(true);
            }
        }
Exemplo n.º 2
0
        public ITimeTask Task(Action <object> task)
        {
            TimeTask timeTask = new TimeTask(this)
            {
                ActionTaskWithContext = task
            };

            return(timeTask);
        }
Exemplo n.º 3
0
        public ITimeTask Task(Action task)
        {
            TimeTask timeTask = new TimeTask(this)
            {
                ActionTask = task
            };

            return(timeTask);
        }
Exemplo n.º 4
0
 protected void CallTask(TimeTask task)
 {
     if (task.ActionTask != null)
     {
         task.ActionTask();
     }
     if (task.ActionTaskWithContext != null)
     {
         task.ActionTaskWithContext(context);
     }
 }
Exemplo n.º 5
0
 protected void CallTask(TimeTask task)
 {
     if (task.TaskCall != null)
     {
         task.TaskCall.Invoke();
     }
     if (task.TaskCallWithContext != null)
     {
         task.TaskCallWithContext.Invoke(context);
     }
 }
Exemplo n.º 6
0
 protected void CallTaskComplete(TimeTask task)
 {
     task.IsComplete = true;
     if (task.OnCompleteTask != null)
     {
         task.OnCompleteTask.Invoke();
     }
     if (task.OnCompleteTaskWithContext != null)
     {
         task.OnCompleteTaskWithContext.Invoke(context);
     }
 }
Exemplo n.º 7
0
        protected bool TaskLoopFunc(TimeTask task, ref float deltaTime)
        {
            TimeTaskAction action = task.TimeLine[task.TimeLineIndex];

            if (!action.FuncBoolArg())
            {
                task.TimeLineIndex++;
                return(true);
            }

            CallTask(task);
            return(false);
        }
Exemplo n.º 8
0
        protected bool TaskDelayFrame(TimeTask task, ref float deltaTime)
        {
            TimeTaskAction action = task.TimeLine[task.TimeLineIndex];

            if (action.IntArgs[0] >= 0 && action.IntArgs[1] < action.IntArgs[0])
            {
                action.IntArgs[1] += 1;
                deltaTime          = 0;
                if (action.IntArgs[1] >= action.IntArgs[0])
                {
                    task.TimeLineIndex++;
                    CallTask(task);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 循环执行指定帧数
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="deltaTime">一帧的时间</param>
        /// <returns>是否完成</returns>
        private bool TaskLoopFrame(TimeTask task, ref float deltaTime)
        {
            var action = task.TimeLine[task.TimeLineIndex];

            if (action.IntArgs[0] >= 0 && action.IntArgs[1] <= action.IntArgs[0])
            {
                action.IntArgs[1] += 1;
                deltaTime          = 0;
                if (action.IntArgs[1] > action.IntArgs[0])
                {
                    task.TimeLineIndex++;
                    return(true);
                }
            }

            CallTask(task);
            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 延迟帧执行
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="deltaTime">一帧的时间</param>
        /// <returns>是否完成</returns>
        private bool TaskDelayFrame(TimeTask task, ref float deltaTime)
        {
            var action = task.TimeLine[task.TimeLineIndex];

            if (action.IntArgs[0] < 0 || action.IntArgs[1] >= action.IntArgs[0])
            {
                return(false);
            }
            action.IntArgs[1] += 1;
            deltaTime          = 0;
            if (action.IntArgs[1] < action.IntArgs[0])
            {
                return(false);
            }
            task.TimeLineIndex++;
            CallTask(task);
            return(true);
        }
Exemplo n.º 11
0
        protected bool TaskLoopTime(TimeTask task, ref float deltaTime)
        {
            TimeTaskAction action = task.TimeLine[task.TimeLineIndex];

            if (action.FloatArgs[0] >= 0 && action.FloatArgs[1] <= action.FloatArgs[0])
            {
                action.FloatArgs[1] += deltaTime;

                if (action.FloatArgs[1] > action.FloatArgs[0])
                {
                    deltaTime = action.FloatArgs[1] - action.FloatArgs[0];
                    task.TimeLineIndex++;
                    return(true);
                }
            }

            CallTask(task);
            return(false);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 延迟时间执行
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="deltaTime">一帧的时间</param>
        /// <returns>是否完成</returns>
        private bool TaskDelayTime(TimeTask task, ref float deltaTime)
        {
            var action = task.TimeLine[task.TimeLineIndex];

            if (!(action.FloatArgs[0] >= 0) || !(action.FloatArgs[1] < action.FloatArgs[0]))
            {
                return(false);
            }

            action.FloatArgs[1] += deltaTime;

            if (!(action.FloatArgs[1] >= action.FloatArgs[0]))
            {
                return(false);
            }

            deltaTime = action.FloatArgs[1] - action.FloatArgs[0];
            task.TimeLineIndex++;
            CallTask(task);
            return(true);
        }
Exemplo n.º 13
0
 public void Cancel(TimeTask task)
 {
     queueTasks.Remove(task);
 }
Exemplo n.º 14
0
 public ITimeTaskHandler Push(TimeTask task)
 {
     queueTasks.Add(task);
     return(task);
 }