#define LIGHTSPEED using UnityEngine; using System.Text; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; namespace WPM { public class WorldMapController : MonoBehaviour { public bool showProvincesInit = true; public bool drawAllProvincesInit = false; public bool showCountryNamesInit = false; public float waitToGoEEUU = 5; public Text latitude; public Text longitude; public GameObject[] objetcsSceneLobby; public GameObject[] objectsSceneLoad; WorldMapGlobe map; bool animatingField; void Start() { // Get a reference to the World Map API: map = WorldMapGlobe.instance; #if LIGHTSPEED Camera.main.fieldOfView = 180; animatingField = true; #endif map.earthInvertedMode = false; /* Register events: this is optionally but allows your scripts to be informed instantly as the mouse enters or exits a country, province or city */ //map.OnCityEnter += (int cityIndex) => Debug.Log("Entered city " + map.cities[cityIndex].name); //map.OnCityExit += (int cityIndex) => Debug.Log("Exited city " + map.cities[cityIndex].name); //map.OnCityPointerDown += (int cityIndex) => Debug.Log("Pointer down on city " + map.cities[cityIndex].name); //map.OnCityClick += (int cityIndex) => Debug.Log("Clicked city " + map.cities[cityIndex].name); //map.OnCityPointerUp += (int cityIndex) => Debug.Log("Pointer up on city " + map.cities[cityIndex].name); //map.OnCountryEnter += (int countryIndex, int regionIndex) => Debug.Log("Entered country (" + countryIndex + ") " + map.countries[countryIndex].name); //map.OnCountryExit += (int countryIndex, int r1024egionIndex) => Debug.Log("Exited country " + map.countries[countryIndex].name); //map.OnCountryPointerDown += (int countryIndex, int regionIndex) => Debug.Log("Pointer down on country " + map.countries[countryIndex].name); //map.OnCountryClick += (int countryIndex, int regionIndex) => Debug.Log("Clicked country " + map.countries[countryIndex].name); //map.OnCountryPointerUp += (int countryIndex, int regionIndex) => Debug.Log("Pointer up on country " + map.countries[countryIndex].name); //map.OnProvinceEnter += (int provinceIndex, int regionIndex) => Debug.Log("Entered province (" + provinceIndex + ") " + map.provinces[provinceIndex].name); //map.OnProvinceExit += (int provinceIndex, int regionIndex) => Debug.Log("Exited province " + map.provinces[provinceIndex].name); //map.OnProvincePointerDown += (int provinceIndex, int regionIndex) => Debug.Log("Pointer down on province " + map.provinces[provinceIndex].name); //map.OnProvinceClick += (int provinceIndex, int regionIndex) => Debug.Log("Clicked province " + map.provinces[provinceIndex].name); //map.OnProvincePointerUp += (int provinceIndex, int regionIndex) => Debug.Log("Pointer up on province " + map.provinces[provinceIndex].name); map.OnProvinceClick += (int provinceIndex, int regionIndex) => { if (map.provinces[provinceIndex].name == "California") { if(objetcsSceneLobby !=null) { foreach (var obj in objetcsSceneLobby) { obj.SetActive(false); } } if (objetcsSceneLobby !=null) { foreach (var obj in objectsSceneLoad) { obj.SetActive(true); } } } }; map.OnClick += (sphereLocation, mouseButtonIndex) => { Vector2 latLon = Conversion.GetLatLonFromSpherePoint(sphereLocation); latitude.text = latLon.x.ToString(); longitude.text = latLon.y.ToString(); //Debug.Log("Clicked on Latitude: " + latLon.x + ", Longitude: " + latLon.y); }; map.showProvinces = showProvincesInit; map.drawAllProvinces = drawAllProvincesInit; map.showCountryNames = showCountryNamesInit; Invoke("ShowStatesNames", waitToGoEEUU); } void Update() { // Animates the camera field of view (just a cool effect at the begining) if (animatingField) { if (Camera.main.fieldOfView > 60) { Camera.main.fieldOfView -= (181.0f - Camera.main.fieldOfView) / (220.0f - Camera.main.fieldOfView); } else { Camera.main.fieldOfView = 60; animatingField = false; } } } string EntityListToString(List entities) { StringBuilder sb = new StringBuilder("Neighbours: "); for (int k = 0; k < entities.Count; k++) { if (k > 0) { sb.Append(", "); } sb.Append(((IAdminEntity)entities[k]).name); } return sb.ToString(); } void FlyToCountry(string countryName) { int countryIndex = map.GetCountryIndex(countryName); float zoomLevel = map.GetCountryMainRegionZoomExtents(countryIndex); map.FlyToCountry(countryIndex, 2f, zoomLevel, 0.5f); map.BlinkCountry(countryIndex, Color.black, Color.green, 4, 2.5f, true); } // Sample code to show how to navigate to a city: void FlyToCity(string cityName) { int cityIndex = map.GetCityIndex(cityName); map.FlyToCity(cityIndex, 2f, 0.2f, 0.5f); } void ShowStatesNames() { // First we ensure only states for USA are shown int countryUSAIndex = map.GetCountryIndex("United States of America"); for (int k = 0; k < map.countries.Length; k++) { if (k != countryUSAIndex) { map.countries[k].allowShowProvinces = false; } } map.showProvinces = true; map.drawAllProvinces = true; // Now, hide all country names and show states for USA map.showCountryNames = false; Country usaCountry = map.countries[countryUSAIndex]; for (int p = 0; p < usaCountry.provinces.Length; p++) { Province state = usaCountry.provinces[p]; Color color = new Color(Random.value, Random.value, Random.value); map.AddText(state.name, state.localPosition, color); } map.FlyToCountry(usaCountry); } } }