Example #1
0
 /// <summary>
 /// Converts a single Task Node Tree to a list of Tasks recursively
 /// </summary>
 /// <returns>A single tree in list form</returns>
 /// <param name="tn">The starting task node</param>
 /// <param name="tasks">The list to build off of</param>
 public static List <Task> TaskTreeSingleToTaskList(TaskNode tn, List <Task> tasks)
 {
     foreach (TaskNode n in tn.Children)
     {
         tasks = TaskTreeSingleToTaskList(n, tasks);
     }
     tasks.Add(tn.AssociatedTask);
     return(tasks);
 }
Example #2
0
        /// <summary>
        /// For each individual tree, this runs the Interaction Event through all tasks and their children recursively to check whether a task has been completed.
        /// This first checks if a task's child nodes have all been completed, and only then runs the event through the tasks trigger function.
        /// </summary>
        /// <param name="evt">Evt.</param>
        /// <param name="tn">Current task node</param>
        /// <param name="doAll">True if trigger should be run regardless of whether task has already been completed once or not</param>
        public bool UpdateTaskBranch(InteractionEvent evt, TaskNode tn, bool doAll)
        {
            bool allChildrenComplete = true;

            foreach (TaskNode tchild in tn.Children)
            {
                allChildrenComplete &= (tchild.AssociatedTask.isComplete || UpdateTaskBranch(evt, tchild, doAll));
                // if child not complete, and updating child doesn't complete the child, allChildrenComplete = false
            }

            if ((doAll || !tn.AssociatedTask.isComplete) &&
                (allChildrenComplete && (tn.AssociatedTask.trigger == null || tn.AssociatedTask.trigger(evt))))
            {
                Debug.Log(string.Format("Task {0} complete", tn.AssociatedTask.name));
                tn.AssociatedTask.isComplete = true;
                tn.AssociatedTask.onComplete(evt);
                return(true);
            }
            return(false);
        }