diff --git a/Assets/Cryville/Crtr/Components/MeshBase.cs b/Assets/Cryville/Crtr/Components/MeshBase.cs index f6147e8..92a3c10 100644 --- a/Assets/Cryville/Crtr/Components/MeshBase.cs +++ b/Assets/Cryville/Crtr/Components/MeshBase.cs @@ -44,7 +44,7 @@ namespace Cryville.Crtr.Components { UpdateColor(); } } - protected void UpdateColor() { + protected virtual void UpdateColor() { if (!mesh.Initialized) return; foreach (var mat in materials) { mat.color = _color; diff --git a/Assets/Cryville/Crtr/Components/TrackLine.cs b/Assets/Cryville/Crtr/Components/TrackLine.cs index fda02b7..9f7653a 100644 --- a/Assets/Cryville/Crtr/Components/TrackLine.cs +++ b/Assets/Cryville/Crtr/Components/TrackLine.cs @@ -5,8 +5,38 @@ namespace Cryville.Crtr.Components { public class TrackLine : SectionalGameObject { readonly List vertices = new List(); + LineRenderer lineRenderer; + + public TrackLine() { + SubmitProperty("width", new PropOp.Float(v => Width = v)); + } + + private float m_width; + public float Width { + get { return m_width; } + set { + m_width = value; + if (lineRenderer != null) { + lineRenderer.startWidth = value; + lineRenderer.endWidth = value; + } + } + } + public override void Init() { base.Init(); + lineRenderer = gameObject.AddComponent(); + lineRenderer.materials = materials = new Material[] { MeshWrapper.NewMaterial() }; + Width = Width; + UpdateColor(); + } + + protected override void UpdateColor() { + base.UpdateColor(); + if (lineRenderer != null) { + lineRenderer.startColor = Color; + lineRenderer.endColor = Color; + } } protected override void AppendPointInternal(Vector3 p, Quaternion r) { @@ -14,13 +44,12 @@ namespace Cryville.Crtr.Components { } public override void Seal() { - var r = GetComponent(); #if UNITY_5_6_OR_NEWER - r.positionCount = vertices.Count; + lineRenderer.positionCount = vertices.Count; #else - r.SetVertexCount(vertices.Count); + lineRenderer.SetVertexCount(vertices.Count); #endif - for (int i = 0; i < vertices.Count; i++) r.SetPosition(i, vertices[i]); + for (int i = 0; i < vertices.Count; i++) lineRenderer.SetPosition(i, vertices[i]); } public override void Reset() { diff --git a/Assets/Cryville/Crtr/GenericResources.cs b/Assets/Cryville/Crtr/GenericResources.cs index 7adf7b0..fa35618 100644 --- a/Assets/Cryville/Crtr/GenericResources.cs +++ b/Assets/Cryville/Crtr/GenericResources.cs @@ -20,6 +20,7 @@ namespace Cryville.Crtr { if (loaded) return; Components.Add("anim", typeof(SkinAnimation)); Components.Add("image", typeof(SpritePlane)); + Components.Add("linesec", typeof(TrackLine)); Components.Add("mesh", typeof(MeshBase)); Components.Add("polysec", typeof(PolygonSGO)); Components.Add("rect", typeof(SpriteRect));