/// <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); }
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); }
// 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; }
void Start() { // Listen to map clicks map = WorldMapGlobe.instance; map.OnClick += (Vector3 sphereLocation, int mouseButtonIndex) => map.AddMarker(MARKER_TYPE.CIRCLE_PROJECTED, sphereLocation, kmRadius, ringWidthStart, ringWidthEnd, Color.green); // Straight the globe preserving current center -- totally optional and has nothing to do with markers map.StraightenGlobe(); // UI Setup - non-important, only for this demo GUIResizer.Init(800, 500); labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.white; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleLeft; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.white; sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; }
public bool IntantiatePlayer(Cell startCell) { GameObject playerObject = Instantiate(playerPrefab); if (playerObject == null) { errorHandler.ReportError("Player instantiation failed", ErrorState.restart_scene); return(false); } PlayerCharacter = playerObject.GetComponent(typeof(IPlayerCharacter)) as IPlayerCharacter; if (PlayerCharacter == null) { errorHandler.ReportError("Player component missing", ErrorState.close_application); return(false); } try { PlayerCharacter.CellLocation = startCell; PlayerCharacter.Latlon = startCell.latlon; Vector3 startingLocation = startCell.sphereCenter; PlayerCharacter.VectorLocation = startingLocation; float playerSize = PlayerCharacter.Size; worldMapGlobe.AddMarker(playerObject, startingLocation, playerSize, false, 0.0f, true, true); startCell.occupants.Add(PlayerCharacter); return(true); } catch { errorHandler.ReportError("Invalid start cell for player", ErrorState.restart_scene); return(false); } }
/// <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; //This seems pointless if (latlonIndex < 0 || (latlonIndex + 1) > latLon.Count) { errorHandler.ReportError("Attempting to move beyond latlon range", ErrorState.close_window); return; } try { Vector3 pos0 = Conversion.GetSpherePointFromLatLon(latLon[latlonIndex]); Vector3 pos1 = Conversion.GetSpherePointFromLatLon(latLon[latlonIndex + 1]); Vector3 pos = Vector3.Lerp(pos0, pos1, progress); pos = pos.normalized * 0.5f; float playerSize = AnimatedObject.Size; worldMapGlobe.AddMarker(gameObject, pos, playerSize, false); // Make it look towards destination Vector3 dir = (pos0 - pos1).normalized; Vector3 proj = Vector3.ProjectOnPlane(dir, pos0); transform.LookAt(worldMapGlobe.transform.TransformPoint(proj + pos0), worldMapGlobe.transform.transform.TransformDirection(pos0)); } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.close_window); } }
/// <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; } } }
void Start() { labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.white; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleLeft; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.white; sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // Get map instance to Globe API methods map = WorldMapGlobe.instance; map.OnDrag += ClearFoW; // Load prefab GameObject tower = Resources.Load <GameObject>("Tower/Tower"); // Colorize some countries for (int colorizeIndex = 0; colorizeIndex < map.countries.Length; colorizeIndex++) { Country country = map.countries[colorizeIndex]; if (country.continent.Equals("Europe")) { // Color country surface Color color = new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), 0.2f); map.ToggleCountrySurface(country.name, true, color); // Clear fog around the country map.SetFogOfWarAlpha(country, 0, 0.1f); // Add a random moving sphere for this country GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere); obj.transform.SetParent(map.transform, false); obj.transform.localScale = Vector3.one * 0.02f; obj.transform.localPosition = country.sphereCenter; obj.AddComponent <AnimateSphereAround>(); // Set a random color for the sphere obj.GetComponent <Renderer>().material.color = new Color(Random.value, Random.value, Random.value); // Add a tower on the center of the country GameObject thisTower = Instantiate(tower); map.AddMarker(thisTower, country.sphereCenter, 0.15f, false, 0, true); } } // Center on Paris map.FlyToCity(map.GetCity("France", "Paris")); }
public void addMarker(TweetObject tweet) { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); Vector3 sphereLocation = Conversion.GetSpherePointFromLatLon(new Vector2(tweet.getTweetLat(), tweet.getTweetLong())); //GameObject obj = map.AddMarker(MARKER_TYPE.CIRCLE, sphereLocation, kmRadius, ringWidthStart, ringWidthEnd, Color.green); map.AddMarker(cube, sphereLocation, 0.001f); tweet.setGameObject(cube); }
/// <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); }
void UpdateRectangle(bool finishSelection) { if (map == null) { return; } if (quad != null) { DestroyImmediate(quad); } quad = map.AddMarker(MARKER_TYPE.QUAD, startPos, endPos, fillColor, borderColor, borderWidth); if (callback != null) { callback(startPos, endPos, finishSelection); } }
void AddPanel() { // If previous panel exists, destroy it if (currentPanel != null) { Destroy(currentPanel); } // Instantiate panel currentPanel = Instantiate <GameObject> (prefab); // Update panel texts Text countryName, provinceName, cityName, population; countryName = currentPanel.transform.Find("Panel/RowCountry/CountryName").GetComponent <Text> (); provinceName = currentPanel.transform.Find("Panel/RowProvince/ProvinceName").GetComponent <Text> (); cityName = currentPanel.transform.Find("Panel/RowCity/CityName").GetComponent <Text> (); population = currentPanel.transform.Find("Panel/RowCityData1/CityData1Value").GetComponent <Text> (); // Gets a random city and populate data int cityIndex = Random.Range(0, map.cities.Count - 1); City city = map.GetCity(cityIndex); cityName.text = city.name; population.text = city.population.ToString(); countryName.text = map.GetCityCountryName(cityIndex); provinceName.text = map.GetCityProvinceName(cityIndex); // Position the canvas over the globe float distaceToGlobeCenter = 1.2f; Vector3 worldPos = map.transform.TransformPoint(city.unitySphereLocation * distaceToGlobeCenter); currentPanel.transform.position = worldPos; // Draw a circle around the city map.AddMarker(MARKER_TYPE.CIRCLE_PROJECTED, city.unitySphereLocation, 100, 0.8f, 1f, Color.green); // Parent the panel to the globe so it rotates with it currentPanel.transform.SetParent(map.transform, true); // Finally fly to city to show the panel map.FlyToCity(cityIndex, 2f); }
public override void OnCellClick(int index) { if (worldMapGlobe.cells[index].tag == null) { //Create Resort var resortPrefab = Resources.Load <GameObject>("Prefabs/Selectables/Resort"); var resortObject = Instantiate(resortPrefab); Resort resortComponent = resortObject.GetComponent(typeof(Resort)) as Resort; worldMapGlobe.AddMarker(resortObject, worldMapGlobe.cells[index].sphereCenter, 0.01f, false, 0.0f, true, true); Deselect(); //Remove Resort from Inventory inventoryUI.RemoveItem(InventoryLocation); } else { //Cell Occupied Deselect(); } }
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 bool InstantiateCulturalLandmark(MountPoint mountPoint) { if (!started) { Start(); } string mountPointName = mountPoint.name; if (mountPointName == null) { errorHandler.ReportError("Cultural mount point name missing", ErrorState.close_window); return(false); } string tempName = mountPointName.Replace("The", ""); tempName = tempName.Replace(" ", ""); var model = Resources.Load <GameObject>(landmarkFilePath + tempName); if (model == null) { errorHandler.ReportError("Unable to load cultural landmark model", ErrorState.close_window); return(false); } var modelClone = Instantiate(model); if (modelClone == null) { errorHandler.ReportError("Failed to instantiate " + mountPointName, ErrorState.close_window); return(false); } Landmark landmarkComponent = modelClone.GetComponent(typeof(Landmark)) as Landmark; if (landmarkComponent == null) { errorHandler.ReportError(mountPointName + " landmark component missing", ErrorState.close_window); return(false); } landmarkComponent.MountPoint = mountPoint; landmarkComponent.ObjectName = mountPointName; landmarkComponent.CellIndex = worldMapGlobe.GetCellIndex(mountPoint.localPosition); if (landmarkComponent.CellIndex < 0 || landmarkComponent.CellIndex > worldMapGlobe.cells.Length) { errorHandler.ReportError("Invalid cell index for " + mountPointName, ErrorState.close_window); return(false); } landmarkComponent.CellLocation = worldMapGlobe.cells[landmarkComponent.CellIndex]; landmarkComponent.CellLocation.canCross = false; worldMapGlobe.AddMarker(modelClone, mountPoint.localPosition, 0.001f, false, -5.0f, true, true); landmarkComponent.CellLocation.occupants.Add(landmarkComponent); string landmarkID = landmarkComponent.GetInstanceID().ToString(); mappablesManager.MappedObjects.Add(landmarkID, landmarkComponent); CulturalLandmarks.Add(landmarkID, landmarkComponent); CulturalLandmarksByName.Add(landmarkComponent.ObjectName, landmarkComponent); return(true); }