private void Start() { //IA2-P2 SetTeamData(); rb = this.gameObject.GetComponent <Rigidbody>(); _initialSpeed = 10; _navMeshAgent = GetComponent <NavMeshAgent>(); initPos = transform.position; sm = new StateMachine(); //Creo los estados var idle = new Idle_State(this); var move = new Move_State(this); var stunned = new Stunned_State(this); var searchFlag = new SearchForFlag_State(this); var chaseFlag = new ChaseFlag_State(this); var carryFlag = new CarryFlagToBase_State(this); var protectFlagCarrier = new ProtectFlagCarrier_State(this); //Los registro para hacer cambios forzados de estados statesRegistry.Add(Enums.SM_STATES.Idle, idle); statesRegistry.Add(Enums.SM_STATES.Move, move); statesRegistry.Add(Enums.SM_STATES.Stunned, stunned); statesRegistry.Add(Enums.SM_STATES.SearchFlag, searchFlag); statesRegistry.Add(Enums.SM_STATES.ChaseFlag, chaseFlag); statesRegistry.Add(Enums.SM_STATES.CarryFlagToBase, carryFlag); statesRegistry.Add(Enums.SM_STATES.ProtectFlagCarrier, protectFlagCarrier); //Agrego transiciones At(searchFlag, move, ImStillSearching()); At(move, searchFlag, FinishMomevent()); At(chaseFlag, carryFlag, HasFlag()); At(carryFlag, searchFlag, ImStillSearching()); At(stunned, searchFlag, ImStillSearching()); At(protectFlagCarrier, searchFlag, ImStillSearching()); //Shortcut para agregar transiciones void At(IState from, IState to, Func <bool> condition) => sm.AddTransition(from, to, condition); //Condiciones Func <bool> IsStunned() => () => isStunned; Func <bool> ImStillSearching() => () => knowsWhereFlagIs == false && hasFlag == false && isStunned == false; Func <bool> FinishMomevent() => () => GetComponent <NavMeshAgent>().velocity == Vector3.zero; Func <bool> FindFlag() => () => knowsWhereFlagIs && hasFlag == false && isStunned == false && sm.CurrentState != protectFlagCarrier; Func <bool> HasFlag() => () => hasFlag; //Desde cualquier estado sm.AddAnyTransition(stunned, IsStunned()); sm.AddAnyTransition(chaseFlag, FindFlag()); //Arranco la maquina en un estado sm.SetState(searchFlag); }
//global variables void Awake() { //first, reference all of the state scripts idleState = GetComponent <Idle_State> (); moveState = GetComponent <Move_State> (); deadState = GetComponent <Dead_State> (); emptyState = GetComponent <Empty_State> (); //get prepping currentState = Player_State.Idle_State; //ready to go ChangeState(); }
private void SetState(Move_State _state) { switch (_state) { case Move_State.COMBAT_STATE: case Move_State.ENGAGE_STATE: case Move_State.DISENGAGE_STATE: m_state = _state; break; default: m_prevState = m_state; m_state = _state; break; } }
private void Start2() { agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); m_state = m_prevState = Move_State.LANING_STATE; info = GetComponent <MinionInfo>(); interactive = GetComponent <Interactive>(); if (Team.RED_TEAM == info.team) { goal = GameManager.BluePortalTransform; if (agent.enabled) { agent.destination = goal.position; } } else { goal = GameManager.RedPortalTransform; } }