Beispiel #1
0
 /**
  * Singleton for road object render
  */
 public static RoadObjectRender Get()
 {
     if (roadObjectRender == null)
     {
         roadObjectRender = (new GameObject("RoadObjectRender")).AddComponent <RoadObjectRender>();
     }
     return(roadObjectRender);
 }
Beispiel #2
0
        /**
         * Render roads
         */
        public void Render(LatLngObject mapMiddleMapPoint, Transform cameraTransform, List <RoadObject> roads)
        {
            if (roads.Count == 0)
            {
                return;
            }

            var middleMapPoint = Converter.ConvertLatLngToXyz(mapMiddleMapPoint);

            //save into global variable
            Roads = roads;
            var terrain = TerrainRender.Get().Terrain;

            //render roads
            for (var i = 0; i < roads.Count; i++)
            {
                var ySize = 1;

                var roadPointInXyz = new Vector3[roads[i].LatLngCoordinates.Count];
                if (roadPointInXyz.Length == 0)
                {
                    continue;
                }

                //convert road point from LatLng to Xyz coordination's; Y coordinate values set as terrain height
                for (var j = 0; j < roadPointInXyz.Length; j++)
                {
                    roadPointInXyz[j] = Converter.ConvertLatLngToXyz(roads[i].LatLngCoordinates[j]);
                    //pricteni hodnoty navic proti prolinani s terenem
                    roadPointInXyz[j].y = terrain.SampleHeight(roadPointInXyz[j]) + 0.03f;
                }

                //road starts outside terrain => reverse points
                if (TerrainUtils.IsObjectOutsideMap(roadPointInXyz[0], middleMapPoint))
                {
                    Array.Reverse(roadPointInXyz);
                }

                //points of road
                for (var j = 0; j < roadPointInXyz.Length; j++)
                {
                    var roadPoint = roadPointInXyz[j];
                    //pokud je mezi dvěma body cesty rozdíl větší než 1
                    if (j == 0 || Math.Abs(roadPoint.x - roadPointInXyz[j - 1].x) >= 1 || Math.Abs(roadPoint.z - roadPointInXyz[j - 1].z) >= 1)
                    {
                        continue;
                    }

                    //snižovat souřadnici Y cesty, pokud je za hranou terénu (efekt padání cesty)
                    if (TerrainUtils.IsObjectOutsideMap(roadPoint, middleMapPoint))
                    {
                        roadPointInXyz[j].y -= ySize;
                        ySize++;
                    }
                }

                //vytvoreni cesty(nastaveni barvy, pozic, poctu pozic...)
                CreateRoadObject(roads, roadPointInXyz, i);

                //set cars for road type
                var carRoads     = new[] { RoadUtils.Secondary };
                var vehicleTypes = new[] { RoadUtils.VehicleTram };
                if (Main.Settings.RoadObjectsToggle && carRoads.Contains(roads[i].RoadType) || vehicleTypes.Contains(roads[i].VehicleType))
                {
                    roads[i].XyzCoordinates = roadPointInXyz;
                    RoadObjectRender.Get().RenderObjectsOnRoad(roads[i], middleMapPoint);
                }

                UiUtils.SetDefaultCameraPos(middleMapPoint, cameraTransform);
            }
        }