using UnityEditor; using UnityEngine; [CustomEditor(typeof(FOV))] public class EditorFOV : Editor { private void OnSceneGUI() { FOV fov = (FOV)target; // Ensure the FOV script has access to the NPC controller OrcNPCController controller = (OrcNPCController)fov.Controller; if (controller != null) { Vector3 lastDirection = controller.LastDirection.normalized; // Draw the full FOV circle Handles.color = Color.green; Handles.DrawWireArc(fov.transform.position, Vector3.forward, Vector3.right, 360, fov.Radius); // Get the angles for the FOV Vector3 viewAngle01 = DirectionFromAngle(lastDirection, -fov.Angle / 2); Vector3 viewAngle02 = DirectionFromAngle(lastDirection, fov.Angle / 2); // Draw the FOV angles Handles.color = Color.yellow; Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngle01 * fov.Radius); Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngle02 * fov.Radius); // Draw the line representing the direction the NPC is facing Handles.color = Color.red; Handles.DrawLine(fov.transform.position, fov.transform.position + lastDirection * fov.Radius); } } private Vector3 DirectionFromAngle(Vector3 direction, float angleInDegrees) { // Rotate the direction vector by the given angle Quaternion rotation = Quaternion.Euler(0, 0, angleInDegrees); return rotation * direction; } }