public void Transition2_4_RRTest() { var countDown = new CountdownEvent(1); foreach (var a in TestDef.Constant.DoubleTriggerButtons) { countDown.Reset(); var gestureDef = new List <IfButtonGestureDefinition>() { new IfButtonGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { Assert.Fail(); }, (ctx) => { Assert.Fail(); }, (ctx) => { countDown.Signal(); }) }; using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), new List <OnButtonGestureDefinition>(), gestureDef); var S2 = S1.S2; var res = S2.Reset(); Assert.IsTrue(res is State0); Assert.IsTrue(Global.IgnoreNext.Contains(Helper.Convert(a as DSL.Def.AcceptableInOnClause).GetPair())); Assert.IsTrue(countDown.Wait(50)); } } }
public void Transition3_0_RRTest() { using (var countDown = new CountdownEvent(2)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { foreach (var b in TestDef.Constant.DoubleTriggerButtons) { var gestureDefA = new List <IfButtonGestureDefinition>() { new IfButtonGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { Assert.Fail(); }, (ctx) => { Assert.Fail(); }, (ctx) => { Assert.Fail(); }) }; var gestureDefB = new List <OnButtonWithIfButtonGestureDefinition>() { new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInOnClause, b as DSL.Def.AcceptableInIfButtonClause, (ctx) => { Assert.Fail(); }, (ctx) => { countDown.Signal(); }, (ctx) => { countDown.Signal(); }) }; foreach (var c in TestDef.Constant.DoubleTriggerButtons) { if (a == c) { continue; } countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), gestureDefB, gestureDefA); var S2 = S1.S2; var S3 = new State3(Global, S0, S2, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), Helper.Convert(b as DSL.Def.AcceptableInOnClause), S2.T3, gestureDefB); var ev = Helper.Convert(c as DSL.Def.AcceptableInOnClause).GetPair(); var res = S3.Input((Def.Event.IEvent)ev, new Point()); if (b == c) { Assert.IsTrue(res.NextState is State2); Assert.IsTrue(Global.IgnoreNext.Count() == 0); Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsTrue(res.NextState is State3); Assert.IsTrue(Global.IgnoreNext.Count() == 0); Assert.IsFalse(countDown.Wait(50)); } } } } } } }
void Start() { mState1 = State1.ScaleUp; mState2_IsFadingOut = false; mShakeDirects = new Vector3[] { new Vector3(-1F, 1F, 0F) , new Vector3(1F, -1.2F, 0F) , new Vector3(1.2F, 1F, 0F) , new Vector3(-1.2F, -0.8F, 0F) }; mSprWeb = Pool_GameObj.GetObj(Prefab_GoSpriteWeb).GetComponent <tk2dSprite>(); if (NameSprite != null && NameSprite != "") { mSprWeb.spriteId = mSprWeb.GetSpriteIdByName(NameSprite); } Transform ts = mSprWeb.transform; mSprWeb.gameObject.SetActive(true); ts.parent = transform; ts.localPosition = Vector3.zero; Color c = ColorInitialize; c.a = 1F; mSprWeb.color = c; mTsWeb = ts; mTimeWaitFadeout = TimeWebScaleUp + TimeShake - TimeFadeOut; mColorWeb = mSprWeb.color; }
public void State2MustBypassInputToStrokeWatcher_RRTest() { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDef = new List <OnButtonGestureDefinition>() { new OnButtonWithIfStrokeGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInOnClause, new Def.Stroke(Def.Direction.Down), (ctx) => { }) }; foreach (var b in TestDef.Constant.Buttons) { using (var Global = new StateGlobal()) { Global.StrokeWatcher.Dispose(); Global.StrokeWatcher = new StrokeWatcherMock(); var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), gestureDef, new List <IfButtonGestureDefinition>()); var S2 = S1.S2; S2.Input(Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause), new Point(0, 0)); S2.Input(Def.Constant.Move, new Point(100, 100)); Console.WriteLine(((StrokeWatcherMock)Global.StrokeWatcher).queue.Count()); Assert.IsTrue(((StrokeWatcherMock)Global.StrokeWatcher).queue.SequenceEqual(new List <Point>() { new Point(0, 0), new Point(100, 100) })); } } } }
public ActionResult Create(UserInfo1 user) { if (!ModelState.IsValid) { var viewModel = new UserViewModel { UserInfo = user, States = context.States.ToList(), Countries = context.Countries.ToList() }; return(View("Create", viewModel)); } if (user.Id == 0) { context.UserInfoes.Add(user); } else { State1 m1 = new State1(); Country1 m2 = new Country1(); var userInDb = context.UserInfoes.Single(c => c.Id == user.Id); userInDb.Name = user.Name; userInDb.DOB = user.DOB; user.State = m1.Name; userInDb.State = user.State; user.Country = m2.Name; userInDb.Country = user.Country; } context.SaveChanges(); return(RedirectToAction("Index")); }
void Start() { mState1 = State1.ScaleUp; mState2_IsFadingOut = false; mShakeDirects = new Vector3[]{ new Vector3(-1F,1F,0F) ,new Vector3(1F,-1.2F,0F) ,new Vector3(1.2F,1F,0F) ,new Vector3(-1.2F,-0.8F,0F) }; mSprWeb = Pool_GameObj.GetObj(Prefab_GoSpriteWeb).GetComponent<tk2dSprite>(); if (NameSprite != null && NameSprite != "") mSprWeb.spriteId = mSprWeb.GetSpriteIdByName(NameSprite); Transform ts = mSprWeb.transform; mSprWeb.gameObject.SetActive(true); ts.parent = transform; ts.localPosition = Vector3.zero; Color c = ColorInitialize; c.a = 1F; mSprWeb.color = c; mTsWeb = ts; mTimeWaitFadeout = TimeWebScaleUp + TimeShake - TimeFadeOut; mColorWeb = mSprWeb.color; }
public void ChangeStateTest() { StateMachine sm = new StateMachine(); // TODO: 初始化为适当的值 Assert.IsNull(sm.GetState()); var state1 = new State1(); //测试基本changestate sm.ChangeState(state1); Assert.AreSame(state1, sm.GetState()); Assert.AreEqual(state1.ToString(), "S1Enter"); //测试对同一个state设置 sm.ChangeState(state1); Assert.AreSame(state1, sm.GetState()); Assert.AreEqual(state1.ToString(), "S1Enter"); sm.Update(); var state2 = sm.GetState(); Assert.AreNotSame(state1, state2); Assert.AreEqual(state1.ToString(), "S1"); Assert.AreEqual(state2.ToString(), "S2Enter"); }
public void State3MustHaveGivenArgumentsTest() { var gestureDef = new List <OnButtonWithIfButtonGestureDefinition>() { new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(true); }, DSL.Def.Constant.RightButton, DSL.Def.Constant.LeftButton, null, (ctx) => { }, null) }; var S0 = new State0(new StateGlobal(), new List <GestureDefinition>()); var S1 = new State1(S0.Global, S0, ctx, Def.Constant.RightButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); var S2 = S1.S2; var S3 = new State3(S1.Global, S0, S2, ctx, Def.Constant.RightButtonDown, Def.Constant.LeftButtonDown, S2.T3, gestureDef); Assert.AreEqual(S3.Global, S1.Global); Assert.AreEqual(S3.S0, S0); Assert.AreEqual(S3.S2, S2); Assert.AreEqual(S3.primaryEvent, Def.Constant.RightButtonDown); Assert.AreEqual(S3.secondaryEvent, Def.Constant.LeftButtonDown); Assert.AreEqual(S3.T0, S2.T3); Assert.AreEqual(S3.T1.Count(), 1); }
public Client() { var factory = new StateFactory(); var first = new State1(factory, this); CurrentState = factory.GetOrCreate <State1>(() => first); }
public async Task RehydrateState_returns_state_correctly( IStateRehydrator <State1> rehydrator, Guid streamId, State1 state) { Mock.Get(rehydrator).Setup(x => x.TryRehydrateState(streamId)).ReturnsAsync(state); State1 actual = await rehydrator.RehydrateState(streamId); actual.Should().BeSameAs(state); }
/// <summary> /// Initializes a new instance of ObjectBinder class. /// </summary> public ObjectBinder() { state0 = new State0(this); state1 = new State1(this); state2 = new State2(this); state3 = new State3(this); state4 = new State4(this); state5 = new State5(this); }
public void RestorePrimaryButtonClickTest() { using (var Global = new StateGlobal()) { var S0 = new State0(new StateGlobal(), new List <GestureDefinition>()); { var S1 = new State1(Global, S0, ctx, Def.Constant.LeftButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); mouseEvents.Clear(); Assert.AreEqual(mouseEvents.Count, 0); S1.RestorePrimaryButtonClickEvent()(); Assert.AreEqual(mouseEvents.Count, 2); Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_LBUTTONDOWN); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_LBUTTONUP); } { var S1 = new State1(Global, S0, ctx, Def.Constant.MiddleButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); mouseEvents.Clear(); Assert.AreEqual(mouseEvents.Count, 0); S1.RestorePrimaryButtonClickEvent()(); Assert.AreEqual(mouseEvents.Count, 2); Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_MBUTTONDOWN); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_MBUTTONUP); } { var S1 = new State1(Global, S0, ctx, Def.Constant.RightButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); mouseEvents.Clear(); Assert.AreEqual(mouseEvents.Count, 0); S1.RestorePrimaryButtonClickEvent()(); Assert.AreEqual(mouseEvents.Count, 2); Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_RBUTTONDOWN); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_RBUTTONUP); } { var S1 = new State1(Global, S0, ctx, Def.Constant.X1ButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); mouseEvents.Clear(); Assert.AreEqual(mouseEvents.Count, 0); S1.RestorePrimaryButtonClickEvent()(); Assert.AreEqual(mouseEvents.Count, 2); Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_XBUTTONDOWN); Assert.IsTrue(mouseEvents[0].Item2.mouseData.asXButton.isXButton1); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_XBUTTONUP); Assert.IsTrue(mouseEvents[1].Item2.mouseData.asXButton.isXButton1); } { var S1 = new State1(Global, S0, ctx, Def.Constant.X2ButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); mouseEvents.Clear(); Assert.AreEqual(mouseEvents.Count, 0); S1.RestorePrimaryButtonClickEvent()(); Assert.AreEqual(mouseEvents.Count, 2); Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_XBUTTONDOWN); Assert.IsTrue(mouseEvents[0].Item2.mouseData.asXButton.isXButton2); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_XBUTTONUP); Assert.IsTrue(mouseEvents[1].Item2.mouseData.asXButton.isXButton2); } } }
public void Transition1_2_RRTest() { using (var countDown = new CountdownEvent(2)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDefA = new List <OnButtonGestureDefinition>() { new OnButtonWithIfStrokeGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInOnClause, new Def.Stroke(new List <Def.Direction>() { Def.Direction.Down }), (ctx) => { countDown.Signal(); }) }; var gestureDefB = new List <IfButtonGestureDefinition>() { new IfButtonGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { Assert.Fail(); }, (ctx) => { Assert.Fail(); }, (ctx) => { countDown.Signal(); }) }; foreach (var b in TestDef.Constant.DoubleTriggerButtons) { countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), gestureDefA, gestureDefB); Global.StrokeWatcher.strokes.Add(new Stroke.Stroke( Global.Config.Gesture.StrokeDirectionChangeThreshold, Global.Config.Gesture.StrokeExtensionThreshold, Def.Direction.Down)); var ev = Helper.Convert(b as DSL.Def.AcceptableInOnClause).GetPair(); var res = S1.Input((Def.Event.IEvent)ev, new Point()); if (a == b) { Assert.IsTrue(res.NextState is State0); Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsTrue(res.NextState is State1); Assert.IsFalse(countDown.Wait(50)); } } } } } }
/// <summary> /// source: https://stackoverflow.com/a/263416 /// </summary> /// <returns></returns> public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + State1.GetHashCode(); hash = hash * 23 + StackSymbol.GetHashCode(); hash = hash * 23 + State2.GetHashCode(); return(hash); } }
public void State2MustHaveGivenArgumentsTest() { var defA = new List <OnButtonGestureDefinition>() { new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(true); }, DSL.Def.Constant.RightButton, DSL.Def.Constant.WheelUp, null, (ctx) => { }, null), new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(false); }, DSL.Def.Constant.RightButton, DSL.Def.Constant.LeftButton, null, (ctx) => { }, null), new OnButtonWithIfStrokeGestureDefinition( (ctx) => { return(false); }, DSL.Def.Constant.RightButton, new Def.Stroke(new List <Def.Direction>() { Def.Direction.Up }), (ctx) => { }) }; var defB = new List <IfButtonGestureDefinition>() { new IfButtonGestureDefinition( (ctx) => { return(true); }, DSL.Def.Constant.LeftButton, null, (ctx) => { }, null) }; var S0 = new State0(new StateGlobal(), new List <GestureDefinition>()); var S1 = new State1(S0.Global, S0, ctx, Def.Constant.RightButtonDown, defA, defB); var S2 = S1.S2; Assert.AreEqual(S2.Global, S0.Global); Assert.AreEqual(S2.S0, S0); Assert.AreEqual(S2.ctx, ctx); Assert.AreEqual(S2.primaryEvent, Def.Constant.RightButtonDown); Assert.AreEqual(S2.T0.Count(), 1); Assert.AreEqual(S2.T1.Count(), 1); Assert.AreEqual(S2.T2.Count(), 1); Assert.AreEqual(S2.T3.Count(), 1); }
public void InputMustResetIgnoreListWhenAPairOfTriggerInIgnoreListGivenTest() { using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Def.Constant.LeftButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); Global.IgnoreNext.Add(Def.Constant.RightButtonUp); Assert.AreEqual(Global.IgnoreNext.Count, 1); var res = S1.Input(Def.Constant.RightButtonDown, new Point()); Assert.IsFalse(res.Event.IsConsumed); Assert.AreEqual(Global.IgnoreNext.Count, 0); } }
public void InputMustResetIgnoreListWhenGivenTriggerIsPairOfTriggerInIgnoreListTest() { var gestureDef = new List <OnButtonWithIfButtonGestureDefinition>(); var S0 = new State0(new StateGlobal(), new List <GestureDefinition>()); var S1 = new State1(S0.Global, S0, ctx, Def.Constant.RightButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); var S2 = S1.S2; var S3 = new State3(S1.Global, S0, S2, ctx, Def.Constant.RightButtonDown, Def.Constant.LeftButtonDown, S2.T3, gestureDef); S3.Global.IgnoreNext.Add(Def.Constant.RightButtonUp); Assert.AreEqual(S3.Global.IgnoreNext.Count, 1); var res = S3.Input(Def.Constant.RightButtonDown, new Point()); Assert.IsFalse(res.Event.IsConsumed); Assert.AreEqual(S3.Global.IgnoreNext.Count, 0); }
public void Transition1_5_RRTest() { using (var countDown = new CountdownEvent(1)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { mouseEvents.Clear(); countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); var res = S1.Cancel(); Global.UserActionTaskFactory.StartNew(() => { countDown.Signal(); }); countDown.Wait(50); Assert.AreEqual(mouseEvents.Count, 1); if (a == DSL.Def.Constant.LeftButton) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_LBUTTONDOWN); } else if (a == DSL.Def.Constant.MiddleButton) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_MBUTTONDOWN); } else if (a == DSL.Def.Constant.RightButton) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_RBUTTONDOWN); } else if (a == DSL.Def.Constant.X1Button) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_XBUTTONDOWN); Assert.IsTrue(mouseEvents[0].Item2.mouseData.asXButton.isXButton1); } else if (a == DSL.Def.Constant.X2Button) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_XBUTTONDOWN); Assert.IsTrue(mouseEvents[0].Item2.mouseData.asXButton.isXButton2); } Assert.IsTrue(res is State0); } } } }
protected override void Start() { Log.L("按下 A/D 切换状态"); State1 s1 = new State1(); State2 s2 = new State2(); fsm.SubscribeState(s1); fsm.enterState = s1; fsm.SubscribeState(s2); // fsm.exitState = s2; var val = fsm.CreateConditionValue <bool>("bool", true); var t1 = fsm.CreateTransition(s1, s2); var t2 = fsm.CreateTransition(s2, s1); t1.BindCondition(fsm.CreateCondition <bool>("bool", false, CompareType.Equals)); t2.BindCondition(fsm.CreateCondition <bool>(val, true, CompareType.Equals)); fsm.Start(); }
public void Transition1_1_RRTest() { using (var countDown = new CountdownEvent(1)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDef = new List <OnButtonGestureDefinition>() { new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(true); }, DSL.Def.Constant.RightButton, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { countDown.Signal(); }, (ctx) => { Assert.Fail(); }, (ctx) => { Assert.Fail(); }) }; foreach (var b in TestDef.Constant.Buttons) { countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Def.Constant.RightButtonDown, gestureDef, new List <IfButtonGestureDefinition>()); var ev = Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause); var res = S1.Input(ev, new Point()); if (a == b) { Assert.IsTrue(res.NextState is State3); Assert.IsTrue(S1.T1[(Def.Event.IDoubleActionSet)ev].SequenceEqual(((State3)res.NextState).T1)); Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsTrue(res.NextState is State1); Assert.IsFalse(countDown.Wait(50)); } } } } } }
public RepeatStateTree2(Player startPlayer = Player.Max) { A.CallTo(() => EndState1.ToString()).Returns(nameof(EndState1)); A.CallTo(() => State1.ToString()).Returns(nameof(State1)); A.CallTo(() => State2.ToString()).Returns(nameof(State2)); A.CallTo(() => State2.ToString()).Returns(nameof(State3)); A.CallTo(() => RootState.ToString()).Returns(nameof(RootState)); A.CallTo(() => RootState.Turn).Returns(startPlayer); A.CallTo(() => State1.Turn).Returns(startPlayer.GetReversePlayer()); A.CallTo(() => State2.Turn).Returns(startPlayer.GetReversePlayer()); A.CallTo(() => State3.Turn).Returns(startPlayer); A.CallTo(() => EndState1.Turn).Returns(startPlayer.GetReversePlayer()); RootState.SetNeigbors(State1, State2); EndState1.SetAsEndState(); State1.SetNeigbor(State3); State2.SetNeigbor(State3); State3.SetNeigbor(EndState1); }
private void Start() { fsm = Framework.env1.modules.CreateModule <FsmModule>(); State1 s1 = new State1(); State2 s2 = new State2(); fsm.SubscribeState(s1); fsm.enterState = s1; fsm.SubscribeState(s2); // fsm.exitState = s2; var val = fsm.CreateConditionValue <bool>("bool", true); var t1 = fsm.CreateTransition(s1, s2); var t2 = fsm.CreateTransition(s2, s1); t1.BindCondition(fsm.CreateCondition <bool>("bool", false, CompareType.Equals)); t2.BindCondition(fsm.CreateCondition <bool>(val, true, CompareType.Equals)); fsm.Start(); }
public void Transition2_0_RRTest() { using (var countDown = new CountdownEvent(1)) { foreach (var a in TestDef.Constant.SingleTriggerButtons) { var gestureDef = new List <OnButtonGestureDefinition>() { new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(true); }, DSL.Def.Constant.RightButton, a as DSL.Def.AcceptableInIfButtonClause, null, (ctx) => { countDown.Signal(); }, null) }; foreach (var b in TestDef.Constant.Buttons) { countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Def.Constant.RightButtonDown, gestureDef, new List <IfButtonGestureDefinition>()); var S2 = S1.S2; var ev = Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause); var res = S2.Input(ev, new Point()); Assert.IsTrue(res.NextState is State2); if (a == b) { Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsFalse(countDown.Wait(50)); } } } } } }
public void Transition1_3_RRTest() { using (var countDown = new CountdownEvent(2)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDef = new List <IfButtonGestureDefinition>() { new IfButtonGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { Assert.Fail(); }, (ctx) => { countDown.Signal(); }, (ctx) => { countDown.Signal(); }) }; foreach (var b in TestDef.Constant.DoubleTriggerButtons) { countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(new StateGlobal(), gestureDef); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), new List <OnButtonGestureDefinition>(), gestureDef); var ev = Helper.Convert(b as DSL.Def.AcceptableInOnClause).GetPair(); var res = S1.Input((Def.Event.IEvent)ev, new Point()); if (a == b) { Assert.IsTrue(res.NextState is State0); Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsTrue(res.NextState is State1); Assert.IsFalse(countDown.Wait(50)); } } } } } }
/// <summary> /// Method om de state te wijzigen /// </summary> public void SetState(StateID stateID) { /** als we de stateID niet kennen als state: stop deze functie dan */ if (!states.ContainsKey(stateID)) { return; } /** als we ons al in een state bevinden: geef de state de mogelijkheid zich op te ruimen */ if (currentState != null) { currentState.Leave(); } /** we stellen de nieuwe currentState in */ currentState = states[stateID]; currIdInt = (int)stateID; /** we stellen de nieuwe currentState in */ currentState = states[stateID]; /** we geven de nieuwe state de mogelijkheid om zich zelf in te stellen */ currentState.Enter(); }
// Start is called before the first frame update void Start() { agent = GetComponent <NavMeshAgent>(); character = GetComponent <ThirdPersonCharacter>(); sphere = GetComponent <SphereCollider>(); anim = gameObject.GetComponent <Animator>(); mh = zombie.GetComponent <MutantHealth>(); agent.updatePosition = true; agent.updateRotation = false; waypoints = GameObject.FindGameObjectsWithTag("Waypoint"); waypointInd = Random.Range(0, waypoints.Length); state = MutantSight.State1.CHASE; target = GameObject.FindGameObjectWithTag("Player"); alive = true; heightMultiplyer = 1.36f; attacking = false; }
public void Transition2_1_RRTest() { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDef = new List <OnButtonGestureDefinition>() { new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(true); }, DSL.Def.Constant.RightButton, a as DSL.Def.AcceptableInIfButtonClause, null, (ctx) => { }, null) }; foreach (var b in TestDef.Constant.Buttons) { using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Def.Constant.RightButtonDown, gestureDef, new List <IfButtonGestureDefinition>()); var S2 = S1.S2; var ev = Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause); var res = S2.Input(ev, new Point()); if (a == b) { Assert.IsTrue(res.NextState is State3); Assert.IsTrue(S2.T1[(Def.Event.IDoubleActionSet)ev].SequenceEqual(((State3)res.NextState).T1)); } else { Assert.IsTrue(res.NextState is State2); } } } } }
/// <summary> /// Voeg een state toe aan de state machine /// LET OP! Alle components die de Class State.cs extenden (inheritance) die mogen in de Dictionary /// Daarom mogen AlertState.cs, AlertState.cs en FleeState.cs in de dictionary, aangezien zij State.CS extenden /// </summary> /// <param name="stateID">Een integer die komt uit de ENUM StateID (zie StateID in Guard.cs)</param> /// <param name="state">Een component die State.cs extend (inheritance)</param> public void AddState(StateID stateID, State1 state) { states.Add(stateID, state); }
private static void UpdateState(State1 s1) { Console.WriteLine("State1 Updated."); }
void Update() { if (mState1 == State1.ScaleUp) { if (mElapse < TimeWebScaleUp) { mTsWeb.localScale = (ScaleTarget * mElapse / TimeWebScaleUp) * Vector3.one; mElapse += Time.deltaTime; } else { mElapse = 0F; mState1 = State1.Shaking; } } else if (mState1 == State1.Shaking) { if (mElapse < TimeShake) { if (mElapseShakeInterval < IntervalShake) { mElapseShakeInterval += Time.deltaTime; } else { mTsWeb.localPosition += (mShakeDirects[mIdxCurShakePos % mShakeDirects.Length] * RangeShake); ++mIdxCurShakePos; mElapseShakeInterval = 0; } } else { mTsWeb.gameObject.SetActive(false); Pool_GameObj.RecycleGO(Prefab_GoSpriteWeb, mTsWeb.gameObject); Destroy(gameObject); } } if (!mState2_IsFadingOut) { if (mElapseFadeout < mTimeWaitFadeout) { mElapseFadeout += Time.deltaTime; } else { mState2_IsFadingOut = true; mElapseFadeout = 0F; } } else { mColorWeb.a = 1F - mElapseFadeout / TimeFadeOut; mSprWeb.color = mColorWeb; mElapseFadeout += Time.deltaTime; } }
private static void UpdateState(IAction act, State1 s1) { Console.WriteLine("State1 IAction Updated."); }
void Update() { if (mState1 == State1.ScaleUp) { if (mElapse < TimeWebScaleUp) { mTsWeb.localScale = Vector3.one;//(ScaleTarget * mElapse / TimeWebScaleUp) * mElapse += Time.deltaTime; } else { mElapse = 0F; mState1 = State1.Shaking; } } else if (mState1 == State1.Shaking) { if (mElapse < TimeShake) { if (mElapseShakeInterval < IntervalShake) { mElapseShakeInterval += Time.deltaTime; } else { //float elapse = 0F; //int curDirectIdx = 0; mTsWeb.localPosition += (mShakeDirects[mIdxCurShakePos % mShakeDirects.Length] * RangeShake); ++mIdxCurShakePos; mElapseShakeInterval = 0; //elapse += IntervalShake; } //yield return new WaitForSeconds(IntervalShake); } else { mTsWeb.gameObject.SetActive(false); Pool_GameObj.RecycleGO(Prefab_GoSpriteWeb, mTsWeb.gameObject); Destroy(gameObject); } } if (!mState2_IsFadingOut) { if (mElapseFadeout < mTimeWaitFadeout) { mElapseFadeout += Time.deltaTime; } else { mState2_IsFadingOut = true; mElapseFadeout = 0F; } } else { mColorWeb.a = 1F - mElapseFadeout / TimeFadeOut; mSprWeb.color = mColorWeb; //c.a = 0F; //mSprWeb.color = c; mElapseFadeout += Time.deltaTime; } }