Esempio n. 1
0
    public static void DrawSpline(SplineComponent a_Spline, GizmoType a_Type)
    {
        Color l_GizmosColor = Gizmos.color;

        if (a_Spline.Spline.IsValid && a_Spline.Spline.Count >= 4) {

                // Start and end points
            Gizmos.color = SplineWindow.StartEndPointColor;
            Gizmos.DrawLine (a_Spline.Spline [0].transform.position, a_Spline.Spline [1].transform.position);
            Gizmos.DrawLine (a_Spline.Spline [a_Spline.Spline.Count - 2].transform.position, a_Spline.Spline [a_Spline.Spline.Count - 1].transform.position);

                // Spline curve
            Gizmos.color = SplineWindow.DefaultColor;
            float l_TDelta = (a_Spline.Spline.LastControlPoint.T - a_Spline.Spline.FirstControlPoint.T) / SplineWindow.CurveSegmentCount;
            SplineEnumerator <SplineControlPointComponent> l_Enumerator = new SplineEnumerator <SplineControlPointComponent> (a_Spline.Spline);
            l_Enumerator.MoveToStart ();
            Vector3 l_PositionA;
            Vector3 l_PositionB = l_Enumerator.CurrentPosition;
            while (!l_Enumerator.IsAtEnd ()) {
                l_Enumerator.MoveForward (l_TDelta);

                l_PositionA = l_PositionB;
                l_PositionB = l_Enumerator.CurrentPosition;

                Gizmos.DrawLine (l_PositionA, l_PositionB);
            }

                // Curve spheres
            if (SplineWindow.CurveSphereCount > 1) {
                Gizmos.color = SplineWindow.CurveSphereColor;
                l_TDelta = (a_Spline.Spline.LastControlPoint.T - a_Spline.Spline.FirstControlPoint.T) / (SplineWindow.CurveSphereCount - 1);
                l_Enumerator.MoveToStart ();
                Gizmos.DrawSphere (l_Enumerator.CurrentPosition, SplineWindow.SphereRadius);
                while (!l_Enumerator.IsAtEnd ()) {
                    l_Enumerator.MoveForward (l_TDelta);
                    Gizmos.DrawSphere (l_Enumerator.CurrentPosition, SplineWindow.SphereRadius);
                }
            }
        }

        Gizmos.color = l_GizmosColor;
    }
    protected void Update()
    {
        Transform l_Transform = transform;

        if (pointCount > 0 && spline.Spline.Count > 0) {
            SplineEnumerator <SplineControlPointComponent> l_Enumerator = new SplineEnumerator <SplineControlPointComponent> (spline.Spline);

            float l_SplineLength = spline.Spline.LastControlPoint.T - spline.Spline.FirstControlPoint.T;
            float l_Delta = l_SplineLength / pointCount;

            m_Points.Clear ();

            l_Enumerator.MoveToStart ();
            while (!l_Enumerator.IsAtEnd ()) {
                m_Points.Add (l_Transform.InverseTransformPoint (l_Enumerator.CurrentPosition));
                l_Enumerator.MoveForward (l_Delta);
            }
            m_Points.Add (l_Transform.InverseTransformPoint (l_Enumerator.CurrentPosition));

            m_LineMeshGenerator.RecalculateMesh (m_Points, 1.0f, l_Transform.InverseTransformDirection (Vector3.up));
        }

        m_MeshFilter.mesh = m_LineMeshGenerator.GeneratedMesh;
    }