- using UnityEditor;
- using UnityEngine;
- [CustomEditor(typeof(FOV))]
- public class EditorFOV : Editor
- {
- private void OnSceneGUI()
- {
- FOV fov = (FOV)target;
-
- OrcNPCController controller = (OrcNPCController)fov.Controller;
- if (controller != null)
- {
- Vector3 lastDirection = controller.LastDirection.normalized;
-
- Handles.color = Color.green;
- Handles.DrawWireArc(fov.transform.position, Vector3.forward, Vector3.right, 360, fov.Radius);
-
- Vector3 viewAngle01 = DirectionFromAngle(lastDirection, -fov.Angle / 2);
- Vector3 viewAngle02 = DirectionFromAngle(lastDirection, fov.Angle / 2);
-
- 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);
-
- Handles.color = Color.red;
- Handles.DrawLine(fov.transform.position, fov.transform.position + lastDirection * fov.Radius);
- }
- }
- private Vector3 DirectionFromAngle(Vector3 direction, float angleInDegrees)
- {
-
- Quaternion rotation = Quaternion.Euler(0, 0, angleInDegrees);
- return rotation * direction;
- }
- }