Esempio n. 1
0
        private void Start()
        {
            if (Parent == null)
            {
                Parent = gameObject;
            }
            if (GetComponent <ConvertToEntity>() != null)
            {
                return;
            }

            m_spline = Spline == null ? null : Spline.GetComponent <ISpline2D>();
            if (m_spline == null)
            {
                Debug.LogError("Please assign a spline");
                enabled = false;
                return;
            }

            for (int i = 0; i < Quantity; i++)
            {
                GameObject example = Instantiate(Prefab, Parent.transform, true);

                Spline2DTraverser mover = example.GetComponent <Spline2DTraverser>();
                mover.Spline   = m_spline;
                mover.Progress = Random.Range(0f, 1f);
#if UNITY_EDITOR
                mover.transform.name = "Mover " + (i + 1);
#endif
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a spline job from this spline
        /// </summary>
        /// <param name="spline">spline to generate a job from</param>
        /// <param name="progress">progress to use when initializing job</param>
        /// <param name="allocator">allocator to use for result values</param>
        /// <returns>spline point retrieval job</returns>
        public static ISplineJob2D ExtractJob(this ISpline2D spline, SplineProgress progress = default, Allocator allocator = Allocator.None)
        {
            switch (spline.SplineDataType)
            {
            case SplineType.Empty:
                return(new Empty2DPointJob(allocator));

            case SplineType.Single:
                return(new SinglePoint2DPointJob(spline, allocator));

            case SplineType.Bezier:
                return(new BezierSpline2DPointJob(spline, progress, allocator));

            case SplineType.CubicLinear:
                return(new LinearCubicSpline2DPointJob(spline, progress, allocator));

            case SplineType.Cubic:
            //todo
            case SplineType.BSpline:
            //todo
            case SplineType.CatmullRom:
                return(new CatmullRomSpline2DPointJob(spline, progress, allocator));

            case SplineType.Linear:     // falls over to the default by design
            default:
                return(new LinearSpline2DPointJob(spline, progress, allocator));
            }
        }
Esempio n. 3
0
        protected override IEnumerable <float3> PointData(ISpline spline)
        {
            ISpline2D spline3D = (spline as ISpline2D);

            foreach (float2 point in spline3D.SplineEntityData2D.Value.Points)
            {
                yield return(new float3(point, 0f));
            }
        }
Esempio n. 4
0
        protected override int SplineSegmentPointCount(ISpline spline)
        {
            ISpline2D spline3D = (spline as ISpline2D);

            Assert.NotNull(spline3D, "Unable to convert spline");
            Assert.NotNull(spline3D.SplineEntityData2D, "spline failed to generate data");

            return(spline3D.SplineEntityData2D.Value.Points.Length);
        }
Esempio n. 5
0
        /// <summary>
        /// Renders points along the spline to demonstrate possible point bunching along the splines length
        /// </summary>
        /// <param name="quantity">amount of points to render</param>
        /// <param name="spline">spline to render on</param>
        protected static void RenderIntermediateSplinePoints(float quantity, ISpline2D spline)
        {
            Handles.color = Color.red;
            const float multiplier = 0.3f;

            for (int i = 0; i <= quantity; i++)
            {
                float progress = i == 0 ? 0f : i / (quantity - 1f);
                HandleDrawPlus(spline.Get2DPointWorld(progress), multiplier);
            }
        }
Esempio n. 6
0
        private float2 getPointViaJob(ISpline2D spline, float progress)
        {
            switch (spline.SplineDataType)
            {
            case SplineType.Bezier:
                BezierSpline2DPointJob bzSpline = new BezierSpline2DPointJob(spline, progress, Allocator.Temp);
                bzSpline.Execute();

                float2 result = bzSpline.Result;
                bzSpline.Dispose();
                return(result);

            case SplineType.Linear:
                LinearSpline2DPointJob pSpline = new LinearSpline2DPointJob(spline, progress, Allocator.Temp);
                pSpline.Execute();
                return(pSpline.Result);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Create a spline job from this spline
 /// </summary>
 /// <param name="spline">spline to generate a job from</param>
 /// <param name="progress">progress to use when initializing job</param>
 /// <param name="allocator">allocator to use for result values</param>
 /// <returns>spline point retrieval job</returns>
 public static ISplineJob2D ExtractJob(this ISpline2D spline, float progress, Allocator allocator = Allocator.None)
 {
     return(ExtractJob(spline, new SplineProgress(progress), allocator));
 }