public void InterruptTest() { // interrupt test // // root - ex1 // // interrupt - ex2 // // ex1 : should be activated twice, at fist tick and at third tick // ex2 : should be activated only once at second tick BT_Root root = new BT_Root(); BT_Execute ex1 = new BT_Execute(); BT_Interrupt interrupt = new BT_Interrupt(); BT_Execute ex2 = new BT_Execute(); root.AddChild(ex1); interrupt.AddChild(ex2); bool isOK1 = false, isOK2 = false; ex1.AddEvent(() => { isOK1 = !isOK1; }); ex2.AddEvent(() => { isOK2 = !isOK2; }); interrupt.SetCondition(() => { return(isOK1 && !isOK2); }); BehaviourTree tree = new BehaviourTree(root); tree.AddInterrupt(interrupt); tree.Tick(); Assert.AreEqual(true, isOK1); Assert.AreEqual(false, isOK2); tree.Tick(); Assert.AreEqual(true, isOK1); Assert.AreEqual(true, isOK2); tree.Tick(); Assert.AreEqual(false, isOK1); Assert.AreEqual(true, isOK2); }
override public void MakeTree() { base.MakeTree(); BT_Root root = new BT_Root(); behaviourTree = new BehaviourTree(root); BT_Selector selector1 = new BT_Selector(); BT_Execute attack = new BT_Execute(); BT_Execute chase = new BT_Execute(); BT_Execute patrol = new BT_Execute(); BT_Selector selector2 = new BT_Selector(); BT_If if_found = new BT_If(); BT_If If_attack = new BT_If(); BT_Execute attackable_check = new BT_Execute(); BT_Execute moveableCheck = new BT_Execute(); BT_If if_patrol = new BT_If(); BT_If If_chase = new BT_If(); BT_If If_escape = new BT_If(); BT_Execute escape = new BT_Execute(); BT_Interrupt DamageInterrupt = new BT_Interrupt(); BT_Execute ResetDamageFlag = new BT_Execute(); BT_Execute ActivateEscape = new BT_Execute(); BT_Execute SetFound = new BT_Execute(); If_escape.SetCondition(() => { return(IsEscape && IsMoveable); }); If_escape.AddChild(escape); escape.AddEvent(() => { escape_event.Invoke(); }); if_found.SetCondition(() => { return(IsFound); }); if_found.AddChild(selector2); If_attack.SetCondition(() => { return(IsAttackable); }); If_attack.AddChild(attack); attackable_check.AddEvent(() => { attackablecheck_event.Invoke(); }); attackable_check.AddChild(If_attack); selector2.AddChild(If_escape); selector2.AddChild(attackable_check); selector2.AddChild(If_chase); attack.AddEvent(() => { attack_event.Invoke(); }); root.AddChild(moveableCheck); selector1.AddChild(if_found); selector1.AddChild(if_patrol); moveableCheck.AddEvent(() => { moveablecheck_event.Invoke(); }); moveableCheck.AddChild(selector1); if_patrol.SetCondition(() => { return(IsMoveable); }); if_patrol.AddChild(patrol); patrol.AddEvent(() => { patrol_event.Invoke(); }); If_chase.SetCondition(() => { return(IsMoveable); }); If_chase.AddChild(chase); ResetDamageFlag.AddEvent(() => { IsGotDamage = false; }); ResetDamageFlag.AddChild(ActivateEscape); ActivateEscape.AddEvent(() => { IsEscape = true; }); ActivateEscape.AddChild(moveableCheck); SetFound.AddEvent(() => { IsFound = true; }); SetFound.AddChild(ResetDamageFlag); chase.AddEvent(() => { chase_event.Invoke(); }); DamageInterrupt.SetCondition(() => { return(IsGotDamage); }); behaviourTree.AddInterrupt(DamageInterrupt); DamageInterrupt.AddChild(SetFound); }
public void Init() { BT_Root root = new BT_Root(); behaviourTree = new BehaviourTree(root); BT_Selector selector1 = new BT_Selector(); BT_Execute attack = new BT_Execute(); BT_Execute chase = new BT_Execute(); BT_Execute patrol = new BT_Execute(); BT_Selector selector2 = new BT_Selector(); BT_If if_found = new BT_If(); BT_If If_attack = new BT_If(); BT_Execute attackable_check = new BT_Execute(); BT_Execute moveableCheck = new BT_Execute(); BT_If if_patrol = new BT_If(); BT_If If_chase = new BT_If(); BT_If If_escape = new BT_If(); BT_Execute escape = new BT_Execute(); BT_Interrupt DamageInterrupt = new BT_Interrupt(); BT_Execute ResetDamageFlag = new BT_Execute(); BT_Execute ActivateEscape = new BT_Execute(); BT_Timing EscapeTimer = new BT_Timing(behaviourTree, true, false); BT_Interrupt EscapeResetInterrupt = new BT_Interrupt(); BT_Execute EscapeResetter = new BT_Execute(); BT_Execute SetFound = new BT_Execute(); root.AddChild(moveableCheck); selector1.AddChild(if_found); selector1.AddChild(if_patrol); attack.AddEvent(() => { attack_event.Invoke(); }); chase.AddEvent(() => { chase_event.Invoke(); }); patrol.AddEvent(() => { patrol_event.Invoke(); }); selector2.AddChild(If_escape); selector2.AddChild(attackable_check); selector2.AddChild(If_chase); if_found.SetCondition(() => { return(IsFound); }); if_found.AddChild(selector2); If_attack.SetCondition(() => { return(IsAttackable); }); If_attack.AddChild(attack); attackable_check.AddEvent(() => { attackablecheck_event.Invoke(); }); attackable_check.AddChild(If_attack); moveableCheck.AddEvent(() => { moveablecheck_event.Invoke(); }); moveableCheck.AddChild(selector1); if_patrol.SetCondition(() => { return(IsMoveable); }); if_patrol.AddChild(patrol); If_chase.SetCondition(() => { return(IsMoveable); }); If_chase.AddChild(chase); If_escape.SetCondition(() => { return(IsEscape && IsMoveable); }); If_escape.AddChild(escape); escape.AddEvent(() => { escape_event.Invoke(); }); DamageInterrupt.SetCondition(() => { return(IsGotDamage); }); behaviourTree.AddInterrupt(DamageInterrupt); DamageInterrupt.AddChild(SetFound); ResetDamageFlag.AddEvent(() => { IsGotDamage = false; }); ResetDamageFlag.AddChild(ActivateEscape); ActivateEscape.AddEvent(() => { IsEscape = true; }); ActivateEscape.AddChild(EscapeTimer); EscapeTimer.SetTimingCreator(() => { return(new Timer(EscapeResetInterrupt, 3.0)); }); EscapeTimer.AddChild(moveableCheck); EscapeResetInterrupt.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(EscapeResetInterrupt); EscapeResetInterrupt.AddChild(EscapeResetter); EscapeResetter.AddEvent(() => { IsEscape = false; }); EscapeResetter.AddChild(moveableCheck); SetFound.AddEvent(() => { IsFound = true; }); SetFound.AddChild(ResetDamageFlag); calledFlag = new Dictionary <string, bool>(); calledFlag.Add("attack", false); attack_event.AddListener(() => { calledFlag["attack"] = true; }); calledFlag.Add("chase", false); chase_event.AddListener(() => { calledFlag["chase"] = true; }); calledFlag.Add("patrol", false); patrol_event.AddListener(() => { calledFlag["patrol"] = true; }); calledFlag.Add("attackable_check", false); attackablecheck_event.AddListener(() => { calledFlag["attackable_check"] = true; }); calledFlag.Add("moveableCheck", false); moveablecheck_event.AddListener(() => { calledFlag["moveableCheck"] = true; }); calledFlag.Add("escape", false); escape_event.AddListener(() => { calledFlag["escape"] = true; }); }
public void Init() { BT_Root root = new BT_Root(); behaviourTree = new BehaviourTree(root); BT_Execute firstEx = new BT_Execute(); BT_Interrupt InterruptTest = new BT_Interrupt(); BT_Execute itrEx = new BT_Execute(); BT_Interrupt IfTest = new BT_Interrupt(); BT_If if1 = new BT_If(); BT_Execute ifEx1 = new BT_Execute(); BT_If if2 = new BT_If(); BT_Execute ifEx2 = new BT_Execute(); BT_If if3 = new BT_If(); BT_Execute ifEx3 = new BT_Execute(); BT_Interrupt WhileTest = new BT_Interrupt(); BT_While while1 = new BT_While(); BT_Execute whileEx1 = new BT_Execute(); BT_Execute whileEx2 = new BT_Execute(); BT_Interrupt SelectorTest = new BT_Interrupt(); BT_Selector selector1 = new BT_Selector(); BT_Execute selectorEx2 = new BT_Execute(); BT_If selectorIf1 = new BT_If(); BT_Execute selectorEx1 = new BT_Execute(); BT_Execute selectorEx3 = new BT_Execute(); BT_Interrupt SequenceTest = new BT_Interrupt(); BT_Sequence sequence1 = new BT_Sequence(); BT_Execute sequenceEx1 = new BT_Execute(); BT_If sequenceIf1 = new BT_If(); BT_Execute sequenceEx2 = new BT_Execute(); BT_Execute sequenceEx3 = new BT_Execute(); BT_Interrupt frameCounterTest = new BT_Interrupt(); BT_Execute frameCounterEx1 = new BT_Execute(); BT_Timing frameCounter1 = new BT_Timing(behaviourTree, false, false, "frameCounter1"); BT_Interrupt frameCounterTest2 = new BT_Interrupt(); BT_Execute frameCounterEx2 = new BT_Execute(); BT_Interrupt frameCounterTest3 = new BT_Interrupt(); BT_Execute frameCounterEx3 = new BT_Execute(); BT_Timing frameCounter2 = new BT_Timing(behaviourTree, false, true, "frameCounter2"); BT_Interrupt frameCounterTest4 = new BT_Interrupt(); BT_Execute frameCounterEx4 = new BT_Execute(); BT_Timing frameCounter3 = new BT_Timing(behaviourTree, true, false, "frameCounter3"); BT_Interrupt frameCounterTest5 = new BT_Interrupt(); BT_Execute frameCounterEx5 = new BT_Execute(); BT_Interrupt timerTest = new BT_Interrupt(); BT_Execute timerTestEx1 = new BT_Execute(); BT_Timing timer1 = new BT_Timing(behaviourTree, false, false, "timer1"); BT_Interrupt timerTest2 = new BT_Interrupt(); BT_Execute timerTestEx2 = new BT_Execute(); BT_Interrupt timerTest3 = new BT_Interrupt(); BT_Execute timerTestEx3 = new BT_Execute(); BT_Timing timer2 = new BT_Timing(behaviourTree, false, true, "timer2"); BT_Interrupt timerTest4 = new BT_Interrupt(); BT_Execute timerTestEx4 = new BT_Execute(); BT_Timing timer3 = new BT_Timing(behaviourTree, true, false, "timer3"); BT_Interrupt timerTest5 = new BT_Interrupt(); BT_Execute timerTestEx5 = new BT_Execute(); BT_Success NextSequence = new BT_Success(); BT_Interrupt setParameterTest = new BT_Interrupt(); BT_Execute SetBool1 = new BT_Execute(); BT_Execute SetBool2 = new BT_Execute(); BT_Sequence sequence = new BT_Sequence(); BT_If setParameterIf1 = new BT_If(); BT_Execute setParameterEx1 = new BT_Execute(); BT_If setParameterIf2 = new BT_If(); BT_Execute setParameterEx2 = new BT_Execute(); BT_Execute SetBool3 = new BT_Execute(); BT_If setParameterIf3 = new BT_If(); BT_Execute setParameterEx3 = new BT_Execute(); BT_Execute SetInt1 = new BT_Execute(); BT_If setParameterIf4 = new BT_If(); BT_Execute setParameterEx4 = new BT_Execute(); BT_Execute SetInt2 = new BT_Execute(); BT_If setParameterIf5 = new BT_If(); BT_Execute setParameterEx5 = new BT_Execute(); BT_Execute SetFloat1 = new BT_Execute(); BT_If setParameterIf6 = new BT_If(); BT_Execute setParameterEx6 = new BT_Execute(); BT_Execute SetFloat2 = new BT_Execute(); BT_If setParameterIf7 = new BT_If(); BT_Execute setParameterEx7 = new BT_Execute(); BT_While while2 = new BT_While(); BT_Execute whileEx3 = new BT_Execute(); BT_Interrupt CancelTest1Itr = new BT_Interrupt(); BT_Timing CancelTest1FC = new BT_Timing(behaviourTree, false, false, "CancelTest1FC"); BT_Execute CancelTest1Cancel = new BT_Execute(); BT_If CancelTest1If = new BT_If(); BT_Execute CencelTest1Ex2 = new BT_Execute(); BT_Execute CencelTest1Ex1 = new BT_Execute(); BT_Interrupt CancelTest2Itr = new BT_Interrupt(); BT_Execute CencelTest2Ex1 = new BT_Execute(); BT_Timing CancelTest2FC = new BT_Timing(behaviourTree, false, false, "CancelTest2FC"); BT_Execute CancelTest2Cancel = new BT_Execute(); BT_If CancelTest2If = new BT_If(); BT_Execute CencelTest2Ex2 = new BT_Execute(); BT_Timing CancelTest2Timer = new BT_Timing(behaviourTree, false, false, "CancelTest2Timer"); firstEx.AddEvent(() => { first_ev.Invoke(); }); root.AddChild(firstEx); InterruptTest.SetCondition(() => { return(case2); }); behaviourTree.AddInterrupt(InterruptTest); InterruptTest.AddChild(itrEx); itrEx.AddEvent(() => { itr_ev.Invoke(); }); IfTest.SetCondition(() => { return(case3); }); behaviourTree.AddInterrupt(IfTest); IfTest.AddChild(if1); if1.SetCondition(() => { return(if_bool1); }); if1.AddChild(ifEx1); ifEx1.AddEvent(() => { if_ev1.Invoke(); }); ifEx1.AddChild(if2); if2.SetCondition(() => { return(if_int1 > 10); }); if2.AddChild(ifEx2); ifEx2.AddEvent(() => { if_ev2.Invoke(); }); ifEx2.AddChild(if3); if3.SetCondition(() => { return(if_float1 < 10.0f); }); if3.AddChild(ifEx3); ifEx3.AddEvent(() => { if_ev3.Invoke(); }); while2.SetCondition(() => { return(while_bool2); }); while2.AddChild(whileEx3); whileEx3.AddEvent(() => { while_ev3.Invoke(); }); while1.SetCondition(() => { return(while_bool1); }); while1.AddChild(whileEx2); WhileTest.SetCondition(() => { return(case4); }); behaviourTree.AddInterrupt(WhileTest); WhileTest.AddChild(whileEx1); whileEx1.AddEvent(() => { while_ev1.Invoke(); }); whileEx1.AddChild(while1); whileEx2.AddEvent(() => { while_ev2.Invoke(); }); whileEx2.AddChild(while2); selectorIf1.SetCondition(() => { return(selector_bool1); }); selectorIf1.AddChild(selectorEx1); selectorEx1.AddEvent(() => { selector_ev1.Invoke(); }); SelectorTest.SetCondition(() => { return(case5); }); behaviourTree.AddInterrupt(SelectorTest); SelectorTest.AddChild(selector1); selectorEx2.AddEvent(() => { selector_ev2.Invoke(); }); selector1.AddChild(selectorIf1); selector1.AddChild(selectorEx2); selector1.AddChild(selectorEx3); selectorEx3.AddEvent(() => { selector_ev3.Invoke(); }); sequenceEx1.AddEvent(() => { sequence_ev1.Invoke(); }); sequenceEx1.AddChild(NextSequence); SequenceTest.SetCondition(() => { return(case6); }); behaviourTree.AddInterrupt(SequenceTest); SequenceTest.AddChild(sequence1); sequence1.AddChild(sequenceEx1); sequence1.AddChild(sequenceIf1); sequence1.AddChild(sequenceEx3); sequenceIf1.SetCondition(() => { return(sequence_bool1 ); }); sequenceIf1.AddChild(sequenceEx2); sequenceEx2.AddEvent(() => { sequence_ev2.Invoke(); }); sequenceEx3.AddEvent(() => { sequence_ev3.Invoke(); }); frameCounterEx2.AddEvent(() => { frameCounter_ev2.Invoke(); }); frameCounterTest.SetCondition(() => { return(case7); }); behaviourTree.AddInterrupt(frameCounterTest); frameCounterTest.AddChild(frameCounterEx1); frameCounter1.SetTimingCreator(() => { return(new FrameCounter(frameCounterTest2, 1)); }); frameCounterTest2.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(frameCounterTest2); frameCounterTest2.AddChild(frameCounterEx2); frameCounterEx1.AddEvent(() => { frameCounter_ev1.Invoke(); }); frameCounterEx1.AddChild(frameCounter1); frameCounterTest3.SetCondition(() => { return(case8); }); behaviourTree.AddInterrupt(frameCounterTest3); frameCounterTest3.AddChild(frameCounterEx3); frameCounterEx3.AddEvent(() => { frameCounter_ev3.Invoke(); }); frameCounterEx3.AddChild(frameCounter2); frameCounter2.SetTimingCreator(() => { return(new FrameCounter(frameCounterTest4, 1)); }); frameCounterTest4.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(frameCounterTest4); frameCounterTest4.AddChild(frameCounterEx4); frameCounterEx4.AddEvent(() => { frameCounter_ev4.Invoke(); }); frameCounterEx4.AddChild(frameCounter3); frameCounter3.SetTimingCreator(() => { return(new FrameCounter(frameCounterTest5, 1)); }); frameCounterTest5.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(frameCounterTest5); frameCounterTest5.AddChild(frameCounterEx5); frameCounterEx5.AddEvent(() => { frameCounter_ev5.Invoke(); }); timerTest.SetCondition(() => { return(case9); }); behaviourTree.AddInterrupt(timerTest); timerTest.AddChild(timerTestEx1); timerTestEx1.AddEvent(() => { timerTest_ev1.Invoke(); }); timerTestEx1.AddChild(timer1); timer1.SetTimingCreator(() => { return(new Timer(timerTest2, 3)); }); timerTest2.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(timerTest2); timerTest2.AddChild(timerTestEx2); timerTestEx2.AddEvent(() => { timerTest_ev2.Invoke(); }); timerTest3.SetCondition(() => { return(case10); }); behaviourTree.AddInterrupt(timerTest3); timerTest3.AddChild(timerTestEx3); timerTestEx3.AddEvent(() => { timerTest_ev3.Invoke(); }); timerTestEx3.AddChild(timer2); timer2.SetTimingCreator(() => { return(new Timer(timerTest4, 1.5)); }); timerTest4.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(timerTest4); timerTest4.AddChild(timerTestEx4); timerTestEx4.AddEvent(() => { timerTest_ev4.Invoke(); }); timerTestEx4.AddChild(timer3); timer3.SetTimingCreator(() => { return(new Timer(timerTest5, 3)); }); timerTest5.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(timerTest5); timerTest5.AddChild(timerTestEx5); timerTestEx5.AddEvent(() => { timerTest_ev5.Invoke(); }); SetBool1.AddEvent(() => { setParameterBool1 = true; }); SetBool1.AddChild(setParameterIf1); SetBool2.AddEvent(() => { setParameterBool2 = false; }); SetBool2.AddChild(setParameterIf2); setParameterIf1.SetCondition(() => { return(setParameterBool1); }); setParameterIf1.AddChild(setParameterEx1); setParameterIf2.SetCondition(() => { return(!setParameterBool2); }); setParameterIf2.AddChild(setParameterEx2); SetBool3.AddEvent(() => { setParameterBool2 = setParameterBool1; }); SetBool3.AddChild(setParameterIf3); setParameterIf3.SetCondition(() => { return(setParameterBool2); }); setParameterIf3.AddChild(setParameterEx3); setParameterEx3.AddEvent(() => { setParameterEv3.Invoke(); }); setParameterEx1.AddEvent(() => { setParameterEv1.Invoke(); }); setParameterEx1.AddChild(SetBool2); setParameterEx2.AddEvent(() => { setParameterEv2.Invoke(); }); setParameterEx2.AddChild(SetBool3); setParameterTest.SetCondition(() => { return(case11); }); behaviourTree.AddInterrupt(setParameterTest); setParameterTest.AddChild(sequence); setParameterIf4.SetCondition(() => { return(setParameterInt1 == 1); }); setParameterIf4.AddChild(setParameterEx4); setParameterIf5.SetCondition(() => { return(setParameterInt2 == 1); }); setParameterIf5.AddChild(setParameterEx5); sequence.AddChild(SetBool1); sequence.AddChild(SetInt1); sequence.AddChild(SetFloat1); SetInt1.AddEvent(() => { setParameterInt1 = 1; }); SetInt1.AddChild(setParameterIf4); setParameterEx4.AddEvent(() => { setParameterEv4.Invoke(); }); setParameterEx4.AddChild(SetInt2); SetInt2.AddEvent(() => { setParameterInt2 = setParameterInt1; }); SetInt2.AddChild(setParameterIf5); setParameterEx5.AddEvent(() => { setParameterEv5.Invoke(); }); setParameterIf6.SetCondition(() => { return(setParameterFloat1 > 1.0f); }); setParameterIf6.AddChild(setParameterEx6); setParameterEx6.AddEvent(() => { setParameterEv6.Invoke(); }); setParameterEx6.AddChild(SetFloat2); setParameterIf7.SetCondition(() => { return(setParameterFloat1 < 1.0f); }); setParameterIf7.AddChild(setParameterEx7); SetFloat1.AddEvent(() => { setParameterFloat1 = 1.5f; }); SetFloat1.AddChild(setParameterIf6); SetFloat2.AddEvent(() => { setParameterFloat1 = setParameterFloat2; }); SetFloat2.AddChild(setParameterIf7); setParameterEx7.AddEvent(() => { setParameterEv7.Invoke(); }); CancelTest1Itr.SetCondition(() => { return(case12); }); behaviourTree.AddInterrupt(CancelTest1Itr); CancelTest1Itr.AddChild(CencelTest1Ex1); CancelTest1FC.SetTimingCreator(() => { return(new FrameCounter(CencelTest1Ex2, 0)); }); CancelTest1FC.AddChild(CancelTest1Cancel); CancelTest1Cancel.AddEvent(() => { behaviourTree.CancelTiming(false, "", "CancelTest1FC"); }); CancelTest1Cancel.AddChild(CancelTest1If); CencelTest1Ex1.AddEvent(() => { cancelTest1ev1.Invoke(); }); CencelTest1Ex1.AddChild(CancelTest1FC); CancelTest1If.SetCondition(() => { return(false); }); CancelTest1If.AddChild(CencelTest1Ex2); CencelTest1Ex2.AddEvent(() => { cancelTest1ev2.Invoke(); }); CancelTest2Itr.SetCondition(() => { return(case13); }); behaviourTree.AddInterrupt(CancelTest2Itr); CancelTest2Itr.AddChild(CencelTest2Ex1); CencelTest2Ex1.AddEvent(() => { cancelTest2ev1.Invoke(); }); CencelTest2Ex1.AddChild(CancelTest2FC); CancelTest2FC.SetTimingCreator(() => { return(new FrameCounter(CencelTest2Ex2, 0)); }); CancelTest2FC.AddChild(CancelTest2Timer); CancelTest2Cancel.AddEvent(() => { behaviourTree.CancelTiming(true, ""); }); CancelTest2Cancel.AddChild(CancelTest2If); CancelTest2Timer.SetTimingCreator(() => { return(new Timer(CencelTest2Ex2, 0.5)); }); CancelTest2Timer.AddChild(CancelTest2Cancel); CancelTest2If.SetCondition(() => { return(false); }); CancelTest2If.AddChild(CencelTest2Ex2); CencelTest2Ex2.AddEvent(() => { cancelTest2ev2.Invoke(); }); calledFlag = new Dictionary <string, bool>(); calledFlag.Add("firstEx", false); first_ev.AddListener(() => { calledFlag["firstEx"] = true; }); calledFlag.Add("itrEx", false); itr_ev.AddListener(() => { calledFlag["itrEx"] = true; }); calledFlag.Add("ifEx1", false); if_ev1.AddListener(() => { calledFlag["ifEx1"] = true; }); calledFlag.Add("ifEx2", false); if_ev2.AddListener(() => { calledFlag["ifEx2"] = true; }); calledFlag.Add("ifEx3", false); if_ev3.AddListener(() => { calledFlag["ifEx3"] = true; }); calledFlag.Add("whileEx1", false); while_ev1.AddListener(() => { calledFlag["whileEx1"] = true; }); calledFlag.Add("whileEx2", false); while_ev2.AddListener(() => { calledFlag["whileEx2"] = true; }); calledFlag.Add("selectorEx2", false); selector_ev2.AddListener(() => { calledFlag["selectorEx2"] = true; }); calledFlag.Add("selectorEx1", false); selector_ev1.AddListener(() => { calledFlag["selectorEx1"] = true; }); calledFlag.Add("selectorEx3", false); selector_ev3.AddListener(() => { calledFlag["selectorEx3"] = true; }); calledFlag.Add("sequenceEx1", false); sequence_ev1.AddListener(() => { calledFlag["sequenceEx1"] = true; }); calledFlag.Add("sequenceEx2", false); sequence_ev2.AddListener(() => { calledFlag["sequenceEx2"] = true; }); calledFlag.Add("sequenceEx3", false); sequence_ev3.AddListener(() => { calledFlag["sequenceEx3"] = true; }); calledFlag.Add("frameCounterEx1", false); frameCounter_ev1.AddListener(() => { calledFlag["frameCounterEx1"] = true; }); calledFlag.Add("frameCounterEx2", false); frameCounter_ev2.AddListener(() => { calledFlag["frameCounterEx2"] = true; }); calledFlag.Add("frameCounterEx3", false); frameCounter_ev3.AddListener(() => { calledFlag["frameCounterEx3"] = true; }); calledFlag.Add("frameCounterEx4", false); frameCounter_ev4.AddListener(() => { calledFlag["frameCounterEx4"] = true; }); calledFlag.Add("frameCounterEx5", false); frameCounter_ev5.AddListener(() => { calledFlag["frameCounterEx5"] = true; }); calledFlag.Add("timerTestEx1", false); timerTest_ev1.AddListener(() => { calledFlag["timerTestEx1"] = true; }); calledFlag.Add("timerTestEx2", false); timerTest_ev2.AddListener(() => { calledFlag["timerTestEx2"] = true; }); calledFlag.Add("timerTestEx3", false); timerTest_ev3.AddListener(() => { calledFlag["timerTestEx3"] = true; }); calledFlag.Add("timerTestEx4", false); timerTest_ev4.AddListener(() => { calledFlag["timerTestEx4"] = true; }); calledFlag.Add("timerTestEx5", false); timerTest_ev5.AddListener(() => { calledFlag["timerTestEx5"] = true; }); calledFlag.Add("setParameterEx1", false); setParameterEv1.AddListener(() => { calledFlag["setParameterEx1"] = true; }); calledFlag.Add("setParameterEx2", false); setParameterEv2.AddListener(() => { calledFlag["setParameterEx2"] = true; }); calledFlag.Add("setParameterEx3", false); setParameterEv3.AddListener(() => { calledFlag["setParameterEx3"] = true; }); calledFlag.Add("setParameterEx4", false); setParameterEv4.AddListener(() => { calledFlag["setParameterEx4"] = true; }); calledFlag.Add("setParameterEx5", false); setParameterEv5.AddListener(() => { calledFlag["setParameterEx5"] = true; }); calledFlag.Add("setParameterEx6", false); setParameterEv6.AddListener(() => { calledFlag["setParameterEx6"] = true; }); calledFlag.Add("setParameterEx7", false); setParameterEv7.AddListener(() => { calledFlag["setParameterEx7"] = true; }); calledFlag.Add("whileEx3", false); while_ev3.AddListener(() => { calledFlag["whileEx3"] = true; }); calledFlag.Add("CencelTest1Ex2", false); cancelTest1ev2.AddListener(() => { calledFlag["CencelTest1Ex2"] = true; }); calledFlag.Add("CencelTest1Ex1", false); cancelTest1ev1.AddListener(() => { calledFlag["CencelTest1Ex1"] = true; }); calledFlag.Add("CencelTest2Ex1", false); cancelTest2ev1.AddListener(() => { calledFlag["CencelTest2Ex1"] = true; }); calledFlag.Add("CencelTest2Ex2", false); cancelTest2ev2.AddListener(() => { calledFlag["CencelTest2Ex2"] = true; }); }
override public void MakeTree() { base.MakeTree(); BT_Root root = new BT_Root(); behaviourTree = new BehaviourTree(root); BT_Execute firstEx = new BT_Execute(); BT_Interrupt InterruptTest = new BT_Interrupt(); BT_Execute itrEx = new BT_Execute(); BT_Interrupt IfTest = new BT_Interrupt(); BT_If if1 = new BT_If(); BT_Execute ifEx1 = new BT_Execute(); BT_If if2 = new BT_If(); BT_Execute ifEx2 = new BT_Execute(); BT_If if3 = new BT_If(); BT_Execute ifEx3 = new BT_Execute(); BT_Interrupt WhileTest = new BT_Interrupt(); BT_While while1 = new BT_While(); BT_Execute whileEx1 = new BT_Execute(); BT_Execute whileEx2 = new BT_Execute(); BT_Interrupt SelectorTest = new BT_Interrupt(); BT_Selector selector1 = new BT_Selector(); BT_Execute selectorEx2 = new BT_Execute(); BT_If selectorIf1 = new BT_If(); BT_Execute selectorEx1 = new BT_Execute(); BT_Execute selectorEx3 = new BT_Execute(); BT_Interrupt SequenceTest = new BT_Interrupt(); BT_Sequence sequence1 = new BT_Sequence(); BT_Execute sequenceEx1 = new BT_Execute(); BT_If sequenceIf1 = new BT_If(); BT_Execute sequenceEx2 = new BT_Execute(); BT_Execute sequenceEx3 = new BT_Execute(); BT_Interrupt frameCounterTest = new BT_Interrupt(); BT_Execute frameCounterEx1 = new BT_Execute(); BT_Timing frameCounter1 = new BT_Timing(behaviourTree, false, false); BT_Interrupt frameCounterTest2 = new BT_Interrupt(); BT_Execute frameCounterEx2 = new BT_Execute(); BT_Interrupt frameCounterTest3 = new BT_Interrupt(); BT_Execute frameCounterEx3 = new BT_Execute(); BT_Timing frameCounter2 = new BT_Timing(behaviourTree, false, true); BT_Interrupt frameCounterTest4 = new BT_Interrupt(); BT_Execute frameCounterEx4 = new BT_Execute(); BT_Timing frameCounter3 = new BT_Timing(behaviourTree, true, false); BT_Interrupt frameCounterTest5 = new BT_Interrupt(); BT_Execute frameCounterEx5 = new BT_Execute(); BT_Interrupt timerTest = new BT_Interrupt(); BT_Execute timerTestEx1 = new BT_Execute(); BT_Timing timer1 = new BT_Timing(behaviourTree, false, false); BT_Interrupt timerTest2 = new BT_Interrupt(); BT_Execute timerTestEx2 = new BT_Execute(); BT_Interrupt timerTest3 = new BT_Interrupt(); BT_Execute timerTestEx3 = new BT_Execute(); BT_Timing timer2 = new BT_Timing(behaviourTree, false, true); BT_Interrupt timerTest4 = new BT_Interrupt(); BT_Execute timerTestEx4 = new BT_Execute(); BT_Timing timer3 = new BT_Timing(behaviourTree, true, false); BT_Interrupt timerTest5 = new BT_Interrupt(); BT_Execute timerTestEx5 = new BT_Execute(); BT_Success NextSequence = new BT_Success(); BT_Interrupt setParameterTest = new BT_Interrupt(); BT_Execute SetBool1 = new BT_Execute(); BT_Execute SetBool2 = new BT_Execute(); BT_Sequence sequence = new BT_Sequence(); BT_If setParameterIf1 = new BT_If(); BT_Execute setParameterEx1 = new BT_Execute(); BT_If setParameterIf2 = new BT_If(); BT_Execute setParameterEx2 = new BT_Execute(); BT_Execute SetBool3 = new BT_Execute(); BT_If setParameterIf3 = new BT_If(); BT_Execute setParameterEx3 = new BT_Execute(); BT_Execute SetInt1 = new BT_Execute(); BT_If setParameterIf4 = new BT_If(); BT_Execute setParameterEx4 = new BT_Execute(); BT_Execute SetInt2 = new BT_Execute(); BT_If setParameterIf5 = new BT_If(); BT_Execute setParameterEx5 = new BT_Execute(); BT_Execute SetFloat1 = new BT_Execute(); BT_If setParameterIf6 = new BT_If(); BT_Execute setParameterEx6 = new BT_Execute(); BT_Execute SetFloat2 = new BT_Execute(); BT_If setParameterIf7 = new BT_If(); BT_Execute setParameterEx7 = new BT_Execute(); firstEx.AddEvent(() => { first_ev.Invoke(); }); root.AddChild(firstEx); InterruptTest.SetCondition(() => { return(case2); }); behaviourTree.AddInterrupt(InterruptTest); InterruptTest.AddChild(itrEx); itrEx.AddEvent(() => { itr_ev.Invoke(); }); IfTest.SetCondition(() => { return(case3); }); behaviourTree.AddInterrupt(IfTest); IfTest.AddChild(if1); if1.SetCondition(() => { return(if_bool1); }); if1.AddChild(ifEx1); ifEx1.AddEvent(() => { if_ev1.Invoke(); }); ifEx1.AddChild(if2); if2.SetCondition(() => { return(if_int1 > 10); }); if2.AddChild(ifEx2); ifEx2.AddEvent(() => { if_ev2.Invoke(); }); ifEx2.AddChild(if3); if3.SetCondition(() => { return(if_float1 < 10.0f); }); if3.AddChild(ifEx3); ifEx3.AddEvent(() => { if_ev3.Invoke(); }); while1.SetCondition(() => { return(while_bool1); }); while1.AddChild(whileEx2); WhileTest.SetCondition(() => { return(case4); }); behaviourTree.AddInterrupt(WhileTest); WhileTest.AddChild(whileEx1); whileEx1.AddEvent(() => { while_ev1.Invoke(); }); whileEx1.AddChild(while1); whileEx2.AddEvent(() => { while_ev2.Invoke(); }); selectorIf1.SetCondition(() => { return(selector_bool1); }); selectorIf1.AddChild(selectorEx1); selectorEx1.AddEvent(() => { selector_ev1.Invoke(); }); SelectorTest.SetCondition(() => { return(case5); }); behaviourTree.AddInterrupt(SelectorTest); SelectorTest.AddChild(selector1); selector1.AddChild(selectorIf1); selector1.AddChild(selectorEx2); selector1.AddChild(selectorEx3); selectorEx2.AddEvent(() => { selector_ev2.Invoke(); }); selectorEx3.AddEvent(() => { selector_ev3.Invoke(); }); sequenceEx1.AddEvent(() => { sequence_ev1.Invoke(); }); sequenceEx1.AddChild(NextSequence); SequenceTest.SetCondition(() => { return(case6); }); behaviourTree.AddInterrupt(SequenceTest); SequenceTest.AddChild(sequence1); sequence1.AddChild(sequenceEx1); sequence1.AddChild(sequenceIf1); sequence1.AddChild(sequenceEx3); sequenceIf1.SetCondition(() => { return(sequence_bool1 ); }); sequenceIf1.AddChild(sequenceEx2); sequenceEx2.AddEvent(() => { sequence_ev2.Invoke(); }); sequenceEx3.AddEvent(() => { sequence_ev3.Invoke(); }); frameCounterEx2.AddEvent(() => { frameCounter_ev2.Invoke(); }); frameCounterTest.SetCondition(() => { return(case7); }); behaviourTree.AddInterrupt(frameCounterTest); frameCounterTest.AddChild(frameCounterEx1); frameCounter1.SetTimingCreator(() => { return(new FrameCounter(frameCounterTest2, 1)); }); frameCounterTest2.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(frameCounterTest2); frameCounterTest2.AddChild(frameCounterEx2); frameCounterEx1.AddEvent(() => { frameCounter_ev1.Invoke(); }); frameCounterEx1.AddChild(frameCounter1); frameCounterTest3.SetCondition(() => { return(case8); }); behaviourTree.AddInterrupt(frameCounterTest3); frameCounterTest3.AddChild(frameCounterEx3); frameCounterEx3.AddEvent(() => { frameCounter_ev3.Invoke(); }); frameCounterEx3.AddChild(frameCounter2); frameCounter2.SetTimingCreator(() => { return(new FrameCounter(frameCounterTest4, 1)); }); frameCounterTest4.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(frameCounterTest4); frameCounterTest4.AddChild(frameCounterEx4); frameCounterEx4.AddEvent(() => { frameCounter_ev4.Invoke(); }); frameCounterEx4.AddChild(frameCounter3); frameCounter3.SetTimingCreator(() => { return(new FrameCounter(frameCounterTest5, 1)); }); frameCounterTest5.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(frameCounterTest5); frameCounterTest5.AddChild(frameCounterEx5); frameCounterEx5.AddEvent(() => { frameCounter_ev5.Invoke(); }); timerTest.SetCondition(() => { return(case9); }); behaviourTree.AddInterrupt(timerTest); timerTest.AddChild(timerTestEx1); timerTestEx1.AddEvent(() => { timerTest_ev1.Invoke(); }); timerTestEx1.AddChild(timer1); timer1.SetTimingCreator(() => { return(new Timer(timerTest2, 3)); }); timerTest2.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(timerTest2); timerTest2.AddChild(timerTestEx2); timerTestEx2.AddEvent(() => { timerTest_ev2.Invoke(); }); timerTest3.SetCondition(() => { return(case10); }); behaviourTree.AddInterrupt(timerTest3); timerTest3.AddChild(timerTestEx3); timerTestEx3.AddEvent(() => { timerTest_ev3.Invoke(); }); timerTestEx3.AddChild(timer2); timer2.SetTimingCreator(() => { return(new Timer(timerTest4, 1.5)); }); timerTest4.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(timerTest4); timerTest4.AddChild(timerTestEx4); timerTestEx4.AddEvent(() => { timerTest_ev4.Invoke(); }); timerTestEx4.AddChild(timer3); timer3.SetTimingCreator(() => { return(new Timer(timerTest5, 3)); }); timerTest5.SetCondition(() => { return(false); }); behaviourTree.AddInterrupt(timerTest5); timerTest5.AddChild(timerTestEx5); timerTestEx5.AddEvent(() => { timerTest_ev5.Invoke(); }); SetBool1.AddEvent(() => { setParameterBool1 = true; }); SetBool1.AddChild(setParameterIf1); SetBool2.AddEvent(() => { setParameterBool2 = false; }); SetBool2.AddChild(setParameterIf2); setParameterIf1.SetCondition(() => { return(setParameterBool1); }); setParameterIf1.AddChild(setParameterEx1); setParameterIf2.SetCondition(() => { return(!setParameterBool2); }); setParameterIf2.AddChild(setParameterEx2); SetBool3.AddEvent(() => { setParameterBool2 = setParameterBool1; }); SetBool3.AddChild(setParameterIf3); setParameterIf3.SetCondition(() => { return(setParameterBool2); }); setParameterIf3.AddChild(setParameterEx3); setParameterEx3.AddEvent(() => { setParameterEv3.Invoke(); }); setParameterEx1.AddEvent(() => { setParameterEv1.Invoke(); }); setParameterEx1.AddChild(SetBool2); setParameterEx2.AddEvent(() => { setParameterEv2.Invoke(); }); setParameterEx2.AddChild(SetBool3); setParameterTest.SetCondition(() => { return(case11); }); behaviourTree.AddInterrupt(setParameterTest); setParameterTest.AddChild(sequence); setParameterIf4.SetCondition(() => { return(setParameterInt1 == 1); }); setParameterIf4.AddChild(setParameterEx4); setParameterIf5.SetCondition(() => { return(setParameterInt2 == 1); }); setParameterIf5.AddChild(setParameterEx5); sequence.AddChild(SetBool1); sequence.AddChild(SetInt1); sequence.AddChild(SetFloat1); SetInt1.AddEvent(() => { setParameterInt1 = 1; }); SetInt1.AddChild(setParameterIf4); setParameterEx4.AddEvent(() => { setParameterEv4.Invoke(); }); setParameterEx4.AddChild(SetInt2); SetInt2.AddEvent(() => { setParameterInt2 = setParameterInt1; }); SetInt2.AddChild(setParameterIf5); setParameterEx5.AddEvent(() => { setParameterEv5.Invoke(); }); setParameterIf6.SetCondition(() => { return(setParameterFloat1 > 1.0f); }); setParameterIf6.AddChild(setParameterEx6); setParameterEx6.AddEvent(() => { setParameterEv6.Invoke(); }); setParameterEx6.AddChild(SetFloat2); setParameterIf7.SetCondition(() => { return(setParameterFloat1 < 1.0f); }); setParameterIf7.AddChild(setParameterEx7); SetFloat1.AddEvent(() => { setParameterFloat1 = 1.5f; }); SetFloat1.AddChild(setParameterIf6); SetFloat2.AddEvent(() => { setParameterFloat1 = setParameterFloat2; }); SetFloat2.AddChild(setParameterIf7); setParameterEx7.AddEvent(() => { setParameterEv7.Invoke(); }); }