Beispiel #1
0
        public Transform addPoint(Transform origin, Vector3 point)
        {
            RoadJoint roadJoint = new RoadJoint(point);

            if (origin == null || origin == this.paths[this.paths.Count - 1].vertex)
            {
                if (this.joints.Count > 0)
                {
                    roadJoint.setTangent(0, (this.joints[this.joints.Count - 1].vertex - point).normalized * 2.5f);
                }
                this.joints.Add(roadJoint);
                Transform transform = ((GameObject)UnityEngine.Object.Instantiate(Resources.Load("Edit/Path"))).transform;
                transform.name   = "Path_" + (this.joints.Count - 1);
                transform.parent = this.line;
                RoadPath roadPath = new RoadPath(transform);
                this.paths.Add(roadPath);
                this.updatePoints();
                return(roadPath.vertex);
            }
            if (origin == this.paths[0].vertex)
            {
                for (int i = 0; i < this.joints.Count; i++)
                {
                    this.paths[i].vertex.name = "Path_" + (i + 1);
                }
                if (this.joints.Count > 0)
                {
                    roadJoint.setTangent(1, (this.joints[0].vertex - point).normalized * 2.5f);
                }
                this.joints.Insert(0, roadJoint);
                Transform transform2 = ((GameObject)UnityEngine.Object.Instantiate(Resources.Load("Edit/Path"))).transform;
                transform2.name   = "Path_0";
                transform2.parent = this.line;
                RoadPath roadPath2 = new RoadPath(transform2);
                this.paths.Insert(0, roadPath2);
                this.updatePoints();
                return(roadPath2.vertex);
            }
            return(null);
        }
Beispiel #2
0
        // Token: 0x0600266F RID: 9839 RVA: 0x000E20AC File Offset: 0x000E04AC
        public Transform addVertex(int vertexIndex, Vector3 point)
        {
            RoadJoint roadJoint = new RoadJoint(point);

            for (int i = vertexIndex; i < this.joints.Count; i++)
            {
                this.paths[i].vertex.name = "Path_" + (i + 1);
            }
            if (this.joints.Count == 1)
            {
                this.joints[0].setTangent(1, (point - this.joints[0].vertex).normalized * 2.5f);
                roadJoint.setTangent(0, (this.joints[0].vertex - point).normalized * 2.5f);
            }
            else if (this.joints.Count > 1)
            {
                if (vertexIndex == 0)
                {
                    if (this.isLoop)
                    {
                        RoadJoint roadJoint2 = this.joints[this.joints.Count - 1];
                        RoadJoint roadJoint3 = this.joints[0];
                        roadJoint.setTangent(1, (roadJoint3.vertex - roadJoint2.vertex).normalized * 2.5f);
                    }
                    else
                    {
                        roadJoint.setTangent(1, (this.joints[0].vertex - point).normalized * 2.5f);
                    }
                }
                else if (vertexIndex == this.joints.Count)
                {
                    if (this.isLoop)
                    {
                        RoadJoint roadJoint4 = this.joints[this.joints.Count - 1];
                        RoadJoint roadJoint5 = this.joints[0];
                        roadJoint.setTangent(1, (roadJoint5.vertex - roadJoint4.vertex).normalized * 2.5f);
                    }
                    else
                    {
                        roadJoint.setTangent(0, (this.joints[this.joints.Count - 1].vertex - point).normalized * 2.5f);
                    }
                }
                else
                {
                    RoadJoint roadJoint6 = this.joints[vertexIndex - 1];
                    RoadJoint roadJoint7 = this.joints[vertexIndex];
                    roadJoint.setTangent(1, (roadJoint7.vertex - roadJoint6.vertex).normalized * 2.5f);
                }
            }
            this.joints.Insert(vertexIndex, roadJoint);
            Transform transform = ((GameObject)UnityEngine.Object.Instantiate(Resources.Load("Edit/Path"))).transform;

            transform.name   = "Path_" + vertexIndex;
            transform.parent = this.line;
            RoadPath roadPath = new RoadPath(transform);

            this.paths.Insert(vertexIndex, roadPath);
            this.updatePoints();
            return(roadPath.vertex);
        }
Beispiel #3
0
 public static void load()
 {
     LevelRoads._models                 = new GameObject().transform;
     LevelRoads.models.name             = "Roads";
     LevelRoads.models.parent           = Level.level;
     LevelRoads.models.tag              = "Logic";
     LevelRoads.models.gameObject.layer = LayerMasks.LOGIC;
     if (ReadWrite.fileExists(Level.info.path + "/Environment/Roads.unity3d", false, false))
     {
         Bundle   bundle = Bundles.getBundle(Level.info.path + "/Environment/Roads.unity3d", false);
         Object[] array  = bundle.load();
         bundle.unload();
         LevelRoads._materials = new RoadMaterial[array.Length];
         for (int i = 0; i < LevelRoads.materials.Length; i++)
         {
             LevelRoads.materials[i] = new RoadMaterial((Texture2D)array[i]);
         }
     }
     else
     {
         LevelRoads._materials = new RoadMaterial[0];
     }
     LevelRoads.roads = new List <Road>();
     if (ReadWrite.fileExists(Level.info.path + "/Environment/Roads.dat", false, false))
     {
         River river = new River(Level.info.path + "/Environment/Roads.dat", false);
         byte  b     = river.readByte();
         if (b > 0)
         {
             byte b2 = river.readByte();
             for (byte b3 = 0; b3 < b2; b3 += 1)
             {
                 if ((int)b3 >= LevelRoads.materials.Length)
                 {
                     break;
                 }
                 LevelRoads.materials[(int)b3].width  = river.readSingle();
                 LevelRoads.materials[(int)b3].height = river.readSingle();
                 LevelRoads.materials[(int)b3].depth  = river.readSingle();
                 if (b > 1)
                 {
                     LevelRoads.materials[(int)b3].offset = river.readSingle();
                 }
                 LevelRoads.materials[(int)b3].isConcrete = river.readBoolean();
             }
         }
         river.closeRiver();
     }
     if (ReadWrite.fileExists(Level.info.path + "/Environment/Paths.dat", false, false))
     {
         River river2 = new River(Level.info.path + "/Environment/Paths.dat", false);
         byte  b4     = river2.readByte();
         if (b4 > 1)
         {
             ushort num = river2.readUInt16();
             for (ushort num2 = 0; num2 < num; num2 += 1)
             {
                 ushort           num3        = river2.readUInt16();
                 byte             newMaterial = river2.readByte();
                 bool             newLoop     = b4 > 2 && river2.readBoolean();
                 List <RoadJoint> list        = new List <RoadJoint>();
                 for (ushort num4 = 0; num4 < num3; num4 += 1)
                 {
                     Vector3   vertex = river2.readSingleVector3();
                     Vector3[] array2 = new Vector3[2];
                     if (b4 > 2)
                     {
                         array2[0] = river2.readSingleVector3();
                         array2[1] = river2.readSingleVector3();
                     }
                     ERoadMode mode;
                     if (b4 > 2)
                     {
                         mode = (ERoadMode)river2.readByte();
                     }
                     else
                     {
                         mode = ERoadMode.FREE;
                     }
                     float offset;
                     if (b4 > 4)
                     {
                         offset = river2.readSingle();
                     }
                     else
                     {
                         offset = 0f;
                     }
                     bool      ignoreTerrain = b4 > 3 && river2.readBoolean();
                     RoadJoint item          = new RoadJoint(vertex, array2, mode, offset, ignoreTerrain);
                     list.Add(item);
                 }
                 if (b4 < 3)
                 {
                     for (ushort num5 = 0; num5 < num3; num5 += 1)
                     {
                         RoadJoint roadJoint = list[(int)num5];
                         if (num5 == 0)
                         {
                             roadJoint.setTangent(0, (roadJoint.vertex - list[(int)(num5 + 1)].vertex).normalized * 2.5f);
                             roadJoint.setTangent(1, (list[(int)(num5 + 1)].vertex - roadJoint.vertex).normalized * 2.5f);
                         }
                         else if (num5 == num3 - 1)
                         {
                             roadJoint.setTangent(0, (list[(int)(num5 - 1)].vertex - roadJoint.vertex).normalized * 2.5f);
                             roadJoint.setTangent(1, (roadJoint.vertex - list[(int)(num5 - 1)].vertex).normalized * 2.5f);
                         }
                         else
                         {
                             roadJoint.setTangent(0, (list[(int)(num5 - 1)].vertex - roadJoint.vertex).normalized * 2.5f);
                             roadJoint.setTangent(1, (list[(int)(num5 + 1)].vertex - roadJoint.vertex).normalized * 2.5f);
                         }
                     }
                 }
                 LevelRoads.roads.Add(new Road(newMaterial, newLoop, list));
             }
         }
         else if (b4 > 0)
         {
             byte b5 = river2.readByte();
             for (byte b6 = 0; b6 < b5; b6 += 1)
             {
                 byte             b7           = river2.readByte();
                 byte             newMaterial2 = river2.readByte();
                 List <RoadJoint> list2        = new List <RoadJoint>();
                 for (byte b8 = 0; b8 < b7; b8 += 1)
                 {
                     Vector3   vertex2  = river2.readSingleVector3();
                     Vector3[] tangents = new Vector3[2];
                     ERoadMode mode2    = ERoadMode.FREE;
                     RoadJoint item2    = new RoadJoint(vertex2, tangents, mode2, 0f, false);
                     list2.Add(item2);
                 }
                 for (byte b9 = 0; b9 < b7; b9 += 1)
                 {
                     RoadJoint roadJoint2 = list2[(int)b9];
                     if (b9 == 0)
                     {
                         roadJoint2.setTangent(0, (roadJoint2.vertex - list2[(int)(b9 + 1)].vertex).normalized * 2.5f);
                         roadJoint2.setTangent(1, (list2[(int)(b9 + 1)].vertex - roadJoint2.vertex).normalized * 2.5f);
                     }
                     else if (b9 == b7 - 1)
                     {
                         roadJoint2.setTangent(0, (list2[(int)(b9 - 1)].vertex - roadJoint2.vertex).normalized * 2.5f);
                         roadJoint2.setTangent(1, (roadJoint2.vertex - list2[(int)(b9 - 1)].vertex).normalized * 2.5f);
                     }
                     else
                     {
                         roadJoint2.setTangent(0, (list2[(int)(b9 - 1)].vertex - roadJoint2.vertex).normalized * 2.5f);
                         roadJoint2.setTangent(1, (list2[(int)(b9 + 1)].vertex - roadJoint2.vertex).normalized * 2.5f);
                     }
                 }
                 LevelRoads.roads.Add(new Road(newMaterial2, false, list2));
             }
         }
         river2.closeRiver();
     }
     if (LevelGround.terrain != null)
     {
         LevelRoads.buildMeshes();
     }
     if (!LevelRoads.isListeningForLandscape)
     {
         LevelRoads.isListeningForLandscape = true;
         if (LevelRoads.< > f__mg$cache0 == null)
         {
             LevelRoads.< > f__mg$cache0 = new LandscapeLoadedHandler(LevelRoads.handleLandscapeLoaded);
         }
         Landscape.loaded += LevelRoads.< > f__mg$cache0;
     }
 }