Ejemplo n.º 1
0
 // Token: 0x06002666 RID: 9830 RVA: 0x000E1A3C File Offset: 0x000DFE3C
 public void getTrackPosition(float t, out int index, out Vector3 position, out Vector3 normal)
 {
     position = this.getPosition(t, out index);
     normal   = Vector3.up;
     if (!this.joints[index].ignoreTerrain)
     {
         position.y = LevelGround.getHeight(position);
         normal     = LevelGround.getNormal(position);
     }
     position += normal * (LevelRoads.materials[(int)this.material].depth + LevelRoads.materials[(int)this.material].offset);
 }
Ejemplo n.º 2
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++;
            }
        }