private void EnterState(AiStateController controller) { if (hasEnterStateAction) { enterStateAction.Act(controller); } }
#pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override void Act(AiStateController controller) { _objectPosition = controller.transform.position; _targetPosition = controller.Target.transform.position; _distance = Vector3.Distance(_objectPosition, _targetPosition); if (_distance < minDistance) { _direction = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.left : Vector3.right; controller.TargetSpeed = _direction * controller.Speed; controller.SetGfxDirectionX = _direction.x; } else if (_distance > maxDistance) { _direction = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.right : Vector3.left; controller.TargetSpeed = _direction * controller.Speed; controller.SetGfxDirectionX = _direction.x; } else { _direction = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.right : Vector3.left; controller.TargetSpeed = Vector2.zero; controller.SetGfxDirectionX = _direction.x; } }
private void ExitState(AiStateController controller) { if (hasExitStateAction) { exitStateAction.Act(controller); } }
private void ExecuteActions(AiStateController controller) { foreach (var action in actions) { action.Act(controller); } }
#pragma warning restore CS0649 /***************************** * Methods * *****************************/ public void UpdateState(AiStateController controller) { if (CheckForTransitions(controller)) { ExecuteActions(controller); } }
#pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override bool Evaluate(AiStateController controller) { _objectPosition = controller.transform.position; _targetPosition = controller.Target.transform.position; _distance = Vector3.Distance(_objectPosition, _targetPosition); if (!(_distance > looseAggroDistance)) { return(false); } controller.Target = null; return(true); }
#pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override void Act(AiStateController controller) { _objectPosition = controller.gameObject.transform.position; _targetPosition = controller.TargetPosition; _distance = Vector3.Distance(_objectPosition, _targetPosition); _direction = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.right : Vector3.left; if (controller.HasCollidedWithOtherEnemy || _distance < 1) { controller.TargetPosition = controller.GetNextPatrolPoint; } controller.TargetSpeed = _direction * controller.Speed; controller.SetGfxDirectionX = _direction.x; }
#pragma warning disable CS0649 /***************************** * Variables * *****************************/ #pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override void Act(AiStateController controller) { switch (controller.CastSpellState) { case SpellCastingState.Waiting: if (controller.EnemyIsReadyToCastSpell()) { controller.CastSpellState = SpellCastingState.Casting; controller.SpellLength = Random.Range(0, controller.MaxSpellLength) + 1; } break; case SpellCastingState.Casting: if (controller.SpellLength > 0 && controller.EnemyIsReadyToAddSpell()) { controller.AddRandomSpell(); controller.SpellLength--; } if (controller.SpellLength == 0) { controller.CastSpellState = SpellCastingState.Firing; } break; case SpellCastingState.Firing: if (controller.EnemyIsReadyToFire()) { controller.FireSpell(); controller.CastSpellState = SpellCastingState.Waiting; } break; default: throw new ArgumentOutOfRangeException(); } }
private bool CheckForTransitions(AiStateController controller) { foreach (var transition in transitions) { if (!transition.decision.Evaluate(controller)) { continue; } controller.currentState.ExitState(controller); transition.nextState.EnterState(controller); controller.currentState = transition.nextState; controller.OnStateChanged(); return(false); } return(true); }
#pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override bool Evaluate(AiStateController controller) { var numColliders = Physics2D.OverlapCircleNonAlloc(controller.Position, searchRadius, _hitColliders, searchLayerMask); var minDist = 100000f; if (numColliders <= 0) { return(false); } for (var index = 0; index < _hitColliders.Length; index++) { var hitCollider = _hitColliders[index]; _hitColliders[index] = null; if (hitCollider == null || controller.gameObject.transform.GetInstanceID() == hitCollider.transform.GetInstanceID()) { continue; } if (hitCollider.gameObject.CompareTag("Enemy")) { //controller.targetPosition = controller.GetNextPatrolPoint; return(false); } var offset = controller.Position - hitCollider.transform.position; var dist = Vector3.SqrMagnitude(offset); if (!(dist < minDist)) { continue; } controller.Target = hitCollider.gameObject; minDist = dist; } return(controller.Target != null); }
#pragma warning disable CS0649 /***************************** * Variables * *****************************/ #pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override bool Evaluate(AiStateController controller) { return(controller.Target == null); }
#pragma warning disable CS0649 /***************************** * Variables * *****************************/ #pragma warning restore CS0649 /***************************** * Methods * *****************************/ public abstract bool Evaluate(AiStateController controller);
#pragma warning disable CS0649 /***************************** * Variables * *****************************/ #pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override void Act(AiStateController controller) { }
#pragma warning disable CS0649 /***************************** * Variables * *****************************/ #pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override void Act(AiStateController controller) { controller.DestroySpell(); }
#pragma warning disable CS0649 /***************************** * Variables * *****************************/ public abstract void Act(AiStateController controller);
#pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override void Act(AiStateController controller) { Debug.Log(message, controller.gameObject); }
#pragma warning restore CS0649 /***************************** * Init * *****************************/ /***************************** * Update * *****************************/ /***************************** * Methods * *****************************/ public override void Act(AiStateController controller) { controller.TargetSpeed = targetSpeed; }