예제 #1
0
 /// <summary>
 /// 执行定时任务
 /// </summary>
 private void Tick()
 {
     if (taskList == null)
     {
         return;
     }
     for (var i = 0; i < taskList.Count;)
     {
         TimeTask task = taskList[i];
         task.timeDelay -= Time.deltaTime;
         if (task.timeDelay <= 0)
         {
             if (task.timeTaskCallBack != null)
             {
                 task.timeTaskCallBack();
             }
             if (!task.repeat)
             {
                 taskList.Remove(task);
                 continue;
             }
             task.timeDelay = task.timeDelayOnly;
         }
         i++;
     }
 }
예제 #2
0
 public void AddTask(TimeTask taskToAdd)
 {
     if (taskList.Contains(taskToAdd) || taskToAdd == null)
     {
         return;
     }
     taskList.Add(taskToAdd);
 }
예제 #3
0
 /// <summary>
 /// 移除定时任务
 /// </summary>
 /// <param name="taskToRemove"></param>
 /// <returns></returns>
 public bool RemoveTask(TimeTaskDelegate taskToRemove)
 {
     if (taskList.Count == 0 || taskToRemove == null)
     {
         return(false);
     }
     for (var i = 0; i < taskList.Count; i++)
     {
         TimeTask item = taskList[i];
         if (item.timeTaskCallBack == taskToRemove)
         {
             return(taskList.Remove(item));
         }
     }
     return(false);
 }