private void OnSceneGUI() { FOV fov = (FOV)target; Handles.color = Color.white; Handles.DrawWireArc(fov.transform.position, Vector3.forward, Vector2.right, 360, fov.viewRadius); Vector3 viewAngleA = fov.DirFromAngle(-fov.viewAngle / 2, false); Vector3 viewAngleB = fov.DirFromAngle(fov.viewAngle / 2, false); Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngleA * fov.viewRadius); Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngleB * fov.viewRadius); if (fov.hasSubFOV) { Handles.color = Color.yellow; Handles.DrawWireArc(fov.transform.position, Vector3.forward, Vector2.right, 360, fov.subViewRadius); Vector3 subViewAngleA = fov.DirFromAngle(-fov.subViewAngle / 2, false); Vector3 subViewAngleB = fov.DirFromAngle(fov.subViewAngle / 2, false); Handles.DrawLine(fov.transform.position, fov.transform.position + subViewAngleA * fov.subViewRadius); Handles.DrawLine(fov.transform.position, fov.transform.position + subViewAngleB * fov.subViewRadius); } Handles.color = Color.red; foreach (Transform visibleTarget in fov.visibleTargets) { Handles.DrawLine(fov.transform.position, visibleTarget.position); } }
void OnSceneGUI() { FOV view = (FOV)target; Handles.color = Color.white; Handles.DrawWireArc(view.transform.position, Vector3.forward, Vector3.right, 360, view.viewRadius); Vector3 viewAngleA = view.DirFromAngle(-view.viewAngle / 2, false); Vector3 viewAngleB = view.DirFromAngle(view.viewAngle / 2, false); Handles.DrawLine(view.transform.position, view.transform.position + viewAngleA * view.viewRadius); Handles.DrawLine(view.transform.position, view.transform.position + viewAngleB * view.viewRadius); }
void OnSceneGUI() { FOV fow = (FOV)target; Handles.color = Color.white; Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.viewRadius); Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false); Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius); Handles.color = Color.red; foreach (Transform visibleTarg in fow.visTarg) { Handles.DrawLine(fow.transform.position, visibleTarg.transform.position); } }
void OnSceneGUI() { FOV fOV = (FOV)target; Handles.color = Color.blue; Handles.DrawWireArc(fOV.transform.position, Vector3.up, Vector3.forward, 360.0f, fOV.viewRadius); Vector3 viewAngleA = fOV.DirFromAngle(-fOV.viewAngle / 2, false); Vector3 viewAngleB = fOV.DirFromAngle(fOV.viewAngle / 2, false); Handles.color = Color.red; Handles.DrawLine(fOV.transform.position, fOV.transform.position + viewAngleA * fOV.viewRadius); Handles.DrawLine(fOV.transform.position, fOV.transform.position + viewAngleB * fOV.viewRadius); foreach (Transform visableTarget in fOV.visableTagets) { Handles.DrawLine(fOV.transform.position, visableTarget.position); } }
private void MakeMesh() { stepCount = Mathf.RoundToInt(fov.viewAngle * meshRes); float stepAngle = fov.viewAngle / stepCount; List <Vector3> viewVertex = new List <Vector3>(); hit = new RaycastHit2D(); for (int i = 0; i < stepCount; i++) { //E,F = rotaciono o FOV: + sentido horario, - sentido anti-horario //B,G,C,H = aumento o raio do FOV: + sentido ah, - sentido h float angle = fov.transform.eulerAngles.y - fov.viewAngle * E / 2 * F + stepAngle * G * i; Vector3 dir = fov.DirFromAngle(angle, false); //armazena o obstaculo hit = Physics2D.Raycast(fov.transform.position, dir, fov.viewRadius, fov.obstacleMask); //se o collider do obstaculo for nulo if (hit.collider == null) { viewVertex.Add(transform.position + dir.normalized * fov.viewRadius); } else { viewVertex.Add(transform.position + dir.normalized * hit.distance); } } int vertexCount = viewVertex.Count + 1; vertices = new Vector3[vertexCount]; triangles = new int[(vertexCount - 2) * 3]; vertices[0] = Vector3.zero; for (int i = 0; i < vertexCount - 1; i++) { vertices[i + 1] = transform.InverseTransformPoint(viewVertex[i]); if (i < vertexCount - 2) { triangles[i * 3 + 2] = 0; triangles[i * 3 + 1] = i + 1; triangles[i * 3] = i + 2; } } mesh.Clear(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); }
void OnSceneGUI() { FOV fow = (FOV)target; //Draws view reach Handles.color = Color.yellow; Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.view_radius); //Draws cone of view Vector3 viewAngleA = fow.DirFromAngle(-fow.view_angle / 2, false); Vector3 viewAngleB = fow.DirFromAngle(fow.view_angle / 2, false); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.view_radius); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.view_radius); Handles.color = Color.red; foreach (Collider ally in fow.alliesInRadius) { Handles.DrawLine(fow.transform.position, ally.transform.position); } }
void MakeMesh() { stepCount = Mathf.RoundToInt(fov.viewAngle * meshRes); float stepAngle = fov.viewAngle / stepCount; List <Vector3> viewVertex = new List <Vector3>(); hit = new RaycastHit2D(); for (int i = 0; i < stepCount; i++) { float angle = fov.transform.eulerAngles.y - fov.viewAngle / 2 + stepAngle * i; Vector3 dir = fov.DirFromAngle(angle, false); hit = Physics2D.Raycast(fov.transform.position, dir, fov.viewRadius, fov.obstacleMask); if (hit.collider == null) { // if it doesn't collide, add the vertex viewVertex.Add(transform.position + dir.normalized * fov.viewRadius); } else { viewVertex.Add(transform.position + dir.normalized * hit.distance); } } int vertexCount = viewVertex.Count + 1; vertices = new Vector3[vertexCount]; triangles = new int[(vertexCount - 2) * 3]; vertices[0] = Vector3.zero; for (int i = 0; i < vertexCount - 1; i++) { vertices[i + 1] = transform.InverseTransformPoint(viewVertex[i]); if (i < vertexCount - 2) { triangles[i * 3 + 2] = 0; triangles[i * 3 + 1] = i + 1; triangles[i * 3] = i + 2; } } mesh.Clear(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); }