// Use this for initialization void Awake() { stateMachine = GetComponent <BotStateMachine>(); navigator = GetComponent <IBotNavigator>(); attacker = GetComponent <BotAttacker>(); stateMachine.onStateChanged -= OnStateChanged; stateMachine.onStateChanged += OnStateChanged; }
protected virtual void Awake() { locator = GetComponent <BotLocator>(); navigator = GetComponent <IBotNavigator>(); ctrlCollider = GetComponent <Collider2D>(); contact = new ContactFilter2D(); contact.layerMask = locator.enemyMask; agent = GetComponent <AttackAgent>(); agent.onAttackStart = OnAttackStart; agent.onAttackComplete = OnAttackComplete; if (agent != null) { agent.Init(locator.enemyMask, locator.obstacleMask); } }
public void Awake() { locator = GetComponent <BotLocator>(); navigator = GetComponent <IBotNavigator>(); attacker = GetComponent <BotAttacker>(); stateDecision = new DecisionTree <BotStateMachine, State> { showDebugInfo = showDecisionPath, root = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.currentState == State.None, positive = new DecisionTree <BotStateMachine, State> .Node { decision = State.Idle }, negative = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.locator.LocateEnemy() != null, positive = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.navigator.IsTargetOnPath(bot.locator.LocateEnemy().transform.position), positive = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.attacker.EnemyInAttackRange(), positive = new DecisionTree <BotStateMachine, State> .Node { decision = State.Attack }, negative = new DecisionTree <BotStateMachine, State> .Node { decision = State.KeepAttackDistance } }, negative = new DecisionTree <BotStateMachine, State> .Node { decision = State.Patrol } }, negative = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.currentState == State.KeepAttackDistance || bot.currentState == State.Attack, positive = new DecisionTree <BotStateMachine, State> .Node { decision = State.Idle }, negative = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.currentState == State.Idle, positive = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.idleTime > 0, positive = new DecisionTree <BotStateMachine, State> .Node { decision = State.Idle }, negative = new DecisionTree <BotStateMachine, State> .Node { decision = State.Patrol } }, negative = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.currentState == State.Patrol, positive = new DecisionTree <BotStateMachine, State> .Node { Condition = bot => bot.patrolTime > 0, positive = new DecisionTree <BotStateMachine, State> .Node { decision = State.Patrol }, negative = new DecisionTree <BotStateMachine, State> .Node { decision = State.Idle } }, negative = new DecisionTree <BotStateMachine, State> .Node { decision = State.Idle } } } } } } }; }