protected FSMState(List<TransitionInfo> transitions, Dictionary<eTransition, TransitionInfo.eTransitionType> transitionType, FSMSystem fsm, eStateId stat) { this.stateId = stat; this._transition = transitions; this._transType = transitionType; this._fsm = fsm; }
public StateFollow(FSMSystem fms, Transform trans) { this.fms = fms; this.name = "follow"; this.transSelf = trans; transTarget = GameObject.FindGameObjectWithTag("Player").transform; characterController = transSelf.GetComponent <CharacterController>(); }
// Use this for initialization void Start () { this.fsm = new FSM.FSMSystem(this.gameObject); List<FSM.FSMState> states = new List<FSM.FSMState>(); List<FSM.TransitionInfo> trans = new List<FSM.TransitionInfo>(); Dictionary<FSM.eTransition, FSM.TransitionInfo.eTransitionType> transType = new Dictionary<FSM.eTransition,FSM.TransitionInfo.eTransitionType>(); trans.Add(new FSM.TransitionInfo(FSM.TransitionInfo.eTransitionType.NoneTransition, FSM.eStateId.Attack, FSM.eTransition.EnemyInTrigger, null)); transType.Add(FSM.eTransition.EnemyInTrigger, FSM.TransitionInfo.eTransitionType.AddChild); states.Add(new FSM.Idle(trans, transType, this.fsm)); trans.Clear(); transType.Clear(); states.Add(new FSM.Attack(trans, transType, this.fsm)); this.fsm.AddState(states); this.fsm.SetState(FSM.eStateId.Idle); }
private void makeFMS() { fms = new FSMSystem();//状态机管理系统 // StatePatrol statePatrol = new StatePatrol(fms, points,transform);//巡逻状态 // statePatrol.addTransition(ETransition.PATROL_TO_FOLLOW, "follow"); // statePatrol.addTransition(ETransition.PATROL_TO_ATTACK, "attack"); StateFollow stateFollow = new StateFollow(fms, transform);//跟随状态 stateFollow.addTransition(ETransition.FOLLOW_TO_ATTACK, "attack"); stateFollow.addTransition(ETransition.FOLLOW_TO_PATROL, "patrol"); StateAttack stateAttack = new StateAttack(fms, transform, firePoint, fireLight);//攻击状态 stateAttack.addTransition(ETransition.ATTACK_TO_FOLLOW, "follow"); stateAttack.addTransition(ETransition.ATTACK_PATROL, "patrol"); // fms.addState(statePatrol); fms.addState(stateFollow); fms.addState(stateAttack); }
public StateAttack(FSMSystem fms, Transform trans, Transform transFirePoint, Transform transFireLight) { this.fms = fms; this.name = "attack";//状态名字就叫攻击 this.transSelf = trans; transTarget = GameObject.FindGameObjectWithTag("Player").transform; characterController = transSelf.GetComponent <CharacterController>(); this.transFirePoint = transFirePoint; this.transFireLight = transFireLight; prefabBullet = Resources.Load("NewPrefabs/bullet") as GameObject; GameObject goBullet = GameObject.Find("Bullets_Monster1"); if (goBullet != null) { int num = goBullet.transform.childCount; transBullets = new Transform[num]; int index = 0; foreach (Transform t in goBullet.transform) { transBullets[index] = t; index++; } } }
public Idle(List<TransitionInfo> transitions, Dictionary<eTransition, TransitionInfo.eTransitionType> transitionType, FSMSystem fsm) : base(transitions, transitionType, fsm, eStateId.Idle) { }
private void SwitchStateTransition(FSMSystem fsm, FSMState state) { fsm.StatTransitTo(state, this.idDest, this.data); }
private void AddTransition(FSMSystem fsm, FSMState state) { fsm.StatAddChild(state, this.idDest, this.data); }
public void PerformTransition(FSMSystem fsm, FSMState state) { if (this.transitionType == eTransitionType.NoneTransition) return; this._transitions[(int)this.transitionType](fsm, state); }