예제 #1
0
        /// <summary>
        /// Sets the distance variable to an appropriate value if slider is normalized.  Called from the custom editor.
        /// </summary>
        public void SetSplinePosition()
        {
            currDist = distance;

            if (interpStyle == InterpStyle.Normalized)
            {
                currDist = distance * spline.GetTotalLength();
            }

            MoveAlongSpline(currDist);
        }
예제 #2
0
        /// <summary>
        /// Spawns prefabs along the spline.
        /// </summary>
        public void GeneratePrefabsAlongSpline()
        {
            if (!prefab || !spline)
            {
                return;
            }

            float length      = spline.GetTotalLength();
            int   count       = (placementStyle == PlacementStyle.Distance) ? Mathf.FloorToInt(length / spacing) : instanceCount;
            float currSpacing = (placementStyle == PlacementStyle.Distance) ? spacing : ((spline.GetTotalLength() - 0.05f) / instanceCount);

            for (int i = 0; i < count; i++)
            {
                if (spawnedObjects.Count <= i || spawnedObjects == null)
                {
                    spawnedObjects.Add(Instantiate(prefab, transform));
                }

                float     dist = (i + 1) * currSpacing;
                Transform t    = spawnedObjects[i].transform;
                t.position = spline.GetPointOnSplineByDistance(dist);

                if (lookForward)
                {
                    t.rotation = Quaternion.LookRotation(spline.GetDerivativeByDistance(dist), Vector3.up);
                }
            }

            for (int i = spawnedObjects.Count - 1; i >= count; i--)
            {
                GameObject g = spawnedObjects[i];
                spawnedObjects.RemoveAt(i);
                DestroyImmediate(g);
            }
        }