public static FSMStateMachine GetCharacterEditorFSM(Creature owner) { FSMTranslationMap translationMap = new FSMTranslationMap(); DeadState dead = new DeadState(owner); AttackState attackState = new AttackState(owner); IdleState idle = new IdleState(owner); WalkState walk = new WalkState(owner); HitState hitState = new HitState(owner); RunState runState = new RunState(owner); HitMoveState hitMoveState = new HitMoveState(owner); HitFlyState hitFlyState = new HitFlyState(owner); translationMap.addState(dead); translationMap.addState(idle); translationMap.addState(walk); translationMap.addState(runState); translationMap.addState(hitState); translationMap.addState(hitMoveState); translationMap.addState(attackState); translationMap.addState(hitFlyState); translationMap.MixAll(); translationMap.check(); FSMStateMachine fsm = new FSMStateMachine(translationMap); return(fsm); }
void MakeFSM() { PatrolState patrol = new PatrolState(); ChaseState chase = new ChaseState(); AttackState attack = new AttackState(); DeadState dead = new DeadState(); IdleState idle = new IdleState(); MoveState move = new MoveState(); patrol.AddTransition(Transition.SawEnemy, chase); patrol.AddTransition(Transition.NoHP, dead); chase.AddTransition(Transition.LostEnemy, patrol); chase.AddTransition(Transition.ReachEnemy, attack); chase.AddTransition(Transition.NoHP, dead); attack.AddTransition(Transition.LostEnemy, patrol); attack.AddTransition(Transition.SawEnemy, chase); attack.AddTransition(Transition.NoHP, dead); AddState(StateID.Patrol, patrol); AddState(StateID.Chase, chase); AddState(StateID.Attack, attack); AddState(StateID.Dead, dead); m_stateMachine.Start(patrol); }
void Start() { Initialize <States>(); ChangeState(States.Intro); // Find other player GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { if (player.name == "Klaus") { target = player.transform; target.GetComponentInChildren <DeadState>().SuscribeOnStart(OnPlayerDead); break; } } foreach (Difficulty difficulty in difficulties) { foreach (ObstaclesGroup group in difficulty.obstaclesPrefabs) { group.CreatePool <ObstaclesGroup>(1); } } // Set death time DeadState state = target.GetComponentInChildren <DeadState>(); state.deathTime = timeToRevive; }
virtual public void InitState() { { State state = new PlayerIdleState(); state.Init(this); _stateMap[eStateType.IDLE] = state; } { State state = new PathfindingMoveState(); state.Init(this); _stateMap[eStateType.MOVE] = state; } { State state = new AttackState(); state.Init(this); _stateMap[eStateType.ATTACK] = state; } { State state = new DamagedState(); state.Init(this); _stateMap[eStateType.DAMAGED] = state; } { State state = new DeadState(); state.Init(this); _stateMap[eStateType.DEAD] = state; } _state = _stateMap[eStateType.IDLE]; }
public StateMachine(Enemy t_enemy) { m_wanderState = new WanderState(t_enemy, this); m_combatState = new CombatState(t_enemy, this); m_deadState = new DeadState(t_enemy); m_currentState = m_wanderState; }
virtual protected void InitState() { { State state = new IdleState(); state.Init(this); _stateMap[eStateType.IDLE] = state; } { State state = new MoveState(); state.Init(this); _stateMap[eStateType.MOVE] = state; } { State state = new AttackState(); state.Init(this); _stateMap[eStateType.ATTACK] = state; } { State state = new DamageState(); state.Init(this); _stateMap[eStateType.DAMAGE] = state; } { State state = new DeadState(); state.Init(this); _stateMap[eStateType.DEAD] = state; } _state = _stateMap[eStateType.IDLE]; }
void InitFSM() { IdleState idleState = new IdleState(gameObject); RunState runState = new RunState(gameObject); ThrowState throwState = new ThrowState(gameObject); DeadState deadState = new DeadState(gameObject); // 注册切换条件 对应的 状态 idleState.AddTransition(FSMTransition.IdleToRun, FSMStateId.Run); runState.AddTransition(FSMTransition.RunToIdle, FSMStateId.Idle); idleState.AddTransition(FSMTransition.IdleToThrow, FSMStateId.Throw); runState.AddTransition(FSMTransition.RunToThrow, FSMStateId.Throw); throwState.AddTransition(FSMTransition.ThrowToIdle, FSMStateId.Idle); idleState.AddTransition(FSMTransition.IdleToDead, FSMStateId.Dead); runState.AddTransition(FSMTransition.RunToDead, FSMStateId.Dead); throwState.AddTransition(FSMTransition.ThrowToDead, FSMStateId.Dead); system.AddState(idleState); system.AddState(runState); system.AddState(throwState); system.AddState(deadState); system.Start(FSMStateId.Idle); }
protected override void BuildFSM() { //Other States Here PatrolState patrol = new PatrolState(this); patrol.AddTransitionState(FSMStateID.Investigate, FSMTransitions.HeardPlayer); patrol.AddTransitionState(FSMStateID.Shoot, FSMTransitions.SawPlayer); AddFSMState(patrol); InvestigateState investigate = new InvestigateState(this); investigate.AddTransitionState(FSMStateID.Patrol, FSMTransitions.FoundNothing); investigate.AddTransitionState(FSMStateID.Shoot, FSMTransitions.SawPlayer); AddFSMState(investigate); ShootState shoot = new ShootState(); shoot.AddTransitionState(FSMStateID.Investigate, FSMTransitions.PlayerOutOfRange); AddFSMState(shoot); DeadState dead = new DeadState(); AddFSMState(dead); }
/// <summary> /// 获取状态 /// </summary> /// <param name="AIState"></param> /// <returns></returns> private StateBase GetState(AIStateType AIState) { if (this.m_StateDic.ContainsKey(AIState)) { return(this.m_StateDic[AIState]); } StateBase state; switch (AIState) { case AIStateType.Attack: state = new AttackState(this.m_ActorBev, this.m_ActorAI); break; case AIStateType.Dead: state = new DeadState(this.m_ActorBev, this.m_ActorAI); break; case AIStateType.Hurt: state = new HurtState(this.m_ActorBev, this.m_ActorAI); break; case AIStateType.Idle: state = new IdleState(this.m_ActorBev, this.m_ActorAI); break; default: Debug.Log(AIState.ToString() + " not exsit "); return(null); } this.m_StateDic.Add(AIState, state); return(state); }
private void Start() { _instance = this; AvatarView = GetComponent <AvatarView>(); if (Application.platform == RuntimePlatform.Android) { _playerState = new AndroidPlayerState(this); } else { if (XmlSceneManager.Instance.ControlMode == XmlSceneManager.ControlModeEnum.PcControl) { _playerState = new PcPlayerState(this); } else { _playerState = new AndroidPlayerState(this); } } _deadState = new DeadState(this); _currentState = _playerState; _characterController = GetComponent <CharacterController>(); _clickPointAuxiliaryPrefab = AssetTool.LoadAsset_Database_Or_Bundle( AssetTool.Assets__Resources_Ours__Prefabs_ + "AuxiliaryPrefabs/ClickPointAuxiliary.prefab", "Prefabs", "auxiliaryprefabs_bundle", "ClickPointAuxiliary"); _clickPointObject = Instantiate(_clickPointAuxiliaryPrefab) as GameObject; }
private void initStates() { var preference = playerData.PreferredPlayerState; var states = preference.GetSortedStates(); CurrentState = ParseEnum <PlayerState>(states[0]); preference = playerData.PreferredIdleState; states = preference.GetSortedStates(); CurrentIdleState = ParseEnum <IdleState>(states[0]); preference = playerData.PreferredBallState; states = preference.GetSortedStates(); CurrentBallState = ParseEnum <BallState>(states[0]); preference = playerData.PreferredEnemyState; states = preference.GetSortedStates(); CurrentEnemyState = ParseEnum <EnemyState>(states[0]); preference = playerData.PreferredKickState; states = preference.GetSortedStates(); CurrentKickState = ParseEnum <KickState>(states[0]); preference = playerData.PreferredDeadState; states = preference.GetSortedStates(); CurrentDeadState = ParseEnum <DeadState>(states[0]); }
private void ConstructFSM() //初始化拥有哪些状态,并为拥有的状态设置转化和状态ID { PatrolState tPatrolState = new PatrolState(wayPoints); tPatrolState.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); tPatrolState.AddTransition(Transition.NoHealth, FSMStateID.Dead); ChaseState tChaseState = new ChaseState(wayPoints); tChaseState.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); tChaseState.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); tChaseState.AddTransition(Transition.NoHealth, FSMStateID.Dead); AttackState tAttackState = new AttackState(wayPoints); tAttackState.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); tAttackState.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); tAttackState.AddTransition(Transition.NoHealth, FSMStateID.Dead); DeadState tDeadState = new DeadState(); tDeadState.AddTransition(Transition.NoHealth, FSMStateID.Dead); AddFSMState(tPatrolState); AddFSMState(tPatrolState); AddFSMState(tPatrolState); AddFSMState(tPatrolState); Events.AddEvent(EventSign.GAME_START, DestroySelf, this); Events.Send(EventSign.GAME_START, new EventArg("123")); }
protected override void ConstructFSM() { DeadState dead = new DeadState(this); DreadnovaSpawnState spawn = new DreadnovaSpawnState(this); DreadnovaShieldState shield = new DreadnovaShieldState(this); DreadnovaEscapeState escape = new DreadnovaEscapeState(this); DreadnovaAttackState attack = new DreadnovaAttackState(this); dead.AddTransition(Transition.Reset, FSMStateID.Spawned); spawn.AddTransition(Transition.Defend, FSMStateID.Defend); spawn.AddTransition(Transition.Reset, FSMStateID.Spawned); spawn.AddTransition(Transition.Attack, FSMStateID.Attacking); //shield.AddTransition(Transition.Attack, FSMStateID.Attacking); shield.AddTransition(Transition.NoShield, FSMStateID.Running); shield.AddTransition(Transition.NoHealth, FSMStateID.Dead); shield.AddTransition(Transition.Reset, FSMStateID.Spawned); escape.AddTransition(Transition.NoHealth, FSMStateID.Dead); escape.AddTransition(Transition.Reset, FSMStateID.Spawned); attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); attack.AddTransition(Transition.Reset, FSMStateID.Spawned); AddFSMState(spawn); AddFSMState(shield); AddFSMState(escape); AddFSMState(attack); AddFSMState(dead); }
private void MakeFSM() { IdleState idle = new IdleState(); idle.AddTransition(Transition.Walk, StateID.Walk); idle.AddTransition(Transition.Jump, StateID.Jump); idle.AddTransition(Transition.Die, StateID.Die); WalkState walk = new WalkState(path); walk.AddTransition(Transition.Idle, StateID.Idle); walk.AddTransition(Transition.Jump, StateID.Jump); walk.AddTransition(Transition.Die, StateID.Die); JumpState jump = new JumpState(); jump.AddTransition(Transition.Idle, StateID.Idle); jump.AddTransition(Transition.Die, StateID.Die); DeadState die = new DeadState(); fsm = new FSMSystem(); fsm.AddState(idle); fsm.AddState(walk); fsm.AddState(jump); fsm.AddState(die); }
private void Start() { GetBalaIndex(); GetRigidBody().drag = GetPlayerDeceleration(); life = 1; score = 0; SetCanShoot(true); damageable = true; matchController = FindObjectOfType <MatchController>(); //matchController.AddPlayer(this); spawnPoint = matchController.GetSpawnPoint(this); teamId = 5; movementSM = new StateMachine(); groundedState = new GroundedState(this, movementSM); shootingState = new ShootingState(this, movementSM); shieldState = new ShieldState(this, movementSM); deadState = new DeadState(this, movementSM); stunState = new StunState(this, movementSM); feederState = new FeederState(this, movementSM); movementSM.Initialize(shootingState); }
protected override void BuildFSM() { PatrolState patrol = new PatrolState(PatrolPoints, navAgent, agroDistance); patrol.AddTransitionState(FSMStateID.Shoot, FSMTransitions.SawPlayer); patrol.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); ShootState shoot = new ShootState(retreatDistance, spawnerScript); shoot.AddTransitionState(FSMStateID.Patrol, FSMTransitions.PlayerOutOfRange); shoot.AddTransitionState(FSMStateID.Retreat, FSMTransitions.PlayerTooClose); shoot.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); RetreatState retreat = new RetreatState(navAgent, retreatDistance); retreat.AddTransitionState(FSMStateID.Shoot, FSMTransitions.CloserDistanceReached); retreat.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); DeadState dead = new DeadState(); AddFSMState(patrol); AddFSMState(shoot); AddFSMState(retreat); AddFSMState(dead); }
private void MakeFSM(Soldier soldier) { LookupState lookupState = new LookupState(soldier.gameObject); lookupState.AddTransition(Transition.FoundEnemy, StateID.ForwardEnemy); lookupState.AddTransition(Transition.HpEmpty, StateID.Dead); ForwardState forwardState = new ForwardState(soldier.gameObject); forwardState.AddTransition(Transition.LostEnemy, StateID.LookupEnemy); forwardState.AddTransition(Transition.CanAttackEnemy, StateID.AttackEnemy); forwardState.AddTransition(Transition.HpEmpty, StateID.Dead); AttackState attackState = new AttackState(soldier.gameObject); attackState.AddTransition(Transition.LostEnemy, StateID.LookupEnemy); attackState.AddTransition(Transition.HpEmpty, StateID.Dead); DeadState deadState = new DeadState(soldier.gameObject); deadState.AddTransition(Transition.HpRemain, StateID.LookupEnemy); fsm = new FSMSystem(); fsm.AddState(lookupState); fsm.AddState(forwardState); fsm.AddState(attackState); fsm.AddState(deadState); }
private void ConstructFSM() { //Get the list of points //pointList = GameObject.FindGameObjectsWithTag("PatrolPoint"); //Transform[] waypoints = new Transform[pointList.Length]; //int i = 0; //foreach(GameObject obj in pointList) //{ // waypoints[i] = obj.transform; // i++; //} int pointlength = Random.Range(3, 5); Debug.Log("pointlength = " + pointlength); Transform[] waypoints = new Transform[pointlength]; float maxdistance = 50; float mindistance = -30; GameObject partpointparent = new GameObject(); partpointparent.transform.position = role.transform.position; partpointparent.name = role.name + "[partolpoints]"; for (int i = 0; i < pointlength; i++) { Vector3 pos = new Vector3(role.transform.position.x + CreatPatrolRange(maxdistance, mindistance), 0, role.transform.position.z + CreatPatrolRange(maxdistance, mindistance)); GameObject go = new GameObject(); go.transform.position = pos; go.transform.parent = partpointparent.transform;; waypoints[i] = go.transform; } Debug.Log("waypoints length -> " + waypoints.Length); PatrolState patrol = new PatrolState(waypoints); patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead); ChaseState chase = new ChaseState(waypoints); chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); chase.AddTransition(Transition.NoHealth, FSMStateID.Dead); AttackState attack = new AttackState(waypoints); attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); DeadState dead = new DeadState(); dead.AddTransition(Transition.NoHealth, FSMStateID.Dead); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); }
void Awake() { _spawner = GetComponentInParent <Spawner>(); _customerEvents = GetComponent <CustomerEvents>(); var waitingState = new WaitingState(this, _customerEvents); var buyingState = new BuyingState(_buyTime, this, _customerEvents); var finishedState = new FinishedState(this, _customerEvents, _spawner, point); var deadState = new DeadState(this, _spawner); _stateMachine = new StateMachine(); At(waitingState, buyingState, IsCustomerCanBuy()); At(buyingState, waitingState, NotIsCustomerCanBuy()); At(waitingState, deadState, IsDead()); At(buyingState, deadState, IsDead()); At(buyingState, finishedState, IsFinishedBuying()); _stateMachine.SetState(waitingState); void At(IState from, IState to, Func <bool> condition) => _stateMachine.AddTransition(from, to, condition); Func <bool> IsCustomerCanBuy() => () => _canBuy; Func <bool> NotIsCustomerCanBuy() => () => !_canBuy; Func <bool> IsFinishedBuying() => () => _finishedBuying; Func <bool> IsDead() => () => _isDead; }
private void ConstructFSM() { //Get the list of points pointList = GameObject.FindGameObjectsWithTag("WanderPoint"); Transform[] waypoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { waypoints[i] = obj.transform; i++; } //Add Transition and State Pairs PatrolState patrol = new PatrolState(waypoints, this); //If the tank sees the player while patrolling, move to chasing state patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); //If the tank loses health while patrolling, move to dead state patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead); patrol.AddTransition(Transition.HalfHealth, FSMStateID.Rage); ChaseState chase = new ChaseState(waypoints, this); //If the tank loses the player while chasing, move to patrol state chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); //If the tank reaches the player while attacking, move to attack state chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); //If the tank loses health while patrolling, move to dead state chase.AddTransition(Transition.NoHealth, FSMStateID.Dead); chase.AddTransition(Transition.HalfHealth, FSMStateID.Rage); AttackState attack = new AttackState(waypoints, this); //If the tank loses the player while attacking, move to patrol state attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); //If the player is within sight while attacking, move to chase state attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); //If the tank loses health while attacking, move to dead state attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); attack.AddTransition(Transition.HalfHealth, FSMStateID.Rage); DeadState dead = new DeadState(this); //When there is no health, go to dead state dead.AddTransition(Transition.NoHealth, FSMStateID.Dead); RageState rage = new RageState(this); rage.AddTransition(Transition.NoHealth, FSMStateID.Dead); rage.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); //Add states to the state list AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); AddFSMState(rage); }
//Construct the Finite State Machine for the AI Car behavior private void ConstructFSM() { //Get the list of points pointList = GameObject.FindGameObjectsWithTag("WandarPoints"); Transform[] waypoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { waypoints[i] = obj.transform; i++; } PatrolState patrol = new PatrolState(waypoints); patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead); ChaseState chase = new ChaseState(waypoints); chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); chase.AddTransition(Transition.NoHealth, FSMStateID.Dead); AttackState attack = new AttackState(waypoints); attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); DeadState dead = new DeadState(); dead.AddTransition(Transition.NoHealth, FSMStateID.Dead); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); }
protected override void BuildFSM() { PatrolState patrol = new PatrolState(PatrolPoints, navAgent, agroDistance); patrol.AddTransitionState(FSMStateID.Shoot, FSMTransitions.SawPlayer); patrol.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); ShootState shoot = new ShootState(chargeDistance, spawnerScript); shoot.AddTransitionState(FSMStateID.Patrol, FSMTransitions.PlayerOutOfRange); shoot.AddTransitionState(FSMStateID.Chase, FSMTransitions.PlayerTooClose); shoot.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); ChaseState chase = new ChaseState(navAgent, chargeDistance); chase.AddTransitionState(FSMStateID.Shoot, FSMTransitions.PlayerOutOfRange); chase.AddTransitionState(FSMStateID.Dead, FSMTransitions.OutOfHealth); DeadState dead = new DeadState(); AddFSMState(patrol); AddFSMState(shoot); AddFSMState(chase); AddFSMState(dead); }
private void ConstructFSM() { //Get the list of points pointList = GameObject.FindGameObjectsWithTag("WandarPoint"); Transform[] waypoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { waypoints[i] = obj.transform; i++; } PatrolState patrol = new PatrolState(waypoints, this); patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); patrol.AddTransition(Transition.LowHealth, FSMStateID.Healing); patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead); patrol.AddTransition(Transition.HasBoredom, FSMStateID.Bored); ChaseState chase = new ChaseState(waypoints, this); chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); chase.AddTransition(Transition.LowHealth, FSMStateID.Healing); chase.AddTransition(Transition.NoHealth, FSMStateID.Dead); AttackState attack = new AttackState(waypoints, this); attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); attack.AddTransition(Transition.LowHealth, FSMStateID.Healing); attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); DeadState dead = new DeadState(); dead.AddTransition(Transition.NoHealth, FSMStateID.Dead); HealState heal = new HealState(waypoints, this); heal.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); heal.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); heal.AddTransition(Transition.NoHealth, FSMStateID.Dead); BoredState bored = new BoredState(waypoints, this); bored.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); bored.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); bored.AddTransition(Transition.LowHealth, FSMStateID.Healing); bored.AddTransition(Transition.NoHealth, FSMStateID.Dead); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); AddFSMState(heal); AddFSMState(bored); }
protected virtual void BuildFSM() { //Other States Here DeadState dead = new DeadState(); AddFSMState(dead); }
void Awake () { wanderState = new WanderState (wanderTimeMin, wanderTimeMax, wanderSpeed, wanderRadius); idleState = new IdleState (idleTime); chaseState = new ChaseState (chaseTime, chaseSpeed); attackState = new AttackState (); deadState = new DeadState (); leaveAltarState = new LeaveAltarState (); }
private void ConstructFSM() { //Get the list of points // pointList = GameObject.FindGameObjectsWithTag("WandarPoint"); var pointList = gameObject.transform.Cast <Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray(); Transform[] waypoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { obj.GetComponent <Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5, Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5); waypoints[i] = obj.transform; // waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5, // Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5); i++; } PatrolState patrol = new PatrolState(waypoints); patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing); patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead); patrol.SetStateDistances(chaseStartDist, attackStartDist); patrol.SetSpeed(speed / 2, rotationSpeed / 2); patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z); ChaseState chase = new ChaseState(waypoints); chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling); chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking); chase.AddTransition(FSMTransition.NoHealth, StateID.Dead); chase.SetStateDistances(chaseStartDist, attackStartDist); chase.SetSpeed(speed, rotationSpeed); AttackState attack = new AttackState(waypoints); attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling); attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing); attack.AddTransition(FSMTransition.NoHealth, StateID.Dead); attack.SetStateDistances(chaseStartDist, attackStartDist); attack.SetSpeed(speed, rotationSpeed); attack.kamikaze = this.kamikaze; DeadState dead = new DeadState(); dead.AddTransition(FSMTransition.NoHealth, StateID.Dead); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); //Start patrolling at given points patrol.FindNextPoint(); }
private DeadState() { if (_instance != null) { return; } _instance = this; }
private void ConstructFSM() { //Get the list of points pointList = GameObject.FindGameObjectsWithTag("WandarPoint"); Transform[] waypoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { waypoints[i] = obj.transform; i++; } PatrolState patrol = new PatrolState(waypoints); patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead); patrol.AddTransition(Transition.Panic, FSMStateID.Fleeing); ChaseState chase = new ChaseState(waypoints); chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); chase.AddTransition(Transition.NoHealth, FSMStateID.Dead); chase.AddTransition(Transition.Panic, FSMStateID.Fleeing); AttackState attack = new AttackState(waypoints); attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); attack.AddTransition(Transition.Panic, FSMStateID.Fleeing); attack.AddTransition(Transition.TooCloseTooPlayer, FSMStateID.Evade); DeadState dead = new DeadState(); dead.AddTransition(Transition.NoHealth, FSMStateID.Dead); FleeState flee = new FleeState(); flee.AddTransition(Transition.NoHealth, FSMStateID.Dead); flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); EvadeState evade = new EvadeState(); evade.AddTransition(Transition.NoHealth, FSMStateID.Dead); evade.AddTransition(Transition.OutOfEvadingRange, FSMStateID.Patrolling); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); AddFSMState(flee); AddFSMState(evade); }
private void ConstructFSM() { PatrolState patrol = new PatrolState(this); patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); patrol.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead); patrol.AddTransition(Transition.GotBored, FSMStateID.Bored); patrol.AddTransition(Transition.WantsTimeOff, FSMStateID.OffDuty); patrol.AddTransition(Transition.Hurt, FSMStateID.Repairing); patrol.AddTransition(Transition.WantsToHide, FSMStateID.Hiding); ChaseState chase = new ChaseState(this); chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); chase.AddTransition(Transition.NoHealth, FSMStateID.Dead); chase.AddTransition(Transition.Hurt, FSMStateID.Repairing); AttackState attack = new AttackState(this); attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); attack.AddTransition(Transition.Hurt, FSMStateID.Repairing); OffDutyState offduty = new OffDutyState(rigidbody.transform, this); offduty.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); offduty.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling); offduty.AddTransition(Transition.NoHealth, FSMStateID.Dead); offduty.AddTransition(Transition.WantsToHide, FSMStateID.Hiding); RepairState repair = new RepairState(this); repair.AddTransition(Transition.Healed, FSMStateID.Patrolling); repair.AddTransition(Transition.NoHealth, FSMStateID.Dead); HideState hide = new HideState(this); hide.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); hide.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling); DeadState dead = new DeadState(); dead.AddTransition(Transition.NoHealth, FSMStateID.Dead); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(offduty); AddFSMState(repair); AddFSMState(hide); AddFSMState(dead); }
void OnEnable() { if (object.ReferenceEquals(KlausDead, null)) { KlausDead = GameObject.FindObjectOfType <DeadState>(); KlausMove = GameObject.FindObjectOfType <MoveState>(); } KlausDead.onRespawn += OnDead; KlausMove.SuscribeOnJump(OnJump); }
public override CellState GetNextState(int neighborhoods) { if (neighborhoods == 2 || neighborhoods == 3) { return(this); } else { return(DeadState.GetInstance()); } }
void Awake() { patrolState = new PatrolState(this); chaseState = new ChaseState(this); attackState = new AttackState(this); deadState = new DeadState(this); alertState = new AlertState(this); koState = new KOState(this); chaseTarget = FindObjectOfType <PlayerController>().transform; }
public BasicMachine(Character character) : base(character) { // States StarState star = new StarState(character); EvadeState evade = new EvadeState(character); DeadState die = new DeadState(character); ChaseLifeState chase = new ChaseLifeState(character); // Add states this.states.Add(star); this.states.Add(evade); this.states.Add(die); this.states.Add(chase); this.initialState = this.currentState = star; }
public void Die() { myState = new DeadState(this); alive = false; }
public override void Update(double elapsedTime) { // update section velocitied for (int i = 1; i < sections.Count; i++) { (sections[i] as Sprite).setVelocity((sections[i-1] as Sprite).getVelocity()); (sections[i] as Sprite).Update(elapsedTime); } // check for collisions with snake and barriers if (Collide(sections.GetRange(1, sections.Count - 1)) != NO_COLLISION || Collide(levelManager.getBarriers()) != NO_COLLISION) { state = new DeadState(this); } // check for collisions with fruits int fruitHit = Collide(fruitManager.getFruits()); if (fruitHit != NO_COLLISION) { fruitManager.CollectFruit(fruitHit); } base.Update(elapsedTime); }
private void ConstructFSM() { //Get the list of points // pointList = GameObject.FindGameObjectsWithTag("WandarPoint"); var pointList = gameObject.transform.Cast<Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray(); Transform[] waypoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { obj.GetComponent<Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5, Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5); waypoints[i] = obj.transform; // waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5, // Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5); i++; } PatrolState patrol = new PatrolState(waypoints); patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing); patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead); patrol.SetStateDistances(chaseStartDist, attackStartDist); patrol.SetSpeed(speed / 2, rotationSpeed / 2); patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z); ChaseState chase = new ChaseState(waypoints); chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling); chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking); chase.AddTransition(FSMTransition.NoHealth, StateID.Dead); chase.SetStateDistances(chaseStartDist, attackStartDist); chase.SetSpeed(speed, rotationSpeed); AttackState attack = new AttackState(waypoints); attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling); attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing); attack.AddTransition(FSMTransition.NoHealth, StateID.Dead); attack.SetStateDistances(chaseStartDist, attackStartDist); attack.SetSpeed(speed, rotationSpeed); attack.kamikaze = this.kamikaze; DeadState dead = new DeadState(); dead.AddTransition(FSMTransition.NoHealth, StateID.Dead); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); //Start patrolling at given points patrol.FindNextPoint(); }
/// <summary> /// Initialize controlling state machine /// </summary> private void InitializeStateMachine() { //states IdleState idleState = new IdleState(); idleState.Parent = this; mStateMachine.AddState(idleState); WalkState walkState = new WalkState(); walkState.Parent = this; mStateMachine.AddState(walkState); /* RunState runState = new RunState(); runState.Parent = this; mStateMachine.AddState(runState); */ GetWalkTarget getWalkTargetState = new GetWalkTarget(); getWalkTargetState.Parent = this; mStateMachine.AddState(getWalkTargetState); SpawnInState spawnInState = new SpawnInState(); spawnInState.Parent = this; mStateMachine.AddState(spawnInState); SpawnOutState spawnOutState = new SpawnOutState(); spawnOutState.Parent = this; mStateMachine.AddState(spawnOutState); DeadState deadState = new DeadState(); deadState.Parent = this; mStateMachine.AddState(deadState); EatCarrotState eatCarrotState = new EatCarrotState(); eatCarrotState.Parent = this; mStateMachine.AddState(eatCarrotState); EatFlowerState eatFlowerState = new EatFlowerState(); eatFlowerState.Parent = this; mStateMachine.AddState(eatFlowerState); WinDanceState winDanceState = new WinDanceState(); winDanceState.Parent = this; mStateMachine.AddState(winDanceState); LostState lostState = new LostState(); lostState.Parent = this; mStateMachine.AddState(lostState); //transitions mStateMachine.AddTransition((int)CharacterEvents.To_Walk, idleState, walkState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, idleState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_Idle, walkState, idleState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, walkState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_Walk, getWalkTargetState, walkState); mStateMachine.AddTransition((int)CharacterEvents.To_Idle, getWalkTargetState, idleState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, spawnInState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_SpawnOut, getWalkTargetState, spawnOutState); mStateMachine.AddTransition((int)CharacterEvents.To_EatCarrot, getWalkTargetState, eatCarrotState); mStateMachine.AddTransition((int)CharacterEvents.To_EatFlower, getWalkTargetState, eatFlowerState); mStateMachine.AddTransition((int)CharacterEvents.To_Dead, spawnOutState, deadState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatCarrotState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatFlowerState, getWalkTargetState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, getWalkTargetState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, idleState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, walkState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnInState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnOutState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatFlowerState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatCarrotState, winDanceState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, idleState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, walkState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, getWalkTargetState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnInState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnOutState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatFlowerState, lostState); mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatCarrotState, lostState); #if (WINDOWS_PHONE && !SILVERLIGHT) mStateMachine.AddTransition((int)CharacterEvents.To_SpawnIn, deadState, spawnInState); #endif //mStateMachine.AddTransition((int)CharacterEvents.To_Run, walkState, runState); //mStateMachine.AddTransition((int)CharacterEvents.TimerElapsed, runState, walkState); // character starts in a spawn in state #if (WINDOWS_PHONE && !SILVERLIGHT) mStateMachine.StartState = deadState; #else mStateMachine.StartState = spawnInState; #endif }
/// <summary> /// 获取状态 /// </summary> /// <param name="AIState"></param> /// <returns></returns> private StateBase GetState(AIStateType AIState) { if (this.m_StateDic.ContainsKey(AIState)) { return this.m_StateDic[AIState]; } StateBase state; switch (AIState) { case AIStateType.Attack: state = new AttackState(this.m_ActorBev,this.m_ActorAI); break; case AIStateType.Dead: state = new DeadState(this.m_ActorBev, this.m_ActorAI); break; case AIStateType.Hurt: state = new HurtState(this.m_ActorBev, this.m_ActorAI); break; case AIStateType.Idle: state = new IdleState(this.m_ActorBev, this.m_ActorAI); break; default: Debug.Log(AIState.ToString() + " not exsit "); return null; } this.m_StateDic.Add(AIState, state); return state; }