diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /ch.sycoforge.Decal.Demo/LineUtil.cs |
+init
Diffstat (limited to 'ch.sycoforge.Decal.Demo/LineUtil.cs')
-rw-r--r-- | ch.sycoforge.Decal.Demo/LineUtil.cs | 50 |
1 files changed, 50 insertions, 0 deletions
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<Vector3> 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); + } +} |