10-14-2015, 05:55 PM
(This post was last modified: 10-14-2015, 06:11 PM by kloveridge.)
So I am learning the API for curvy. And I just wanted to draw the spline genered by CurvySpline. So I wrote this class:
I attach this component to a CurvySpline GameObject. And in the CurvySpline component put in the OnRefresh event a callback to the RedrawSpline() function. When I run the scene, my line draws. I can manipulate the spline and the line redraws. Just wonder If I'm missing something more efficient you have already written.
I just found that Curvy has a component called CurvyLineRenderer which does what I was trying to do. I love reinventing wheels!
Code:
using UnityEngine;
using System.Collections;
using FluffyUnderware.Curvy;
using FluffyUnderware.Curvy.Utils;
public class SplineRenderer : MonoBehaviour {
LineRenderer linerender;
CurvySpline spline;
// Use this for initialization
void Start () {
linerender = gameObject.AddComponent<LineRenderer> ();
spline = GetComponent<CurvySpline> ();
// while (!spline.IsInitialized)
// yield return null;
}
public void RedrawSpline()
{
SplinePolyLine line = new SplinePolyLine (spline);
Vector3[] vtx = line.getVertices ();
linerender.SetVertexCount(vtx.Length);
for( int i=0; i<vtx.Length; ++i )
{
linerender.SetPosition(i, vtx[i]);
}
linerender.SetWidth(.25f, .25f);
}
}
I attach this component to a CurvySpline GameObject. And in the CurvySpline component put in the OnRefresh event a callback to the RedrawSpline() function. When I run the scene, my line draws. I can manipulate the spline and the line redraws. Just wonder If I'm missing something more efficient you have already written.
I just found that Curvy has a component called CurvyLineRenderer which does what I was trying to do. I love reinventing wheels!