Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Editor / EditorFOV.cs
  1. using UnityEditor;
  2. using UnityEngine;
  3. [CustomEditor(typeof(FOV))]
  4. public class EditorFOV : Editor
  5. {
  6. private void OnSceneGUI()
  7. {
  8. FOV fov = (FOV)target;
  9. // Ensure the FOV script has access to the NPC controller
  10. OrcNPCController controller = (OrcNPCController)fov.Controller;
  11. if (controller != null)
  12. {
  13. Vector3 lastDirection = controller.LastDirection.normalized;
  14. // Draw the full FOV circle
  15. Handles.color = Color.green;
  16. Handles.DrawWireArc(fov.transform.position, Vector3.forward, Vector3.right, 360, fov.Radius);
  17. // Get the angles for the FOV
  18. Vector3 viewAngle01 = DirectionFromAngle(lastDirection, -fov.Angle / 2);
  19. Vector3 viewAngle02 = DirectionFromAngle(lastDirection, fov.Angle / 2);
  20. // Draw the FOV angles
  21. Handles.color = Color.yellow;
  22. Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngle01 * fov.Radius);
  23. Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngle02 * fov.Radius);
  24. // Draw the line representing the direction the NPC is facing
  25. Handles.color = Color.red;
  26. Handles.DrawLine(fov.transform.position, fov.transform.position + lastDirection * fov.Radius);
  27. }
  28. }
  29. private Vector3 DirectionFromAngle(Vector3 direction, float angleInDegrees)
  30. {
  31. // Rotate the direction vector by the given angle
  32. Quaternion rotation = Quaternion.Euler(0, 0, angleInDegrees);
  33. return rotation * direction;
  34. }
  35. }