Exemple #1
0
 void Awake()
 {
     // this will assign the spline when there is only a reference
     if (!spline && splineRefernce)
     {
         spline = Spline.CreateSpline(splineRefernce);
         SetWorldPositions();
         spline.SetSegments();
     }
     else
     {
         //setup position relative to parenting
         SetWorldPositions();
     }
 }
Exemple #2
0
        /// <summary>
        /// Drawing the spline in the editor
        /// </summary>
        void OnDrawGizmos()
        {
            if (!spline)
            {
                return;
            }
            Gizmos.color = splineColor;
            float prevTime = 0;

            Vector3 pointA;
            Vector3 pointB = new Vector3();

            Waypoint[] waypoints = spline.waypoints;

            bool notSelected = UnityEditor.Selection.gameObjects.Length == 0 || UnityEditor.Selection.gameObjects[0] != gameObject;

            if (notSelected)
            {
                SetWorldPositions();
            }
            float rpp = 0.1f; // resolution per point

            spline.SetSegments();
            for (int i = 0; i < waypoints.Length; i++)
            {
                if (notSelected)
                {
                    Gizmos.color = pointColor;
                    Gizmos.DrawSphere(waypoints[i].position, 0.2f);
                }
                Gizmos.color = splineColor;
                for (int s = 0; s < waypoints[i].subways.Length; s++)
                {
                    rpp = waypoints[i].segments[s];
                    for (float t = rpp; t <= 1; t += rpp)
                    {
                        pointA = spline.GetPointAtTime(prevTime, i, s);
                        pointB = spline.GetPointAtTime(t, i, s);
                        Gizmos.DrawLine(pointA, pointB);
                        prevTime = t;
                    }
                    prevTime = 0;
                    Gizmos.DrawLine(pointB, waypoints[waypoints[i].subways[s]].position);
                }
            }
        }