Example #1
0
        /// <summary>
        /// Receive map style
        /// </summary>
        /// <param name="type"><see cref="MapStyleData.Type"/> of map style</param>
        /// <returns>Map style as <see cref="GameObjectOptions"/></returns>
        /// <exception cref="ArgumentNullException">Thrown when dataset does not contain <see cref="MapStyleData"/>
        /// of given <see cref="MapStyleData.Type"/></exception>
        public GameObjectOptions GetMapStyle(MapStyleData.Type type)
        {
            var styleData = mapStyleData.FirstOrDefault(element => element.StyleType == type);

            if (styleData == null)
            {
                throw new ArgumentNullException(nameof(styleData), $"Style of {type} type does not exist!");
            }

            var style = styleData.GenerateStyle();

            // Terrain style generation
            var terrainStyleBuilder = new TerrainStyle.Builder()
            {
                AlphaMapResolutionMetersPerPixel = alphaMapResolutionMetersPerPixel,
                BaseMapResolutionMetersPerPixel  = baseMapResolutionMetersPerPixel,
                BaseMapDistance = baseMapDistance,
                TerrainLayers   = new List <TerrainLayer>(terrainLayers)
            };

            style.TerrainStyle = terrainStyleBuilder.Build();

            // Segment style with adjustments to the terrain style
            var segmentStyleBuilder = new SegmentStyle.Builder(style.SegmentStyle)
            {
                GameObjectLayer = style.TerrainStyle.TerrainPaintingLayer
            };

            style.SegmentStyle = segmentStyleBuilder.Build();

            // Area water style with adjustments to the terrain style
            var areaWaterStyleBuilder = new AreaWaterStyle.Builder(style.AreaWaterStyle)
            {
                GameObjectLayer = style.TerrainStyle.TerrainPaintingLayer
            };

            style.AreaWaterStyle = areaWaterStyleBuilder.Build();

            // Region style with adjustments to the terrain style
            var regionStyleBuilder = new RegionStyle.Builder(style.RegionStyle)
            {
                GameObjectLayer = style.TerrainStyle.TerrainPaintingLayer
            };

            style.RegionStyle = regionStyleBuilder.Build();

            // Line water style with adjustments to the terrain style
            var lineWaterStyleBuilder = new LineWaterStyle.Builder(style.LineWaterStyle)
            {
                GameObjectLayer = style.TerrainStyle.TerrainPaintingLayer
            };

            style.LineWaterStyle = lineWaterStyleBuilder.Build();

            return(style);
        }
    /// <summary>
    /// Configures the map.
    /// </summary>
    private void Start()
    {
        MapsService mapsService = GetComponent <MapsService>();

        mapsService.InitFloatingOrigin(LoadingCenter);

        Material adminAreaMaterial = BaseMapMaterialUtils.CreateUniformColoredMaterial(AdminAreaColor);

        // Configure the map to only show prefectures and texture them with a solid color.
        mapsService.Events.RegionEvents.WillCreate.AddListener(args => {
            if (args.MapFeature.Metadata.Usage == RegionMetadata.UsageType.AdministrativeArea1)
            {
                RegionStyle.Builder style = args.Style.AsBuilder();
                style.FillMaterial        = adminAreaMaterial;
                args.Style = style.Build();
            }
            else
            {
                args.Cancel = true;
            }
        });

        // When a prefecture GameObject is created, create an extruded outline for it.
        Material borderMaterial = null;

        mapsService.Events.RegionEvents.DidCreate.AddListener(args => {
            if (borderMaterial == null)
            {
                // Set up the border material based on the prefecture material, but change the render queue
                // so that it renders on top.
                borderMaterial       = new Material(args.GameObject.GetComponent <Renderer>().material);
                borderMaterial.color = BorderColor;
                borderMaterial.renderQueue++;
            }
            Extruder.AddAreaExternalOutline(args.GameObject, borderMaterial, args.MapFeature.Shape,
                                            BorderWidth);
        });

        // Don't display water.
        mapsService.Events.AreaWaterEvents.WillCreate.AddListener(args => {
            args.Cancel = true;
        });

        // Load the map around Japan.
        mapsService.MakeMapLoadRegion()
        .AddCircle(mapsService.Coords.FromLatLngToVector3(LoadingCenter), 2000000) // 2,000 km.
        .Load(ExampleDefaults.DefaultGameObjectOptions, 5);                        // Zoom level 5.
    }
        /// <summary>
        /// Returns a new <see cref="GameObjectOptions"/> instance reflecting the properties on
        /// this component.
        /// </summary>
        private GameObjectOptions CreateGameObjectOptions()
        {
            GameObjectOptions gameObjectOptions = new GameObjectOptions();

            // Terrain style
            TerrainStyle.Builder terrainStyleBuilder = new TerrainStyle.Builder()
            {
                AlphaMapResolutionMetersPerPixel = AlphaMapResolutionMetersPerPixel,
                BaseMapResolutionMetersPerPixel  = BaseMapResolutionMetersPerPixel,
                BaseMapDistance = BaseMapDistance,
                TerrainLayers   = new List <TerrainLayer>(TerrainLayers),
            };
            gameObjectOptions.TerrainStyle = terrainStyleBuilder.Build();

            // Segment style
            SegmentStyle.Builder segmentStyleBuilder = new SegmentStyle.Builder()
            {
                Material             = SegmentMaterial,
                IntersectionMaterial = IntersectionMaterial,
                GameObjectLayer      = gameObjectOptions.TerrainStyle.TerrainPaintingLayer
            };
            gameObjectOptions.SegmentStyle = segmentStyleBuilder.Build();

            // Area water style
            AreaWaterStyle.Builder areaWaterStyleBuilder = new AreaWaterStyle.Builder()
            {
                FillMaterial    = AreaWaterMaterial,
                GameObjectLayer = gameObjectOptions.TerrainStyle.TerrainPaintingLayer
            };
            gameObjectOptions.AreaWaterStyle = areaWaterStyleBuilder.Build();

            // Region style
            RegionStyle.Builder regionStyleBuilder = new RegionStyle.Builder()
            {
                FillMaterial    = RegionMaterial,
                GameObjectLayer = gameObjectOptions.TerrainStyle.TerrainPaintingLayer
            };
            gameObjectOptions.RegionStyle = regionStyleBuilder.Build();

            // Line water style
            LineWaterStyle.Builder lineWaterStyleBuilder = new LineWaterStyle.Builder()
            {
                Material        = LineWaterMaterial,
                GameObjectLayer = gameObjectOptions.TerrainStyle.TerrainPaintingLayer
            };
            gameObjectOptions.LineWaterStyle = lineWaterStyleBuilder.Build();

            // Extruded structure style
            ExtrudedStructureStyle.Builder extrudedStructureStyleBuilder =
                new ExtrudedStructureStyle.Builder()
            {
                RoofMaterial = BuildingMaterial,
                WallMaterial = BuildingMaterial
            };
            gameObjectOptions.ExtrudedStructureStyle = extrudedStructureStyleBuilder.Build();

            // Modeled structure style
            ModeledStructureStyle.Builder modeledStructureStyleBuilder =
                new ModeledStructureStyle.Builder()
            {
                Material = BuildingMaterial
            };
            gameObjectOptions.ModeledStructureStyle = modeledStructureStyleBuilder.Build();

            return(gameObjectOptions);
        }