public static void DrawLineOrtho(Vector2 p1, Vector2 p2, Color color, bool clip = true) { //p1 += ASUI.AbsPos(ASUI.owner); //p2 += ASUI.AbsPos(ASUI.owner); //p1 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //p2 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //clip if (clip) { var rect = ASUI.Rect(ASUI.owner); if (LineClip.ClipCohSuth(rect[0], rect[1], ref p1, ref p2) == LineClip.Result.discard) { return; } } //normalize & flip y p1.x /= ASUI.scaler.referenceResolution.x; p1.y = ASUI.scaler.referenceResolution.y - p1.y; p1.y /= ASUI.scaler.referenceResolution.y; p2.x /= ASUI.scaler.referenceResolution.x; p2.y = ASUI.scaler.referenceResolution.y - p2.y; p2.y /= ASUI.scaler.referenceResolution.y; GL.Begin(GL.LINES); GL.Color(color); GL.Vertex(p1); GL.Vertex(p2); GL.End(); }
// 控制粗细的线条实际是画四边形,不一定与坐标轴垂直。 public static void DrawLineWidth(Vector2 p1, Vector2 p2, float width, Color color, bool clip = true) { //p1 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //p2 += MathTool.ReverseY(ASUI.owner.anchoredPosition); //clip if (clip) { var rect = ASUI.Rect(ASUI.owner); if (LineClip.ClipCohSuth(rect[0], rect[1], ref p1, ref p2) == LineClip.Result.discard) { return; } } var v = p2 - p1; var v2 = p1 - p2; width *= 0.5f; var p1a = p1 + new Vector2(-v.y, v.x).normalized *width; var p1b = p1 + new Vector2(v.y, -v.x).normalized *width; var p2a = p2 + new Vector2(-v2.y, v2.x).normalized *width; var p2b = p2 + new Vector2(v2.y, -v2.x).normalized *width; //四边形可能切成更多边形,暂时没做画多边形功能因此暂不裁剪宽度,只裁剪长度 DrawQuads(p1a, p1b, p2a, p2b, color); }