コード例 #1
0
    void Update()
    {
        if (roadNetwork != null)
        {
            float deltaT = Time.deltaTime;
            float rSpeed = (deltaT * speed);

            distance += rSpeed;

            // pass the current distance to get the position on the road
//			Debug.Log(road);
            Vector3 v = road.GetPosition(distance, ref currentElement);
            v.y += 1;

            go.transform.position = v;
            go.transform.forward  = road.GetLookatSmooth(distance, currentElement);;
        }

        // spline point info center of the road
        //      public function ERRoad.GetSplinePointsCenter() : Vector3[];

        // spline point info center of the road
        //      public function ERRoad.GetSplinePointsRightSide() : Vector3[];

        // spline point info center of the road
        //      public function ERRoad.GetSplinePointsLeftSide() : Vector3[];

        // Get the selected road in the Unity Editor
        //  public static function EREditor.GetSelectedRoad() : ERRoad;
    }
コード例 #2
0
        private void buildRoadVertexPath()
        {
            var vertexList     = new List <Vector3>();
            var directionsList = new List <Vector3>();
            var rotationsList  = new List <Quaternion>();
            var distanceList   = new List <float>();

            var currentRoadElement = 0;

            for (var t = 0f; t < road.GetDistance(); t += scanStep)
            {
                var p = road.GetPosition(t, ref currentRoadElement);
                var d = road.GetLookatSmooth(t, currentRoadElement);
                var r = Quaternion.LookRotation(d);

                var isSignificantVertex = vertexList.IsNullOrEmpty() || Vector3.Angle(d, directionsList.Last()) > angleThreshold;

                if (isSignificantVertex)
                {
                    vertexList.Add(p);
                    directionsList.Add(d);
                    rotationsList.Add(r);
                    distanceList.Add(t);
                }
            }

            positions  = vertexList.ToArray();
            directions = directionsList.ToArray();
            rotations  = rotationsList.ToArray();
            distances  = distanceList.ToArray();
        }