forked from Comp3interactive/FieldOfView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldOfViewEditor.cs
33 lines (27 loc) · 1.2 KB
/
FieldOfViewEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(FieldOfView))]
public class FieldOfViewEditor : Editor
{
private void OnSceneGUI()
{
FieldOfView fov = (FieldOfView)target;
Handles.color = Color.white;
Handles.DrawWireArc(fov.transform.position, Vector3.up, Vector3.forward, 360, fov.radius);
Vector3 viewAngle01 = DirectionFromAngle(fov.transform.eulerAngles.y, -fov.angle / 2);
Vector3 viewAngle02 = DirectionFromAngle(fov.transform.eulerAngles.y, 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);
if (fov.canSeePlayer)
{
Handles.color = Color.green;
Handles.DrawLine(fov.transform.position, fov.playerRef.transform.position);
}
}
private Vector3 DirectionFromAngle(float eulerY, float angleInDegrees)
{
angleInDegrees += eulerY;
return new Vector3(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad), 0, Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));
}
}