public void Update(BehaviourStateMachine stateMachine) { for (int i = 1; i <= memoryInterruptions.Count; ++i) { var it = memoryInterruptions[i - 1]; MemoryEvent ev = stateMachine.memory.SearchInMemory(it.eventType); if (ev != null && ev.GetState() == it.eventState) { //Debug.Log(i + "; " + it.eventType + "; " + it.eventState); stateMachine.target = ev; if (lastInterruptionType != i) { lastInterruptionType = i; stateMachine.SetCurrentBehaviour(it.entry); } return; } } { //Debug.Log("neutral"); stateMachine.target = null; if (lastInterruptionType != 0) { lastInterruptionType = 0; stateMachine.SetCurrentBehaviour(neutralEntry); } } }
void Init() { //-----初始化状态机---------- MMachine = new BehaviourStateMachine(); HeroIdleState idleState = new HeroIdleState(gameObject); MMachine.AddState(idleState); HeroMoveState moveState = new HeroMoveState(gameObject); MMachine.AddState(moveState); HeroKickState kickState = new HeroKickState(gameObject); MMachine.AddState(kickState); //-----end---------------- //----初始化角色位置 MCurCoordinate = new SGridCoordinate(4, 0); Vector3 heroPosition = Definition.GridToWorld(MCurCoordinate.x, MCurCoordinate.z); //heroPosition.y += MHeroHeight / 2f; transform.position = heroPosition; //--------------------- }
public override void Render(GameTime gameTime, SpriteBatch _spriteBatch) { List <Vector2> randomVecList = Game1.CalculateRenderPosition(Position); foreach (Vector2 position in Game1.CalculateRenderPosition(Position)) { Game1.FishSprites.RenderFish((float)gameTime.TotalGameTime.TotalSeconds + AnimationOfset, _spriteBatch, velocity, position, TextureNumber); BehaviourStateMachine.Render(gameTime, _spriteBatch, position); } }
public HeroBaseState(GameObject noum) { if (noum != null) { Noumenon = noum; NoumenonT = noum.transform; MHeroController = noum.GetComponent <HeroController>(); MMachine = MHeroController.MMachine; MCharacter = noum.GetComponent <CharacterController>(); MHeroAnimator = noum.GetComponent <HeroAnimatorController>(); } }
void Awake() { jumpMachine = new BehaviourStateMachine <IJump, JumpStates>(new Dictionary <JumpStates, IBehaviourState <IJump, JumpStates> > { { JumpStates.OnGround, new OnGroundState() }, { JumpStates.Jump, new JumpState() }, { JumpStates.AirTime, new AirTimeState() }, { JumpStates.Falling, new FallingState() } }, this); jumpMachine.ChangeState(JumpStates.OnGround); rigidbody = gameObject.GetComponent <Rigidbody>(); }
void Awake() { movementMachine = new BehaviourStateMachine <IMove, MovementState>(new Dictionary <MovementState, IBehaviourState <IMove, MovementState> > { { MovementState.NotMoving, new NotMovingState() }, { MovementState.Acceleration, new AccelerationState() }, { MovementState.MaxSpeed, new MaxSpeedState() }, { MovementState.Deacceleration, new DeaccelerationState() } }, this); movementMachine.ChangeState(MovementState.NotMoving); m_rigidBody = gameObject.GetComponent <Rigidbody>(); }
public override void Render(GameTime gameTime, SpriteBatch _spriteBatch) { foreach (Vector2 position in Game1.CalculateRenderPosition(Position)) { Game1.SharkSprites.RenderFish((float)gameTime.TotalGameTime.TotalSeconds + AnimationOfset, _spriteBatch, velocity, position, TextureNumber); BehaviourStateMachine.Render(gameTime, _spriteBatch, position); if (Settings.RenderBehaviour) { foreach (SteeringBehaviour behaviour in steeringBehaviours) { //behaviour.Render(gameTime, _spriteBatch, position); } //BehaviourUtil.RenderVector(_spriteBatch, velocity, position, 0.01, Color.Red); } } }
void InitMachine(BehaviourStateMachine machine) { machine.data = inputData; machine.memory = memory; machine.character = GetComponentInParent <CharacterStateController>(); }