/// <summary> /// Illustrates how to add custom markers over the globe using the AddMarker API. /// In this example a building prefab is added to a random city (see comments for other options). /// </summary> void AddMarkerGameObjectOnRandomCity() { // Every marker is put on a spherical-coordinate (assuming a radius = 0.5 and relative center at zero position) Vector3 sphereLocation; // Add a marker on a random city City city = map.cities [Random.Range(0, map.cities.Count)]; sphereLocation = city.unitySphereLocation; // or... choose a city by its name: // int cityIndex = map.GetCityIndex("Moscow"); // sphereLocation = map.cities[cityIndex].unitySphereLocation; // or... use the centroid of a country // int countryIndex = map.GetCountryIndex("Greece"); // sphereLocation = map.countries[countryIndex].center; // Send the prefab to the AddMarker API setting a scale of 0.02f (this depends on your marker scales) GameObject building = Instantiate(Resources.Load <GameObject> ("Building/Building")); map.AddMarker(building, sphereLocation, 0.02f); // Fly to the destination and see the building created map.FlyToLocation(sphereLocation); // Optionally add a blinking effect to the marker MarkerBlinker.AddTo(building, 4, 0.2f); }
public void OnPointerClick(PointerEventData dat) { Vector2 localCursor; Vector2 pos = dat.position; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rt, pos, null, out localCursor)) { return; } localCursor.x -= rt.rect.xMin; localCursor.y -= rt.rect.yMin; localCursor.x /= rt.rect.width; localCursor.y /= rt.rect.height; Vector2 latlon = Conversion.GetLatLonFromUV(localCursor); if (customZoomLevel && customDuration) { map.FlyToLocation(latlon, duration, zoomLevel); } else if (customZoomLevel) { map.FlyToLocation(latlon, map.navigationTime, zoomLevel); } else if (customDuration) { map.FlyToLocation(latlon, duration); } else { map.FlyToLocation(latlon); } }
void AddMarkerUnitAtMouseCurser() { Vector3 cartesianLocation = map.cursorLocation; //returns cartesian coords GameObject unit = Instantiate(Resources.Load("Prefabs/Unit") as GameObject); map.AddMarker(unit, cartesianLocation, 0.01f); map.FlyToLocation(cartesianLocation); }
void Update() { if (Input.GetKeyDown(KeyCode.T)) { map.FlyToLocation(40.7589f, -73.9851f, 20f, 0.00001f); // Fly to Times Square as close as possible } if (Input.GetKeyDown(KeyCode.A)) { map.FlyToLocation(map.cursorLocation, 2f, 0.8f); } }
// Use this for initialization void Start() { float selected_latitude = 40.71f; float selected_longitude = -74f; Sprite selected_sprite = Resources.Load <Sprite>("NewYork"); WorldMapGlobe map = WorldMapGlobe.instance; map.calc.fromLatDec = selected_latitude; map.calc.fromLonDec = selected_longitude; map.calc.fromUnit = UNIT_TYPE.DecimalDegrees; map.calc.Convert(); Vector3 sphereLocation = map.calc.toSphereLocation; // Create sprite GameObject destinationSprite = new GameObject(); SpriteRenderer dest_sprite = destinationSprite.AddComponent <SpriteRenderer>(); dest_sprite.sprite = selected_sprite; // Add sprite billboard to the map with custom scale, billboard mode and little bit elevated from surface (to prevent clipping with city spots) map.AddMarker(destinationSprite, sphereLocation, 0.02f, true, 0.1f); // Add click handlers destinationSprite.AddComponent <SpriteClickHandler>(); // Locate it on the map map.FlyToLocation(sphereLocation); map.autoRotationSpeed = 0f; }
/// <summary> /// Moves the gameobject obj onto the globe at the path given by latlon array and progress factor. /// </summary> /// <param name="obj">Object.</param> /// <param name="progress">Progress expressed in 0..1.</param> public void MoveTo(float progress) { // Iterate again until we reach progress int steps = latLon.Count; float acum = 0, acumPrev = 0; for (int k = 0; k < steps - 1; k++) { acumPrev = acum; acum += stepLengths[k] / totalLength; if (acum > progress) { // This is the step where "progress" is contained. if (k > 0) { progress = (progress - acumPrev) / (acum - acumPrev); } Vector3 pos0 = Conversion.GetSpherePointFromLatLon(latLon[k]); Vector3 pos1 = Conversion.GetSpherePointFromLatLon(latLon[k + 1]); Vector3 pos = Vector3.Lerp(pos0, pos1, progress); pos = pos.normalized * 0.5f; map.AddMarker(gameObject, pos, 0.01f, false); map.FlyToLocation(pos, 2f); break; } } }
/// <summary> /// Illustrates how to add custom markers over the globe using the AddMarker API. /// In this example a building prefab is added to a random city (see comments for other options). /// </summary> void AddMarkerGameObjectOnRandomCity() { // Every marker is put on a spherical-coordinate (assuming a radius = 0.5 and relative center at zero position) Vector3 sphereLocation; // Add a marker on a random city City city = map.cities [Random.Range(0, map.cities.Count)]; sphereLocation = city.unitySphereLocation; // or... choose a city by its name: // int cityIndex = map.GetCityIndex("Moscow"); // sphereLocation = map.cities[cityIndex].unitySphereLocation; // or... use the centroid of a country // int countryIndex = map.GetCountryIndex("Greece"); // sphereLocation = map.countries[countryIndex].center; // or... use a custom location lat/lon. Example put the building over New York: // map.calc.fromLatDec = 40.71f; // 40.71 decimal degrees north // map.calc.fromLonDec = -74.00f; // 74.00 decimal degrees to the west // map.calc.fromUnit = UNIT_TYPE.DecimalDegrees; // map.calc.Convert(); // sphereLocation = map.calc.toSphereLocation; // Send the prefab to the AddMarker API setting a scale of 0.02f (this depends on your marker scales) GameObject building = Instantiate(Resources.Load <GameObject> ("Building/Building")); map.AddMarker(building, sphereLocation, 0.02f); // Fly to the destination and see the building created map.FlyToLocation(sphereLocation); // Optionally add a blinking effect to the marker MarkerBlinker.AddTo(building, 4, 0.2f); }
// Use this for initialization void Start() { WorldMapGlobe map = WorldMapGlobe.instance; // Gets France center in sphere coordinates int countryIndex = map.GetCountryIndex("France"); Vector3 countryCenter = map.countries[countryIndex].sphereCenter; // Center on France and set constraint around country center map.FlyToLocation(countryCenter, 0); map.constraintPosition = countryCenter; map.constraintAngle = 5f; map.constraintPositionEnabled = true; // Set zoom level and stop rotation map.SetZoomLevel(0.1f); map.autoRotationSpeed = 0f; }
void BuildRoad() { // Get a path between both cities List <int> cellIndices = null; do { // Find 2 random cities in Europe int city1Index = GetRandomEuropeanCity(); int city2Index = GetRandomEuropeanCity(); // Underline cell indices? int cell1Index = map.GetCellIndex(map.GetCity(city1Index).latlon); int cell2Index = map.GetCellIndex(map.GetCity(city2Index).latlon); if (cell1Index == cell2Index) { continue; } // Get the path cellIndices = map.FindPath(cell1Index, cell2Index, 0, true); } while(cellIndices == null); // Highlight road cells StartCoroutine(IlluminateRoadCells(cellIndices)); // Get lat/lon coordinates for the path int positionsCount = cellIndices.Count; Vector2[] latLons = new Vector2[positionsCount]; for (int k = 0; k < positionsCount; k++) { latLons [k] = map.cells [cellIndices [k]].latlonCenter; } // Build a road along the map coordinates LineMarkerAnimator lma = map.AddLine(latLons, Color.white, 0.1f); lma.lineMaterial.mainTexture = roadTexture; lma.lineMaterial.mainTextureScale = new Vector2(2f, 1f); // Go to there! map.FlyToLocation(latLons [0].x, latLons [0].y, 1f, 0.2f); }
void Start() { float latitude = 40.71f; float longitude = -74f; WorldMapGlobe map = WorldMapGlobe.instance; Vector3 sphereLocation = Conversion.GetSpherePointFromLatLon(latitude, longitude); // Create sprite destinationSprite = new GameObject(); SpriteRenderer dest_sprite = destinationSprite.AddComponent <SpriteRenderer> (); dest_sprite.sprite = Resources.Load <Sprite> ("NewYork"); // Add sprite billboard to the map with custom scale, billboard mode and little bit elevated from surface (to prevent clipping with city spots) map.AddMarker(destinationSprite, sphereLocation, 0.02f, true, 0.1f); // Add click handlers destinationSprite.AddComponent <SpriteClickHandler> (); // Locate it on the map map.FlyToLocation(sphereLocation, 4f, 0.4f); map.autoRotationSpeed = 0f; }
/// <summary> /// Moves the gameobject obj onto the globe at the path given by latlon array and progress factor. /// </summary> /// <param name="obj">Object.</param> /// <param name="progress">Progress expressed in 0..1.</param> public void MoveTo(float progress) { currentProgress = progress; // Iterate again until we reach progress int steps = latLon.Count; float acum = 0, acumPrev = 0; for (int k = 0; k < steps - 1; k++) { acumPrev = acum; acum += stepLengths [k] / totalLength; if (acum > progress) { // This is the step where "progress" is contained. if (k > 0) { progress = (progress - acumPrev) / (acum - acumPrev); } Vector3 pos0 = Conversion.GetSpherePointFromLatLon(latLon [k]); Vector3 pos1 = Conversion.GetSpherePointFromLatLon(latLon [k + 1]); Vector3 pos = Vector3.Lerp(pos0, pos1, progress); pos = pos.normalized * 0.5f; map.AddMarker(gameObject, pos, 0.01f, false); // Make it look towards destination Vector3 dir = (pos1 - pos0).normalized; Vector3 proj = Vector3.ProjectOnPlane(dir, pos0); transform.LookAt(map.transform.TransformPoint(proj + pos0), map.transform.transform.TransformDirection(pos0)); // Follow object map.FlyToLocation(pos, 0f); break; } } }
public void OrientOnLocation(Vector3 vectorLocation) { worldMapGlobe.FlyToLocation(vectorLocation, 1.5F, 0.05F, 0.01F, 0); worldMapGlobe.pitch = 0; worldMapGlobe.yaw = 0; }