예제 #1
0
        private void CheckTimeTask()
        {
            lock (lockTime)
            {
                for (int tempIndex = 0; tempIndex < tempTaskList.Count; tempIndex++)
                {
                    taskList.Add(tempTaskList[tempIndex]);
                }
            }


            for (int taskIndex = 0; taskIndex < taskList.Count - tempTaskList.Count; taskIndex++)
            {
                TimeTask task = taskList[taskIndex];
                if (Time.time < task.destTime)
                {
                    continue;
                }
                else
                {
                    if (task.callback != null)
                    {
                        task.callback();
                        Debug.Log("1");
                        taskList.RemoveAt(taskIndex);
                        taskIndex--;
                        recTidLst.Add(task.tid);
                        timeTaskStack.Push(task);
                    }
                }
            }

            tempTaskList.Clear();
        }
예제 #2
0
        private void DelTimeTask()
        {
            if (tmpDelTimeLst.Count > 0)
            {
                lock (lockTime)
                {
                    for (int i = 0; i < tmpDelTimeLst.Count; i++)
                    {
                        bool isDel  = false;
                        int  delTid = tmpDelTimeLst[i];
                        for (int j = 0; j < taskList.Count; j++)
                        {
                            TimeTask task = taskList[j];
                            if (task.tid == delTid)
                            {
                                isDel = true;
                                taskList.RemoveAt(j);
                                recTidLst.Add(delTid);
                                break;
                            }
                        }

                        if (isDel)
                        {
                            continue;
                        }

                        for (int j = 0; j < tempTaskList.Count; j++)
                        {
                            TimeTask task = tempTaskList[j];
                            if (task.tid == delTid)
                            {
                                tempTaskList.RemoveAt(j);
                                recTidLst.Add(delTid);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public int AddTimeTask(float delay, Action callback)
        {
            if (callback == null)
            {
                return(0);
            }
            TimeTask timeTask;

            if (timeTaskStack.Count > 0)
            {
                timeTask = timeTaskStack.Pop();
            }
            else
            {
                timeTask = new TimeTask();
            }

            timeTask.destTime = Time.time + delay;
            timeTask.callback = callback;
            tempTaskList.Add(timeTask);
            timeTask.tid = GetTid();
            return(timeTask.tid);
        }