protected virtual void Awake() { locator = GetComponent <BotLocator>(); attacker = GetComponent <BotAttacker>(); hitbox = GetComponent <Hitbox>(); hitbox.onDamageTaken += OnDamageTaken; controller = GetComponent <Controller2D>(); globalPatrolTargets = new Vector3[patrolTargets.Length]; if (gravityDirection == Vector2.zero) { Debug.LogWarning("Gravity not setup corectly"); return; } for (int i = 0; i < patrolTargets.Length; i++) { globalPatrolTargets[i] = patrolTargets[i] + transform.position; if (gravityDirection.y != 0) { minPatrolTarget = i == 0 || minPatrolTarget.x > globalPatrolTargets[i].x ? globalPatrolTargets[i] : minPatrolTarget; maxPatrolTarget = i == 0 || maxPatrolTarget.x < globalPatrolTargets[i].x ? globalPatrolTargets[i] : maxPatrolTarget; } else { minPatrolTarget = i == 0 || minPatrolTarget.y > globalPatrolTargets[i].y ? globalPatrolTargets[i] : minPatrolTarget; maxPatrolTarget = i == 0 || maxPatrolTarget.y < globalPatrolTargets[i].y ? globalPatrolTargets[i] : maxPatrolTarget; } } }
// Use this for initialization void Awake() { stateMachine = GetComponent <BotStateMachine>(); navigator = GetComponent <IBotNavigator>(); attacker = GetComponent <BotAttacker>(); stateMachine.onStateChanged -= OnStateChanged; stateMachine.onStateChanged += OnStateChanged; }
protected void Awake() { locator = GetComponent <BotLocator>(); attacker = GetComponent <BotAttacker>(); controller = GetComponent <Controller2D>(); hitbox = GetComponent <Hitbox>(); hitbox.onDamageTaken += OnDamageTaken; globalPatrolTargets = new Vector2[patrolTargets.Length]; for (int i = 0; i < patrolTargets.Length; i++) { globalPatrolTargets[i] = patrolTargets[i] + (Vector2)transform.position; } CalculatePatrolBounds(); }
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 } } } } } } }; }