You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
using System; |
|
using System.Collections.Generic; |
|
using Meta; |
|
using Player; |
|
using Unity.Collections; |
|
using UnityEngine; |
|
using Utils; |
|
|
|
namespace Ai |
|
{ |
|
public class AiController : MonoSingleton<AiController> { |
|
|
|
[ReadOnly] public readonly List<TargetingEnemy> TargetingEnemies = new List<TargetingEnemy>(); |
|
public MainCharacter Player { get; set; } |
|
public event Action StageCompletedEvent; |
|
public event Action<Vector3> EnemyDiedEvent; |
|
|
|
public Vector3 PlayerPosition |
|
{ |
|
get { return Player != null ? Player.transform.position : Vector3.zero; } |
|
} |
|
|
|
public void EnemyDied(Vector3 position) |
|
{ |
|
if (EnemyDiedEvent != null) |
|
EnemyDiedEvent(position); |
|
if (TargetingEnemies.Count <= 0) |
|
{ |
|
if (StageCompletedEvent != null) |
|
StageCompletedEvent(); |
|
|
|
PlayerResources.Instance.Repaint(); |
|
BulletManager.Instance.ShutDown(); |
|
} |
|
} |
|
|
|
public void Update() |
|
{ |
|
foreach (var targetingEnemy in TargetingEnemies) |
|
{ |
|
targetingEnemy.Proceed(Player.IsDead ? targetingEnemy.transform.position : PlayerPosition); |
|
if (Player.IsDead) continue; |
|
targetingEnemy.SetGuns(PlayerPosition); |
|
} |
|
} |
|
} |
|
}
|
|
|