private void JumpStateChanged(CharacterJumpStateMachine.States state) { if (state == CharacterJumpStateMachine.States.NoJump) { this.model.jumpPerformed.Value = 0; } else if (state == CharacterJumpStateMachine.States.DoJump) { this.model.jumpPerformed.Value = this.model.jumpPerformed.Value + 1; this.model.jumpLocked.Value = true; Observable.Timer (TimeSpan.FromMilliseconds (100)) .Subscribe (l => { Debug.Log("this.model.jumpLocked.Value = false;"); this.model.jumpLocked.Value = false; }); } }
public CharacterModel() { GameObject jumpStateMachineObje = new GameObject(); jumpStateMachine = jumpStateMachineObje.AddComponent <CharacterJumpStateMachine> (); jumpStateMachine.Init(); speed = new ReactiveProperty <Vector3>(_initialSpeed); moveIntention = new ReactiveProperty <MovementIntention>(MovementIntention.Stop); jumpIntention = new ReactiveProperty <JumpIntention>(JumpIntention.None); isOnTheGround = new ReactiveProperty <bool>(true); isNotOnTheGround = new ReactiveProperty <bool>(true); shouldJump = new ReactiveProperty <bool>(false); jumpLocked = new ReactiveProperty <bool>(false); jumpPerformed = new ReactiveProperty <int>(0); this.isOnTheGround.Subscribe((bool isGround) => { this.isNotOnTheGround.Value = !isGround; }); this.jumpIntention.Subscribe((JumpIntention intention) => { this.shouldJump.Value = this.ComputeShouldJump(); // ReactivePropertyは同じ値で更新されてもOnNextが呼ばれないのでfalseに戻す this.shouldJump.Value = false; }); this.shouldJump.Subscribe((bool should) => { this.jumpStateMachine.JumpExpectedTransition(); }); this.isNotOnTheGround.Subscribe((bool notGround) => { this.jumpStateMachine.LeftGroundTransition(); }); this.isNotOnTheGround.Subscribe((bool notGround) => { this.jumpStateMachine.LandedTransition(); }); }
public CharacterModel() { GameObject jumpStateMachineObje = new GameObject (); jumpStateMachine = jumpStateMachineObje.AddComponent<CharacterJumpStateMachine> (); jumpStateMachine.Init (); speed = new ReactiveProperty<Vector3>(_initialSpeed); moveIntention = new ReactiveProperty<MovementIntention>(MovementIntention.Stop); jumpIntention = new ReactiveProperty<JumpIntention>(JumpIntention.None); isOnTheGround = new ReactiveProperty<bool>(true); isNotOnTheGround = new ReactiveProperty<bool>(true); shouldJump = new ReactiveProperty<bool>(false); jumpLocked = new ReactiveProperty<bool>(false); jumpPerformed = new ReactiveProperty<int>(0); this.isOnTheGround.Subscribe ((bool isGround) => { this.isNotOnTheGround.Value = !isGround; }); this.jumpIntention.Subscribe ((JumpIntention intention) => { this.shouldJump.Value = this.ComputeShouldJump(); // ReactivePropertyは同じ値で更新されてもOnNextが呼ばれないのでfalseに戻す this.shouldJump.Value = false; }); this.shouldJump.Subscribe ((bool should) => { this.jumpStateMachine.JumpExpectedTransition(); }); this.isNotOnTheGround.Subscribe ((bool notGround) => { this.jumpStateMachine.LeftGroundTransition(); }); this.isNotOnTheGround.Subscribe ((bool notGround) => { this.jumpStateMachine.LandedTransition(); }); }
public override void Bind() { base.Bind(); _MovementIntentionProperty = new P<MovementIntention>(this, "MovementIntention"); _MovementStateProperty = new CharacterMovementStateMachine(this, "MovementState"); _JumpIntentionProperty = new P<JumpIntention>(this, "JumpIntention"); _JumpStateProperty = new CharacterJumpStateMachine(this, "JumpState"); _IsOnTheGroundProperty = new P<Boolean>(this, "IsOnTheGround"); _JumpLockedProperty = new P<Boolean>(this, "JumpLocked"); _JumpsPerformedProperty = new P<Int32>(this, "JumpsPerformed"); _CoinsCollectedProperty = new P<Int32>(this, "CoinsCollected"); _IsAliveProperty = new P<Boolean>(this, "IsAlive"); _IsInvulnarableProperty = new P<Boolean>(this, "IsInvulnarable"); _LivesProperty = new P<Int32>(this, "Lives"); _ShouldMoveLeftProperty = new P<Boolean>(this, "ShouldMoveLeft"); _ShouldMoveRightProperty = new P<Boolean>(this, "ShouldMoveRight"); _ShouldStopProperty = new P<Boolean>(this, "ShouldStop"); _ShouldJumpProperty = new P<Boolean>(this, "ShouldJump"); _IsNotOnTheGroundProperty = new P<Boolean>(this, "IsNotOnTheGround"); this.ResetShouldMoveLeft(); this.ResetShouldMoveRight(); this.ResetShouldStop(); this.ResetShouldJump(); this.ResetIsNotOnTheGround(); this._MovementStateProperty.GoLeft.AddComputer(_ShouldMoveLeftProperty); this._MovementStateProperty.GoRight.AddComputer(_ShouldMoveRightProperty); this._MovementStateProperty.Stop.AddComputer(_ShouldStopProperty); this._JumpStateProperty.JumpExpected.AddComputer(_ShouldJumpProperty); this._JumpStateProperty.LeftGround.AddComputer(_IsNotOnTheGroundProperty); this._IsOnTheGroundProperty.Subscribe(_JumpStateProperty.Landed); }