Summons
This commit is contained in:
56
Assets/AI/_Summons/SwarmCoordinator.cs
Normal file
56
Assets/AI/_Summons/SwarmCoordinator.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SwarmCoordinator : MonoBehaviour
|
||||
{
|
||||
[Header("Targeting")]
|
||||
[SerializeField] private bool autoFindPlayer = true;
|
||||
[SerializeField] private string playerTag = "Player";
|
||||
[SerializeField] private float targetRefreshInterval = 0.75f;
|
||||
|
||||
[Header("Swarm Tuning")]
|
||||
[SerializeField] private float updateInterval = 0.2f;
|
||||
[SerializeField] private float updateJitter = 0.05f;
|
||||
[SerializeField] private float separationRadius = 1.2f;
|
||||
[SerializeField] private float separationWeight = 1.0f;
|
||||
|
||||
private readonly List<SwarmAgent> agents = new List<SwarmAgent>();
|
||||
private Transform target;
|
||||
private float nextTargetRefreshTime;
|
||||
|
||||
public Transform Target => target;
|
||||
public float UpdateInterval => updateInterval;
|
||||
public float UpdateJitter => updateJitter;
|
||||
public float SeparationRadius => separationRadius;
|
||||
public float SeparationWeight => separationWeight;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!autoFindPlayer) return;
|
||||
if (Time.time < nextTargetRefreshTime) return;
|
||||
nextTargetRefreshTime = Time.time + targetRefreshInterval;
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
GameObject player = GameObject.FindGameObjectWithTag(playerTag);
|
||||
if (player != null) target = player.transform;
|
||||
}
|
||||
}
|
||||
|
||||
public void Register(SwarmAgent agent)
|
||||
{
|
||||
if (agent == null || agents.Contains(agent)) return;
|
||||
agents.Add(agent);
|
||||
}
|
||||
|
||||
public void Unregister(SwarmAgent agent)
|
||||
{
|
||||
if (agent == null) return;
|
||||
agents.Remove(agent);
|
||||
}
|
||||
|
||||
public List<SwarmAgent> GetAgents()
|
||||
{
|
||||
return agents;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user