Example #1
0
        // Token: 0x06002678 RID: 9848 RVA: 0x000E3A00 File Offset: 0x000E1E00
        private void updateSamples()
        {
            this.samples.Clear();
            float num = 0f;

            for (int i = 0; i < this.joints.Count - 1 + ((!this.isLoop) ? 0 : 1); i++)
            {
                float lengthEstimate = this.getLengthEstimate(i);
                float num2;
                for (num2 = num; num2 < lengthEstimate; num2 += 5f)
                {
                    float      time       = num2 / lengthEstimate;
                    RoadSample roadSample = new RoadSample();
                    roadSample.index = i;
                    roadSample.time  = time;
                    this.samples.Add(roadSample);
                }
                num = num2 - lengthEstimate;
            }
            if (this.isLoop)
            {
                RoadSample roadSample2 = new RoadSample();
                roadSample2.index = 0;
                roadSample2.time  = 0f;
                this.samples.Add(roadSample2);
            }
            else
            {
                RoadSample roadSample3 = new RoadSample();
                roadSample3.index = this.joints.Count - 2;
                roadSample3.time  = 1f;
                this.samples.Add(roadSample3);
            }
        }
Example #2
0
 // Token: 0x0600267A RID: 9850 RVA: 0x000E3CAC File Offset: 0x000E20AC
 public void updatePoints()
 {
     for (int i = 0; i < this.joints.Count; i++)
     {
         RoadJoint roadJoint = this.joints[i];
         if (!roadJoint.ignoreTerrain)
         {
             roadJoint.vertex.y = LevelGround.getHeight(roadJoint.vertex);
         }
     }
     for (int j = 0; j < this.joints.Count; j++)
     {
         RoadPath roadPath = this.paths[j];
         roadPath.vertex.position = this.joints[j].vertex;
         roadPath.tangents[0].gameObject.SetActive(j > 0 || this.isLoop);
         roadPath.tangents[1].gameObject.SetActive(j < this.joints.Count - 1 || this.isLoop);
         roadPath.setTangent(0, this.joints[j].getTangent(0));
         roadPath.setTangent(1, this.joints[j].getTangent(1));
     }
     if (this.joints.Count < 2)
     {
         this.lineRenderer.numPositions = 0;
         return;
     }
     this.updateSamples();
     this.lineRenderer.numPositions = this.samples.Count;
     for (int k = 0; k < this.samples.Count; k++)
     {
         RoadSample roadSample = this.samples[k];
         RoadJoint  roadJoint2 = this.joints[roadSample.index];
         Vector3    position   = this.getPosition(roadSample.index, roadSample.time);
         if (!roadJoint2.ignoreTerrain)
         {
             position.y = LevelGround.getHeight(position);
         }
         if (roadSample.index < this.joints.Count - 1)
         {
             position.y += Mathf.Lerp(roadJoint2.offset, this.joints[roadSample.index + 1].offset, roadSample.time);
         }
         else if (this.isLoop)
         {
             position.y += Mathf.Lerp(roadJoint2.offset, this.joints[0].offset, roadSample.time);
         }
         else
         {
             position.y += roadJoint2.offset;
         }
         this.lineRenderer.SetPosition(k, position);
     }
 }
Example #3
0
        // Token: 0x06002679 RID: 9849 RVA: 0x000E3B08 File Offset: 0x000E1F08
        private void updateTrackSamples()
        {
            this.trackSamples.Clear();
            if (this.samples.Count < 2)
            {
                return;
            }
            Vector3 vector = Vector3.zero;
            Vector3 up     = Vector3.up;
            double  num    = 0.0;
            int     num2   = (!this.isLoop) ? this.samples.Count : (this.samples.Count - 1);

            for (int i = 1; i < num2; i++)
            {
                RoadSample  roadSample  = this.samples[i];
                TrackSample trackSample = null;
                if (i == 1)
                {
                    RoadSample roadSample2 = this.samples[0];
                    this.getTrackPosition(roadSample2.index, roadSample2.time, out vector, out up);
                    trackSample          = new TrackSample();
                    trackSample.position = vector;
                    trackSample.normal   = up;
                    this.trackSamples.Add(trackSample);
                }
                Vector3 vector2;
                Vector3 normal;
                this.getTrackPosition(roadSample.index, roadSample.time, out vector2, out normal);
                Vector3     a            = vector2 - vector;
                float       magnitude    = a.magnitude;
                Vector3     direction    = a / magnitude;
                TrackSample trackSample2 = new TrackSample();
                trackSample2.distance  = (float)num;
                trackSample2.position  = vector2;
                trackSample2.normal    = normal;
                trackSample2.direction = direction;
                this.trackSamples.Add(trackSample2);
                if (trackSample != null)
                {
                    trackSample.direction = direction;
                }
                vector = vector2;
                num   += (double)magnitude;
            }
            if (this.isLoop)
            {
                num += (double)(this.trackSamples[0].position - vector).magnitude;
            }
            this.trackSampledLength = (float)num;
        }
Example #4
0
        // Token: 0x06002677 RID: 9847 RVA: 0x000E25D0 File Offset: 0x000E09D0
        public void buildMesh()
        {
            for (int i = 0; i < this.road.childCount; i++)
            {
                UnityEngine.Object.Destroy(this.road.GetChild(i).gameObject);
            }
            if (this.joints.Count < 2)
            {
                return;
            }
            this.updateSamples();
            if (!Level.isEditor)
            {
                bool flag = false;
                foreach (LevelTrainAssociation levelTrainAssociation in Level.info.configData.Trains)
                {
                    if (levelTrainAssociation.RoadIndex == this.roadIndex)
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    this.updateTrackSamples();
                }
            }
            Vector3[] array   = new Vector3[this.samples.Count * 4 + ((!this.isLoop) ? 8 : 0)];
            Vector3[] array2  = new Vector3[this.samples.Count * 4 + ((!this.isLoop) ? 8 : 0)];
            Vector2[] array3  = new Vector2[this.samples.Count * 4 + ((!this.isLoop) ? 8 : 0)];
            float     num     = 0f;
            Vector3   b       = Vector3.zero;
            Vector3   vector  = Vector3.zero;
            Vector3   vector2 = Vector3.zero;
            Vector3   vector3 = Vector3.zero;
            Vector3   a       = Vector3.zero;
            Vector2   b2      = Vector2.zero;
            int       j;

            for (j = 0; j < this.samples.Count; j++)
            {
                RoadSample roadSample = this.samples[j];
                RoadJoint  roadJoint  = this.joints[roadSample.index];
                vector = this.getPosition(roadSample.index, roadSample.time);
                if (!roadJoint.ignoreTerrain)
                {
                    vector.y = LevelGround.getHeight(vector);
                }
                vector2 = this.getVelocity(roadSample.index, roadSample.time).normalized;
                if (roadJoint.ignoreTerrain)
                {
                    vector3 = Vector3.up;
                }
                else
                {
                    vector3 = LevelGround.getNormal(vector);
                }
                a = Vector3.Cross(vector2, vector3);
                if (!roadJoint.ignoreTerrain)
                {
                    Vector3 point = vector + a * LevelRoads.materials[(int)this.material].width;
                    float   num2  = LevelGround.getHeight(point) - point.y;
                    if (num2 > 0f)
                    {
                        vector.y += num2;
                    }
                    Vector3 point2 = vector - a * LevelRoads.materials[(int)this.material].width;
                    float   num3   = LevelGround.getHeight(point2) - point2.y;
                    if (num3 > 0f)
                    {
                        vector.y += num3;
                    }
                }
                if (roadSample.index < this.joints.Count - 1)
                {
                    vector.y += Mathf.Lerp(roadJoint.offset, this.joints[roadSample.index + 1].offset, roadSample.time);
                }
                else if (this.isLoop)
                {
                    vector.y += Mathf.Lerp(roadJoint.offset, this.joints[0].offset, roadSample.time);
                }
                else
                {
                    vector.y += roadJoint.offset;
                }
                array[((!this.isLoop) ? 4 : 0) + j * 4]      = vector + a * (LevelRoads.materials[(int)this.material].width + LevelRoads.materials[(int)this.material].depth * 2f) - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset;
                array[((!this.isLoop) ? 4 : 0) + j * 4 + 1]  = vector + a * LevelRoads.materials[(int)this.material].width + vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset;
                array[((!this.isLoop) ? 4 : 0) + j * 4 + 2]  = vector - a * LevelRoads.materials[(int)this.material].width + vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset;
                array[((!this.isLoop) ? 4 : 0) + j * 4 + 3]  = vector - a * (LevelRoads.materials[(int)this.material].width + LevelRoads.materials[(int)this.material].depth * 2f) - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset;
                array2[((!this.isLoop) ? 4 : 0) + j * 4]     = vector3;
                array2[((!this.isLoop) ? 4 : 0) + j * 4 + 1] = vector3;
                array2[((!this.isLoop) ? 4 : 0) + j * 4 + 2] = vector3;
                array2[((!this.isLoop) ? 4 : 0) + j * 4 + 3] = vector3;
                if (j == 0)
                {
                    b = vector;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4]     = Vector2.zero;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4 + 1] = Vector2.zero;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4 + 2] = Vector2.right;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4 + 3] = Vector2.right;
                }
                else
                {
                    num += (vector - b).magnitude;
                    b    = vector;
                    b2   = Vector2.up * num / (float)LevelRoads.materials[(int)this.material].material.mainTexture.height * LevelRoads.materials[(int)this.material].height;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4]     = Vector2.zero + b2;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4 + 1] = Vector2.zero + b2;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4 + 2] = Vector2.right + b2;
                    array3[((!this.isLoop) ? 4 : 0) + j * 4 + 3] = Vector2.right + b2;
                }
            }
            if (!this.isLoop)
            {
                array[4 + j * 4]      = vector + a * (LevelRoads.materials[(int)this.material].width + LevelRoads.materials[(int)this.material].depth * 2f) - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset + vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array[4 + j * 4 + 1]  = vector + a * LevelRoads.materials[(int)this.material].width - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset + vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array[4 + j * 4 + 2]  = vector - a * LevelRoads.materials[(int)this.material].width - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset + vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array[4 + j * 4 + 3]  = vector - a * (LevelRoads.materials[(int)this.material].width + LevelRoads.materials[(int)this.material].depth * 2f) - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset + vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array2[4 + j * 4]     = vector3;
                array2[4 + j * 4 + 1] = vector3;
                array2[4 + j * 4 + 2] = vector3;
                array2[4 + j * 4 + 3] = vector3;
                b2 = Vector2.up * num / (float)LevelRoads.materials[(int)this.material].material.mainTexture.height * LevelRoads.materials[(int)this.material].height;
                array3[4 + j * 4]     = Vector2.zero + b2;
                array3[4 + j * 4 + 1] = Vector2.zero + b2;
                array3[4 + j * 4 + 2] = Vector2.right + b2;
                array3[4 + j * 4 + 3] = Vector2.right + b2;
                j      = 0;
                vector = this.getPosition(this.samples[0].index, this.samples[0].time);
                if (!this.joints[0].ignoreTerrain)
                {
                    vector.y = LevelGround.getHeight(vector);
                }
                vector2 = this.getVelocity(this.samples[0].index, this.samples[0].time).normalized;
                if (this.joints[0].ignoreTerrain)
                {
                    vector3 = LevelGround.getNormal(this.joints[0].vertex);
                }
                else
                {
                    vector3 = LevelGround.getNormal(vector);
                }
                a = Vector3.Cross(vector2, vector3);
                if (!this.joints[0].ignoreTerrain)
                {
                    Vector3 point3 = vector + a * LevelRoads.materials[(int)this.material].width;
                    float   num4   = LevelGround.getHeight(point3) - point3.y;
                    if (num4 > 0f)
                    {
                        vector.y += num4;
                    }
                    Vector3 point4 = vector - a * LevelRoads.materials[(int)this.material].width;
                    float   num5   = LevelGround.getHeight(point4) - point4.y;
                    if (num5 > 0f)
                    {
                        vector.y += num5;
                    }
                }
                vector.y         += this.joints[0].offset;
                array[j * 4]      = vector + a * (LevelRoads.materials[(int)this.material].width + LevelRoads.materials[(int)this.material].depth * 2f) - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset - vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array[j * 4 + 1]  = vector + a * LevelRoads.materials[(int)this.material].width - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset - vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array[j * 4 + 2]  = vector - a * LevelRoads.materials[(int)this.material].width - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset - vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array[j * 4 + 3]  = vector - a * (LevelRoads.materials[(int)this.material].width + LevelRoads.materials[(int)this.material].depth * 2f) - vector3 * LevelRoads.materials[(int)this.material].depth + vector3 * LevelRoads.materials[(int)this.material].offset - vector2 * LevelRoads.materials[(int)this.material].depth * 4f;
                array2[j * 4]     = vector3;
                array2[j * 4 + 1] = vector3;
                array2[j * 4 + 2] = vector3;
                array2[j * 4 + 3] = vector3;
                array3[j * 4]     = Vector2.zero;
                array3[j * 4 + 1] = Vector2.zero;
                array3[j * 4 + 2] = Vector2.right;
                array3[j * 4 + 3] = Vector2.right;
            }
            int num6 = 0;

            for (int k = 0; k < this.samples.Count; k += 20)
            {
                int num7 = Mathf.Min(k + 20, this.samples.Count - 1);
                int num8 = num7 - k + 1;
                if (!this.isLoop)
                {
                    if (k == 0)
                    {
                        num8++;
                    }
                    if (num7 == this.samples.Count - 1)
                    {
                        num8++;
                    }
                }
                Vector3[] array4 = new Vector3[num8 * 4];
                Vector3[] array5 = new Vector3[num8 * 4];
                Vector2[] array6 = new Vector2[num8 * 4];
                int[]     array7 = new int[num8 * 18];
                int       num9   = k;
                if (!this.isLoop && k > 0)
                {
                    num9++;
                }
                Array.Copy(array, num9 * 4, array4, 0, array4.Length);
                Array.Copy(array2, num9 * 4, array5, 0, array4.Length);
                Array.Copy(array3, num9 * 4, array6, 0, array4.Length);
                for (int l = 0; l < num8 - 1; l++)
                {
                    array7[l * 18]      = l * 4 + 5;
                    array7[l * 18 + 1]  = l * 4 + 1;
                    array7[l * 18 + 2]  = l * 4 + 4;
                    array7[l * 18 + 3]  = l * 4;
                    array7[l * 18 + 4]  = l * 4 + 4;
                    array7[l * 18 + 5]  = l * 4 + 1;
                    array7[l * 18 + 6]  = l * 4 + 6;
                    array7[l * 18 + 7]  = l * 4 + 2;
                    array7[l * 18 + 8]  = l * 4 + 5;
                    array7[l * 18 + 9]  = l * 4 + 1;
                    array7[l * 18 + 10] = l * 4 + 5;
                    array7[l * 18 + 11] = l * 4 + 2;
                    array7[l * 18 + 12] = l * 4 + 7;
                    array7[l * 18 + 13] = l * 4 + 3;
                    array7[l * 18 + 14] = l * 4 + 6;
                    array7[l * 18 + 15] = l * 4 + 2;
                    array7[l * 18 + 16] = l * 4 + 6;
                    array7[l * 18 + 17] = l * 4 + 3;
                }
                Transform transform = new GameObject().transform;
                transform.name             = "Segment_" + num6;
                transform.parent           = this.road;
                transform.tag              = "Environment";
                transform.gameObject.layer = LayerMasks.ENVIRONMENT;
                transform.gameObject.AddComponent <MeshCollider>();
                if (!Dedicator.isDedicated)
                {
                    transform.gameObject.AddComponent <MeshFilter>();
                    MeshRenderer meshRenderer = transform.gameObject.AddComponent <MeshRenderer>();
                    meshRenderer.reflectionProbeUsage = ReflectionProbeUsage.Simple;
                    meshRenderer.shadowCastingMode    = ShadowCastingMode.Off;
                }
                if (LevelRoads.materials[(int)this.material].isConcrete)
                {
                    transform.GetComponent <Collider>().sharedMaterial = (PhysicMaterial)Resources.Load("Physics/Concrete_Static");
                }
                else
                {
                    transform.GetComponent <Collider>().sharedMaterial = (PhysicMaterial)Resources.Load("Physics/Gravel_Static");
                }
                Mesh mesh = new Mesh();
                mesh.name      = "Road_Segment_" + num6;
                mesh.vertices  = array4;
                mesh.normals   = array5;
                mesh.uv        = array6;
                mesh.triangles = array7;
                transform.GetComponent <MeshCollider>().sharedMesh = mesh;
                if (!Dedicator.isDedicated)
                {
                    transform.GetComponent <MeshFilter>().sharedMesh   = mesh;
                    transform.GetComponent <Renderer>().sharedMaterial = LevelRoads.materials[(int)this.material].material;
                }
                num6++;
            }
        }