示例#1
0
    /*
     * public void RemoveSequentialTask(Func<IEnumerator> f) {
     *  SequentialTasks.Remove(f);
     * }
     */


    /*
     * public void RemoveImmediateTask(Func<IEnumerator> f) {
     *  ImmediateTasks.Remove(f);
     * }
     */

    IEnumerator RunTasks()
    {
        PC.SetPlayerInputEnabled(PlayerInputFlag.TASKMANAGER, false);

        /*
         * TaskEndFlag = new bool[ImmediateTasks.Count];
         * var Tasks = new List<IClockTask>(ImmediateTasks);
         * Tasks.AddRange(SequentialTasks);
         * Tasks.OrderBy((x) => x.StartClock);
         * foreach (var x in Tasks) {
         *  x.RunImmediately();
         * }
         */
        //SequentialTasks.OrderBy((x) => x.StartClock);

        /*
         * for (int i=0;i<ImmediateTasks.Count;i++) {
         *
         *  StartCoroutine(RunTaskAndRaiseFlag(ImmediateTasks[i], i));
         *
         * }
         * yield return new WaitUntil(() => { var result = true; foreach (var b in TaskEndFlag) { result &= b; } return result; });
         */
        for (int i = 0; i < UndoneTasks.Count; i++)
        {
            if (UndoneTasks[i].StartClock <= Clock)
            {
                SequentialTasks.Add(UndoneTasks[i]);
                UndoneTasks.RemoveAt(i);
                i--;
            }
        }

        Debug.Log("Clock : " + Clock);
        while (SequentialTasks.Count != 0)
        {
            SequentialTasks = SequentialTasks.OrderBy((x) => x.Priority).OrderBy((x) => x.StartClock).ToList();
            var t = SequentialTasks[0];
            if (t.HasIteration)
            {
                yield return(t.Run());
            }
            else
            {
                t.Run();
            }
            //Debug.Log("Task : " + t.ToString() + ", Priority : " + t.Priority + ", Time : " + t.StartClock + ", Frame : " + Time.frameCount + ", RealTime : " + Time.unscaledTime);
            SequentialTasks.Remove(t);
            OnTaskEnd?.Invoke();

            for (int i = 0; i < UndoneTasks.Count; i++)
            {
                if (UndoneTasks[i].StartClock <= Clock)
                {
                    SequentialTasks.Add(UndoneTasks[i]);
                    UndoneTasks.RemoveAt(i);
                    i--;
                }
            }
        }

        //ImmediateTasks.Clear();
        SequentialTasks.Clear();
        PC.SetPlayerInputEnabled(PlayerInputFlag.TASKMANAGER, true);
    }