using UnityEngine; public abstract class Sensor : MonoBehaviour { protected Agent _agent; protected virtual void Start() { _agent = GetComponent(); } /// /// Main sensing method to gather information about a target agent. /// /// The agent to sense. /// SensorOutput containing position and velocity data. /// /// Implementers should: /// 1. Call SensePosition to get position data. /// 2. Call SenseVelocity to get velocity data. /// 3. Combine results into a SensorOutput struct. /// public abstract SensorOutput Sense(Agent target); /// /// Calculates the relative position of the target agent. /// /// The agent to sense. /// PositionOutput containing range, azimuth, and elevation. /// /// Implementers should calculate: /// - range: Distance to the target (in unity units). /// - azimuth: Horizontal angle to the target (in degrees). /// Positive is clockwise from the forward direction. /// - elevation: Vertical angle to the target (in degrees). /// Positive is above the horizontal plane. /// protected abstract PositionOutput SensePosition(Agent target); /// /// Calculates the relative velocity of the target agent. /// /// The agent to sense. /// VelocityOutput containing range rate, azimuth rate, and elevation rate. /// /// Implementers should calculate: /// - range: Radial velocity (closing speed) in units/second. /// Positive means the target is moving away. /// - azimuth: Rate of change of azimuth in degrees/second. /// Positive means the target is moving clockwise. /// - elevation: Rate of change of elevation in degrees/second. /// Positive means the target is moving upwards. /// protected abstract VelocityOutput SenseVelocity(Agent target); } public struct SensorOutput { public PositionOutput position; public VelocityOutput velocity; } public struct PositionOutput { public float range; public float azimuth; public float elevation; } public struct VelocityOutput { public float range; public float azimuth; public float elevation; }