/// <summary>
        /// Change the `LocationPath` the GameObject will traverse.
        /// </summary>
        /// <param name="path"></param>
        public void SetLocationPath(LocationPath path)
        {
            PathSettings.LocationPath = path;

            state.PointCount = PathSettings.LocationPath.Locations.Length;
            state.Points     = new Vector3[state.PointCount];


            BuildSpline(locationProvider.CurrentLocation.ToLocation());
        }
Пример #2
0
        void OnSceneGUI()
        {
            LocationPath locationPath = (LocationPath)target;

            if (locationPath.Locations == null)
            {
                return;
            }

            DrawOnSceneGui();
            DrawPath();
        }
Пример #3
0
        void DrawPath()
        {
            LocationPath locationPath  = (LocationPath)target;
            var          pathLocations = locationPath.Locations;

            if (pathLocations == null || pathLocations.Length < 2)
            {
                return;
            }

            var viewScale = sceneViewScale.floatValue;

            var points = new Vector3[pathLocations.Length];

            for (var i = 0; i < pathLocations.Length; i++)
            {
                var loc = pathLocations[i];
                points[i] = Vector3.Scale(loc.ToVector3(), new Vector3(viewScale, 1, viewScale));
            }


            //var points = curve.SamplePoints(100, p => getVec(p, curve.points[0]));
            var effScale = (1.0f + Mathf.Cos(viewScale * Mathf.PI / 2 - Mathf.PI));
            var s        = new Vector3(effScale, 1.0f, effScale);


            var newCPs = new Vector3[locationPath.Locations.Length];

            for (var i = 0; i < locationPath.Locations.Length; i++)
            {
                // ps.Add(locationPath.locations[i].ToVector3());

                var loc = locationPath.Locations[i];
                var p   = Location.GetGameObjectPositionForLocation(
                    null,
                    new Vector3(),
                    // new Transform(),
                    pathLocations[0],
                    pathLocations[i],
                    true
                    );
                Handles.color = Color.blue;
                Handles.SphereHandleCap(i, Vector3.Scale(p, s), Quaternion.identity, 0.4f, EventType.Repaint);
                Handles.Label(Vector3.Scale(p, s), loc.Label == "" ? ("   Point " + i) : loc.Label);
                newCPs[i] = Vector3.Scale(p, s);
            }

            Spline newPath;

            if (((SplineType)splineType.enumValueIndex) == SplineType.CatmullromSpline)
            {
                newPath = new CatmullRomSpline(newCPs, 100, alpha.floatValue);
            }
            else
            {
                newPath = new LinearSpline(newCPs);
            }

            var newSample = newPath.SamplePoints(1000);

            for (var i = 0; i < (newSample.Length - 2); i++)
            {
                Handles.color = Color.green;
                Handles.DrawLine(newSample[i + 1], newSample[i]);
            }
        }