From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- ch.sycoforge.Decal.Demo/LineUtil.cs | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 ch.sycoforge.Decal.Demo/LineUtil.cs (limited to 'ch.sycoforge.Decal.Demo/LineUtil.cs') diff --git a/ch.sycoforge.Decal.Demo/LineUtil.cs b/ch.sycoforge.Decal.Demo/LineUtil.cs new file mode 100644 index 0000000..864ee19 --- /dev/null +++ b/ch.sycoforge.Decal.Demo/LineUtil.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace ch.sycoforge.Decal.Demo; + +public static class LineUtil +{ + public static void DrawPath(float thickness, Material material, List path) + { + if (path != null && (path == null || path.Count >= 2)) + { + if (thickness <= Mathf.Epsilon) + { + GL.Begin(1); + } + else + { + GL.Begin(7); + } + material.SetPass(0); + GL.Color(Color.blue); + Vector3 start = path[0]; + for (int i = 1; i < path.Count; i++) + { + Vector3 vector = path[i]; + DrawLine(thickness, start, vector); + start = vector; + } + GL.End(); + } + } + + private static void DrawLine(float thickness, Vector3 start, Vector3 end) + { + if (thickness <= Mathf.Epsilon) + { + GL.Vertex(start); + GL.Vertex(end); + return; + } + Camera main = Camera.main; + Vector3 normalized = (end - start).normalized; + Vector3 normalized2 = (start - main.transform.position).normalized; + Vector3 vector = Vector3.Cross(normalized2, normalized) * (thickness / 2f); + GL.Vertex(start - vector); + GL.Vertex(start + vector); + GL.Vertex(end + vector); + GL.Vertex(end - vector); + } +} -- cgit v1.1-26-g67d0