コード例 #1
0
        public CoroutineTask CreateAndAddSubCoroutineTask(IEnumerator coroutine)
        {
            var j = new CoroutineTask(coroutine, false);

            AddSubCoroutineTask(j);
            return(j);
        }
コード例 #2
0
 public void AddSubCoroutineTask(CoroutineTask subCoroutineTask)
 {
     if (gSubCoroutineTaskStack == null)
     {
         gSubCoroutineTaskStack = new Stack <CoroutineTask>();
     }
     gSubCoroutineTaskStack.Push(subCoroutineTask);
 }
コード例 #3
0
        private IEnumerator ExecuteSubTask()
        {
            // Check if there is any sub-coroutines in the stack.
            if (gSubCoroutineTaskStack != null && gSubCoroutineTaskStack.Count > 0)
            {
                do
                {
                    // Get first sub-task.
                    CoroutineTask subTask = gSubCoroutineTaskStack.Pop();

                    // Execute the sub task.
                    yield return(CoroutineCoordinator.Instance.StartCoroutine(subTask.StartAsCoroutine()));
                }
                // Keep executing the sub tasks as long as there is any.
                while(gSubCoroutineTaskStack.Count > 0);
            }
        }
コード例 #4
0
        public void RemoveSubCoroutineTask(CoroutineTask subCoroutineTask)
        {
            if (gSubCoroutineTaskStack.Contains(subCoroutineTask))
            {
                var subCoroutineTaskStack = new Stack <CoroutineTask>(gSubCoroutineTaskStack.Count - 1);
                var allCurrentSubTasks    = gSubCoroutineTaskStack.ToArray();
                System.Array.Reverse(allCurrentSubTasks);

                for (var i = 0; i < allCurrentSubTasks.Length; i++)
                {
                    var j = allCurrentSubTasks[i];
                    if (j != subCoroutineTask)
                    {
                        subCoroutineTaskStack.Push(j);
                    }
                }

                // assign the new stack
                gSubCoroutineTaskStack = subCoroutineTaskStack;
            }
        }