diff --git a/CachedLineRenderer.cs b/CachedLineRenderer.cs index 82dab19..594b199 100644 --- a/CachedLineRenderer.cs +++ b/CachedLineRenderer.cs @@ -36,7 +36,7 @@ public class CachedLineRenderer : LineRendererBase /// - void Awake() + void Start() { // Collect. LineRendererCamera.AddCachedRenderer(this); diff --git a/DirectLineRenderer.cs b/DirectLineRenderer.cs index d988c50..24a4d7c 100644 --- a/DirectLineRenderer.cs +++ b/DirectLineRenderer.cs @@ -26,7 +26,7 @@ public class DirectLineRenderer : LineRendererBase #region Events - void Awake() + void Start() { // Collect. LineRendererCamera.AddDirectRenderer(this); diff --git a/Line.cs b/Line.cs index 2dd0d1d..d327e48 100644 --- a/Line.cs +++ b/Line.cs @@ -16,12 +16,9 @@ namespace EPPZ.Lines [Serializable] public class Line { - - public Vector3 from; public Vector3 to; public Color color; + public float width = 1; } } - - diff --git a/LineRendererBase.cs b/LineRendererBase.cs index e0df360..07add97 100644 --- a/LineRendererBase.cs +++ b/LineRendererBase.cs @@ -197,4 +197,4 @@ protected void DrawLineWithTransform(Vector2 from, Vector2 to, Color color, Tran } -} +} \ No newline at end of file diff --git a/LineRendererCamera.cs b/LineRendererCamera.cs index c7ad128..0922e63 100644 --- a/LineRendererCamera.cs +++ b/LineRendererCamera.cs @@ -6,7 +6,6 @@ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using UnityEngine; -using System.Collections; using System.Collections.Generic; @@ -55,7 +54,12 @@ public static void AddCachedRenderer(CachedLineRenderer renderer) void Awake() { - shared = this; + if (shared != null && shared != this) + { + Destroy(this); + return; + } + shared = this; _camera = GetComponent(); } @@ -123,15 +127,22 @@ void DrawLines() void DrawCall() { // Assign vertex color material. - material.SetPass(0); // Single draw call (set pass call) - - // Send vertices in GL_LINES Immediate Mode. - GL.Begin(GL.LINES); - foreach (EPPZ.Lines.Line eachLine in lineBatch) + // Single draw call (set pass call) + material.SetPass(0); + // Draw with width + GL.Begin(GL.QUADS); + foreach (Line eachLine in lineBatch) { GL.Color(eachLine.color); - GL.Vertex(eachLine.from); - GL.Vertex(eachLine.to); + + Vector3 v = eachLine.to - eachLine.from; + Vector3 u = new Vector3(-v.y, v.x, v.z).normalized * .1f * eachLine.width; + u.z = v.z; + + GL.Vertex(eachLine.from - u); + GL.Vertex(eachLine.from + u); + GL.Vertex(eachLine.to + u); + GL.Vertex(eachLine.to - u); } GL.End(); }