示例#1
0
    /// <summary>
    /// Get <see cref="MapsService"/> and use it to load geometry.
    /// </summary>
    private void Start()
    {
        // Get required Maps Service component on this GameObject.
        MapsService mapsService = GetComponent <MapsService>();

        // Set location to load.
        mapsService.InitFloatingOrigin(LatLng);

        // Create a roads style that defines a material for roads and for borders of roads. The specific
        // border material used is chosen to look just a little darker than the material of the ground
        // plane (helping the roads to visually blend into the surrounding ground).
        SegmentStyle roadsStyle = new SegmentStyle.Builder {
            Material       = Roads,
            BorderMaterial = RoadEdges,
            Width          = 7.0f,
            BorderWidth    = 1.0f
        }.Build();

        // Get default style options.
        GameObjectOptions renderingStyles = ExampleDefaults.DefaultGameObjectOptions;

        // Replace default roads style with new, just created roads style.
        renderingStyles.SegmentStyle = roadsStyle;

        // Load map with desired options.
        mapsService.LoadMap(ExampleDefaults.DefaultBounds, renderingStyles);
    }
示例#2
0
        /// <summary>
        /// Use <see cref="MapsService"/> to load geometry.
        /// </summary>
        private void Start()
        {
            // Get required MapsService component on this GameObject.
            MapsService mapsService = GetComponent <MapsService>();

            // Set real-world location to load.
            mapsService.InitFloatingOrigin(LatLng);

            // Configure Map Styling.
            GameObjectOptions options = new GameObjectOptions();

            options.RegionStyle =
                RegionStyleSettings.Apply(options.RegionStyle);
            options.SegmentStyle =
                RoadStyleSettings.Apply(options.SegmentStyle);
            options.AreaWaterStyle =
                WaterStyleSettings.Apply(options.AreaWaterStyle);
            options.ExtrudedStructureStyle =
                ExtrudedStructureStyleSettings.Apply(options.ExtrudedStructureStyle);
            options.ModeledStructureStyle =
                ModeledStructureStyleSettings.Apply(options.ModeledStructureStyle);
            // Load map with default options.
            Bounds bounds = new Bounds(Vector3.zero, Vector3.one * LoadRange);

            mapsService.LoadMap(bounds, options);
        }
示例#3
0
    /// <summary>
    /// Get <see cref="MapsService"/> and use it to load geometry, searching for the given Place Id
    /// in all extruded buildings.
    /// </summary>
    private void Start()
    {
        // Make sure a Place Id has been given.
        if (string.IsNullOrEmpty(PlaceId))
        {
            // Note: 'name' and 'GetType()' just give the name of the GameObject this script is on, and
            // the name of this script respectively.
            Debug.LogErrorFormat("No Place Id defined for {0}.{1}, which needs a Place Id to operate!",
                                 name, GetType());
            return;
        }

        // Get required Maps Service component on this GameObject.
        MapsService mapsService = GetComponent <MapsService>();

        // Set location to load.
        mapsService.InitFloatingOrigin(LatLng);

        // Sign up to event that will be called after each extruded building is created, so can check
        // the Place Id of this building and adjust its height if required.
        mapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(CheckGeometry);

        // Load map with default options.
        mapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);
    }
示例#4
0
        /// <summary>
        /// This defines the origin of the loaded map.
        /// </summary>
        protected virtual void InitFloatingOrigin()
        {
            if (MapsService == null)
            {
                return;
            }

            // Set real-world location to load.
            MapsService.InitFloatingOrigin(LatLng);
        }
示例#5
0
        /// <summary>
        /// Use <see cref="MapsService"/> to load geometry.
        /// </summary>
        private void Start()
        {
            // Get required Maps Service component on this GameObject.
            MapsService mapsService = GetComponent <MapsService>();

            // Set real-world location to load.
            mapsService.InitFloatingOrigin(LatLng);

            // Load map with default options.
            mapsService.LoadMap(Bounds, ExampleDefaults.DefaultGameObjectOptions);
        }
        /// <summary>
        /// Follow player's real-world location, as derived from the device's GPS signal.
        /// </summary>
        private IEnumerator Follow()
        {
            // If location is allowed by the user, start the location service and compass, otherwise abort
            // the coroutine.
      #if PLATFORM_IOS
            // The location permissions request in IOS does not seem to get invoked until it is called for
            // in the code. It happens at runtime so if the code is not trying to access the location
            // right away, it will not pop up the permissions dialog.
            Input.location.Start();
      #endif

            while (!Input.location.isEnabledByUser)
            {
                Debug.Log("Waiting for location services to become enabled..");
                yield return(new WaitForSeconds(1f));
            }
            Debug.Log("Location services is enabled.");

      #if !PLATFORM_IOS
            Input.location.Start();
      #endif

            Input.compass.enabled = true;

            // Wait for the location service to start.
            while (true)
            {
                if (Input.location.status == LocationServiceStatus.Initializing)
                {
                    // Starting, just wait.
                    yield return(new WaitForSeconds(1f));
                }
                else if (Input.location.status == LocationServiceStatus.Failed)
                {
                    // Failed, abort the coroutine.
                    Debug.LogError("Location Services failed to start.");

                    yield break;
                }
                else if (Input.location.status == LocationServiceStatus.Running)
                {
                    // Started, continue the coroutine.
                    break;
                }
            }

            // Get the MapsService component and load it at the device location.
            PreviousLocation =
                new LatLng(Input.location.lastData.latitude, Input.location.lastData.longitude);
            MapsService = GetComponent <MapsService>();
            MapsService.InitFloatingOrigin(PreviousLocation);
            MapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);
        }
        /// <summary>
        /// Use <see cref="MapsService"/> to load geometry.
        /// </summary>
        private void Start()
        {
            // Get required Maps Service component on this GameObject.
            MapsService mapsService = GetComponent <MapsService>();

            // Set real-world location to load.
            mapsService.InitFloatingOrigin(LatLng);
            mapsService.Events.SegmentEvents.WillCreate.AddListener(WillCreateHandler);

            // Load map with default options.
            mapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);
        }
示例#8
0
        /// <summary>
        /// Use <see cref="MapsService"/> to load geometry.
        /// </summary>
        private void Start()
        {
            // Get required MapsService component on this GameObject.
            MapsService mapsService = GetComponent <MapsService>();

            // Set real-world location to load.
            mapsService.InitFloatingOrigin(LatLng);

            // Register a listener to be notified when the map is loaded.
            mapsService.Events.MapEvents.Loaded.AddListener(OnLoaded);

            // Load map with default options.
            mapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);
        }
    /// <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.
    }
示例#10
0
        /// <summary>
        /// Handle Unity *Start* event.
        /// </summary>
        private void Start()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            // Get required Maps Service component on this GameObject.
            MapsService mapsService = GetComponent <MapsService>();

            // Set real-world location to load.
            mapsService.InitFloatingOrigin(mapsService.MapPreviewOptions.Location);

            // Load map with default options.
            mapsService.LoadMap(mapsService.GetPreviewBounds(), mapsService.MaybeGetGameObjectOptions());
        }
示例#11
0
    /// <summary>
    /// Use <see cref="MapsService"/> to load geometry.
    /// </summary>
    public void LoadMap()
    {
        loaded = false;
        // Get required MapsService component on this GameObject.
        MapsService mapsService = GetComponent <MapsService>();

        // Set real-world location to load.
        mapsService.InitFloatingOrigin(latLng);

        // Register a listener to be notified when the map is loaded.
        mapsService.Events.MapEvents.Loaded.AddListener(OnLoaded);

        // Load map with default options.
        mapsService.LoadMap(bounds, ExampleDefaults.DefaultGameObjectOptions);

        Debug.Log("load map at " + latLng.ToString() + "bound" + bounds.size);
    }
示例#12
0
        /// <summary>
        /// Add a <see cref="MapsService"/> as a component of this <see cref="GameObject"/>.
        /// </summary>
        private void Start()
        {
            // Verify an Api Key was given.
            if (string.IsNullOrEmpty(ApiKey))
            {
                // If no Api Key given, use Api Key checker class to show an error to this effect, and skip
                // the rest of setup.
                ApiKeyChecker.ShowError();

                return;
            }

            // Set this GameObject to be inactive. This is so that when add we MapsService
            // component, its Awake function is not immediately called, giving us a chance
            // to set its parameters.
            gameObject.SetActive(false);

            // Add required Maps Service component to this GameObject.
            MapsService mapsService = gameObject.AddComponent <MapsService>();

            // Set Api Key so MapsService component can download tiles.
            mapsService.ApiKey = ApiKey;

            // Set Zoom Level on MapsService component (usually needs to be set before hitting
            // play, but can also be set in this way before its Awake function is called).
            mapsService.ZoomLevel = ZoomLevel;

            // Re-active this GameObject, which will allow Awake to be called on added
            // MapsService component.
            gameObject.SetActive(true);

            // Set real-world location to load.
            mapsService.InitFloatingOrigin(LatLng);

            // Optionally add a Error Handling component to debug any errors encountered by the Maps SDK
            // for Unity when loading geometry. We must do this now, after the MapsService component has
            // been added but before LoadMap is called.
            if (AddErrorHandling)
            {
                gameObject.AddComponent <ErrorHandling>();
            }

            // Load map with default options.
            mapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);
        }
示例#13
0
    /// <summary>
    /// Use <see cref="Google.Maps.MapsService"/> to load geometry.
    /// </summary>
    private void Start()
    {
        // Get required Maps Service component on this GameObject.
        MapsService = GetComponent <MapsService>();

        // Set real-world location to load.
        MapsService.InitFloatingOrigin(LatLng);

        MapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);

        // Add a pre-creation listener for buildings to apply some randomized heights.
        MapsService.Events.ExtrudedStructureEvents.WillCreate.AddListener(e => {
            e.Style = RandomizeBuildingHeight(e.Style);
        });

        // Apply a post-creation listener that adds the squashing MonoBehaviour to each building.
        MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(e => {
            AddSquasher(e.GameObject);
        });

        // Start a coroutine that periodically loads the visible portion of the map.
        StartCoroutine(LoadVisibleMapArea());
    }
示例#14
0
    /// <summary>
    /// Use <see cref="MapsService"/> to load geometry, labelling all created buildings with their
    /// names.
    /// </summary>
    private void Start()
    {
        // Get required Maps Service component on this GameObject.
        MapsService mapsService = GetComponent <MapsService>();

        // Set real-world location to load.
        mapsService.InitFloatingOrigin(LatLng);

        // Sign up to event called just after any new building (extruded structure or modelled
        // structure) is loaded, so we can show name using required BuildingLabeller component.
        BuildingLabeller buildingLabeller = GetComponent <BuildingLabeller>();

        mapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(args
                                                                         => buildingLabeller.NameExtrudedBuilding(args.GameObject, args.MapFeature));
        mapsService.Events.ModeledStructureEvents.DidCreate.AddListener(args
                                                                        => buildingLabeller.NameModeledBuilding(args.GameObject, args.MapFeature));

        // Set custom load distance (given as a parameter), which should be larger than the default 500m
        // in order to better demonstrate Level of Detail effect over a large area.
        Bounds loadBounds = new Bounds(Vector3.zero, new Vector3(LoadDistance, 0, LoadDistance));

        // Load map with created load bounds and default options.
        mapsService.LoadMap(loadBounds, ExampleDefaults.DefaultGameObjectOptions);
    }
示例#15
0
 protected void Start()
 {
     Service.InitFloatingOrigin(new LatLng(Lat, Lng));
     // ↓Exampleは使いたくなかったが、GameObjectOptionsの構築が面倒だったので止む無く失敬。
     Service.LoadMap(new Bounds(Vector3.zero, new Vector3(800.0f, 0.0f, 800.0f)), ExampleDefaults.DefaultGameObjectOptions);
 }
示例#16
0
 /// <summary>
 /// This defines the origin of the loaded map.
 /// </summary>
 protected virtual void InitFloatingOrigin()
 {
     // Set real-world location to load.
     mapsService.InitFloatingOrigin(LatLng);
 }
示例#17
0
    /// <summary>
    /// Follow player's real-world location, as derived from the device's GPS signal.
    /// </summary>
    private IEnumerator Follow()
    {
        // If location is allowed by the user, start the location service and compass, otherwise abort
        // the coroutine.
        if (Input.location.isEnabledByUser)
        {
            Input.location.Start();
            Input.compass.enabled = true;
        }
        else
        {
            Debug.LogError("Location Services not enabled by the user.");
            yield break;
        }

        // Wait for the location service to start.
        while (true)
        {
            if (Input.location.status == LocationServiceStatus.Initializing)
            {
                // Starting, just wait.
                yield return(new WaitForSeconds(1f));
            }
            else if (Input.location.status == LocationServiceStatus.Failed)
            {
                // Failed, abort the coroutine.
                Debug.LogError("Location Services failed to start.");
                yield break;
            }
            else if (Input.location.status == LocationServiceStatus.Running)
            {
                // Started, continue the coroutine.
                break;
            }
        }

        // Get the MapsService component and load it at the device location.
        LatLng previousLocation = new LatLng(
            Input.location.lastData.latitude, Input.location.lastData.longitude);
        MapsService mapsService = GetComponent <MapsService>();

        mapsService.InitFloatingOrigin(previousLocation);
        mapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);

        // Every second, move the map location to the device location.
        while (true)
        {
            yield return(new WaitForSeconds(1f));

            // Only move the map location if the device has moved more than 2 meters.
            LatLng currentLocation = new LatLng(
                Input.location.lastData.latitude, Input.location.lastData.longitude);
            float distance = Vector3.Distance(
                Vector3.zero, mapsService.Coords.FromLatLngToVector3(currentLocation));
            if (distance > 2)
            {
                mapsService.MoveFloatingOrigin(currentLocation);
                previousLocation = currentLocation;
            }
        }
    }
    private IEnumerator Follow()
    {
        // If location is allowed by the user, start the location service and compass, otherwise abort
        // the coroutine.


        #if PLATFORM_IOS
        // The location permissions request in IOS does not seem to get invoked until it is called for
        // in the code. It happens at runtime so if the code is not trying to access the location
        // right away, it will not pop up the permissions dialog.
        Input.location.Start();
        #endif

        while (!Input.location.isEnabledByUser)
        {
            //Debug.Log("Waiting for location services to become enabled..");
            yield return(new WaitForSeconds(1f));
        }

        _ShowAndroidToastMessage("Location services is enabled.");

        /*Start the Location service*/
        #if !PLATFORM_IOS
        Input.location.Start();
        #endif

        Input.compass.enabled = true;

        // Wait for the location service to start.
        while (true)
        {
            if (Input.location.status == LocationServiceStatus.Initializing)
            {
                // Starting, just wait.
                yield return(new WaitForSeconds(1f));
            }
            else if (Input.location.status == LocationServiceStatus.Failed)
            {
                // Failed, abort the coroutine.
                //Debug.LogError("Location Services failed to start.");
                _ShowAndroidToastMessage("Location Service failed to start.");

                yield break;
            }
            else if (Input.location.status == LocationServiceStatus.Running)
            {
                // Started, continue the coroutine.
                break;
            }
        }

        // Get the MapsService component and load it at the device location.
        PreviousLocation =
            new LatLng(Input.location.lastData.latitude, Input.location.lastData.longitude);

        mapsService = GetComponent <MapsService>();

        /*Get the static HistoricStreet from MainScript class
         * . Check whether it is null
         * . if it is null set the MapsService InitFloatingOrigin to the Users Location
         * . if it is not null set the MapService InitFloatingOrgin to the set location
         */

        historicStreet = MainScript.selectedLocation;

        if (historicStreet == null)
        {
            mapsService.InitFloatingOrigin(PreviousLocation);
        }
        else
        {
            LatLng selectedLocation = new LatLng(historicStreet.Latitude, historicStreet.Longitude);
            mapsService.InitFloatingOrigin(selectedLocation);
            MainCamera.GetComponent <ObjectFollower>().ShouldFollow(false);
        }


        //_ShowAndroidToastMessage("MapsService initialised and InitFloatingOrigin called");

        // Register a listener to be notified when the map is loaded.
        mapsService.Events.MapEvents.Loaded.AddListener(OnLoaded);

        // Load map with default options.
        LoadMap();
    }