private bool TryGetFirstNodeOfType <T>(BehaviourTreeNodeController controller, out T Node) { foreach (BehaviourTreeNode behaviourTreeNode in controller.Children) { if (behaviourTreeNode is T) { Node = (T)((object)behaviourTreeNode); return(true); } if (behaviourTreeNode is BehaviourTreeNodeController) { T t = default(T); if (this.TryGetFirstNodeOfType <T>(behaviourTreeNode as BehaviourTreeNodeController, out t)) { Node = t; return(true); } } if (behaviourTreeNode is QuestBehaviourTreeNode_Decorator_InteractWith) { foreach (QuestBehaviourTreeNode_ConditionCheck questBehaviourTreeNode_ConditionCheck in (behaviourTreeNode as QuestBehaviourTreeNode_Decorator_InteractWith).ConditionChecks) { if (questBehaviourTreeNode_ConditionCheck is T) { Node = (T)((object)questBehaviourTreeNode_ConditionCheck); return(true); } } } } Node = default(T); return(false); }
public static bool TryGetNodeOfType <T>(BehaviourTreeNodeController controller, out T Node, ref int startvalue, int position = 1) { if (position >= 1 && startvalue < position) { foreach (BehaviourTreeNode behaviourTreeNode in controller.Children) { if (behaviourTreeNode is T) { startvalue++; if (startvalue == position) { Node = (T)((object)behaviourTreeNode); return(true); } } if (behaviourTreeNode is BehaviourTreeNodeController) { T t = default(T); if (ELCPUtilities.TryGetNodeOfType <T>(behaviourTreeNode as BehaviourTreeNodeController, out t, ref startvalue, position)) { Node = t; return(true); } } if (behaviourTreeNode is QuestBehaviourTreeNode_Decorator_InteractWith) { foreach (QuestBehaviourTreeNode_ConditionCheck questBehaviourTreeNode_ConditionCheck in (behaviourTreeNode as QuestBehaviourTreeNode_Decorator_InteractWith).ConditionChecks) { if (questBehaviourTreeNode_ConditionCheck is T) { startvalue++; if (startvalue == position) { Node = (T)((object)questBehaviourTreeNode_ConditionCheck); return(true); } } } } } } Node = default(T); return(false); }