private static void DrawGizmo(PolygonAreaConfig scr, GizmoType gizmoType) { if ((gizmoType & GizmoType.Selected) == GizmoType.Selected) { return; } if ((gizmoType & GizmoType.InSelectionHierarchy) != GizmoType.InSelectionHierarchy) { var count = Selection.activeGameObject?.transform.parent?.GetComponentsInChildren <PolygonAreaConfig>().Length ?? 0; var selfCount = scr.GetComponents <PolygonAreaConfig>().Length; if (count <= selfCount) { return; } } GetValue(scr, out var area, out var origin, out var dir, out var color, out var vOffset, out var dirLineLength, out var dirLineWidth); var plane = GetPlane(origin); Handles.color = color; color.a = 1.0f; if (area.Vertexes == null) { return; } Handles.DrawAAPolyLine(5.0f, area.Vertexes.ToArray()); DrawArrow(origin - plane.normal * 0.2f, origin + dir * dirLineLength - plane.normal * 0.2f, plane.normal, dirLineWidth, color); color.a = 0.04f; Handles.color = color; Handles.DrawAAConvexPolygon(area.Vertexes.ToArray()); for (int i = 1; i < area.Vertexes.Count; ++i) { Vector3 v1 = area.Vertexes[i]; Vector3 v2 = area.Vertexes[i - 1]; Vector3 v3 = v1 - plane.normal * (Vector3.Dot(v1, plane.normal) + vOffset); Vector3 v4 = v2 - plane.normal * (Vector3.Dot(v2, plane.normal) + vOffset); color.a = 0.04f; Handles.color = color; Handles.DrawAAConvexPolygon(v1, v2, v4, v3, v1); } }
private static void GetValue(PolygonAreaConfig scr, out PolygonArea area, out Vector3 origin, out Vector3 dir, out Color color, out float vOffset, out float dirLineLength, out float dirLineWidth) { var type = scr.GetType(); area = (PolygonArea)type.GetFieldAll("m_Area").GetValue(scr); color = (Color)type.GetFieldAll("m_AreaColor").GetValue(scr); vOffset = (float)type.GetFieldAll("m_AreaVertialOffsetBase").GetValue(scr); dirLineLength = (float)type.GetFieldAll("m_DirLineLength").GetValue(scr); dirLineWidth = (float)type.GetFieldAll("m_DirLineWidth").GetValue(scr); var polygonType = area.GetType(); origin = (Vector3)polygonType.GetFieldAll("m_Origin").GetValue(area); dir = (Vector3)polygonType.GetFieldAll("m_Direction").GetValue(area); }