public AIExecutionContext(GameObject gameObject, AIExecutionLog log, AITreeNode[] children, TreeArguments memoryMap) { this.gameObject = gameObject; this.log = log; this.children = children; this.memoryMap = memoryMap; }
public IEnumerable <AIResult> IfElse(AIExecutionContext context) { GameObject gameObject = context.gameObject; AITreeNode[] children = context.children; AIExecutionLog log = context.log; IReadOnlyDictionary <object, object> memoryMap = context.memoryMap; AITreeNode ifChild = null, thenChild = null, elseChild = null; if (children.Length >= 1) { ifChild = children[0]; } if (children.Length >= 2) { thenChild = children[1]; } if (children.Length >= 3) { elseChild = children[2]; } bool?success = false; if (ifChild != null) { bool breakIfElseLoop = false; foreach (var result in ifChild.Call(context)) { switch (result) { case AIResult.Success: success = true; breakIfElseLoop = true; break; case AIResult.Failure: success = false; breakIfElseLoop = true; break; case AIResult.Running: break; } if (breakIfElseLoop) { break; } } } if (success == null) { yield return(AIResult.Failure); } else { foreach (var result in ProcessIfThenChild(success.Value ? thenChild : elseChild, context)) { // Process if then child method will ensure appropriate returns yield return(result); } } }