/// <summary> /// Moves the camera and refreshes the map as the player moves. /// </summary> private void Update() { if (MapsService == null) { return; } // Get the current map location. LatLng currentLocation = new LatLng(Input.location.lastData.latitude, Input.location.lastData.longitude); Vector3 currentWorldLocation = MapsService.Coords.FromLatLngToVector3(currentLocation); // Move the camera to the current map location. Vector3 targetCameraPosition = new Vector3(currentWorldLocation.x, Camera.main.transform.position.y, currentWorldLocation.z); Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, targetCameraPosition, Time.deltaTime * 5); // Only move the map location if the device has moved more than 2 meters. if (Vector3.Distance(Vector3.zero, currentWorldLocation) > 2) { MapsService.MoveFloatingOrigin(currentLocation, new[] { Camera.main.gameObject }); MapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions); PreviousLocation = currentLocation; } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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> /// 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()); }
/// <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); }
/// <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); }
/// <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()); }
/// <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); }
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); }
/// <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; } } }