// Start is called before the first frame update public override void Start() { //profile = GlobalManager.Instance.tacticalProfile; trigger = this.GetComponentInChildren <AITriggerDetector>(); threat = null; enemies = new List <GameObject>(); nodeQueue = new Queue <GraphNode>(); moveQueue = new Queue <Direction>(); timer = inputTimer; moveXY = transform.position; newAngle = transform.eulerAngles; nextAction = 1; currentState = new ExploringState(); currentState.OnStateEnter(this); var newLists = GraphBuilder.ExploreGraph(transform.position, graph, unvisitedNodes, junctionNodes, holeNodes); graph = newLists[0]; unvisitedNodes = newLists[1]; junctionNodes = newLists[2]; holeNodes = newLists[3]; graph.Find(a => a.Equals(new GraphNode(transform.position.x, transform.position.y))).visited = true; graph.Find(a => a.Equals(new GraphNode(transform.position.x, transform.position.y))).UpdateGraphNodeType(); unvisitedNodes.Remove(new GraphNode(transform.position.x, transform.position.y)); }
public void OnBulletDetected(GameObject bullet) { // If bullet is detected, we always flee threat = bullet; currentState = new FleeingState(); currentState.OnStateEnter(this); }
public void ChangePrimaryState(AbstractState newState) { if (_currentState != null) { _currentState.OnStateExit(); } _currentState = newState; var stateMachine = this; _currentState.OnStateEnter(ref stateMachine); OnStateChanged?.Invoke(_currentState.GetType()); }
public void OnEnemyDetected(GameObject player) { // If player is detected, we check if it is our teammate, or enemy, if it is enemy and we are not fleeing or attacking, we enter attacking state if (player.GetComponent <AbstractController>().team == team) { return; } if (!enemies.Contains(player)) { enemies.Add(player); if (!(currentState.GetType() == typeof(FleeingState)) && !(currentState.GetType() == typeof(AttackingState))) { currentState = new AttackingState(); currentState.OnStateEnter(this); } } }