using System.Collections; using System.Collections.Generic; using UnityEngine; using WPM; using DG.Tweening; using UnityEngine.UI; using Assets.Scripts.Apis; using Newtonsoft.Json.Linq; using Assets.Scripts; public class EarthController : PFUIPanel { private WorldMapGlobe map; private Text Province; private Text Country; private RawImage maskImage; private MapApi mapApi; private Text CountText; private Text OfficialText; private Text RiderText; private GameObject hotPanel; private GameObject content; private Object itemObject; Transform rootPanel; Canvas canvas; float time = 0f; bool showSummary = false; Vector2 latlonCenter; protected override void Awake() { base.Awake(); mapApi = new MapApi(); canvas = this.transform.Find("Canvas").GetComponent(); canvas.worldCamera = Camera.main; rootPanel = this.transform.Find("Canvas").Find("Panel"); map = WorldMapGlobe.instance; map.showProvinces = true; map.showCities = true; map.autoRotationSpeed = 0f; //map.autoRotationSpeed = 0.1f; //Camera.main.fieldOfView = 180; map.SetZoomLevel(1.4f); //map.allowUserZoom = false; map.showLatitudeLines = false; map.showLongitudeLines = false; map.showCursor = false; } // Start is called before the first frame update protected override void Start() { itemObject = Resources.Load("UI/Prefab/BigMap/Item"); var panel = rootPanel.Find("Panel"); SetRounded(panel, 60); hotPanel = rootPanel.Find("HotPanel").gameObject; SetRounded(hotPanel.transform, 60); maskImage = rootPanel.Find("MaskImage").GetComponent(); Country = panel.Find("Country").GetComponent(); Province = panel.Find("Province").GetComponent(); CountText = panel.Find("CountPanel").Find("Count").GetComponent(); OfficialText = panel.Find("OfficialPanel").Find("Count").GetComponent(); RiderText = panel.Find("RiderPanel").Find("Count").GetComponent(); content = hotPanel.transform.Find("Scroll View").Find("Viewport").Find("Content").gameObject; //map.SetZoomLevel(10); //var mainCanvas = GameObject.Find("Canvas"); //mainCanvas.gameObject.SetActive(false); UIManager.Instance.MainPanel.gameObject.SetActive(false); Camera.main.transform.position = new Vector3(0, 0); Camera.main.transform.rotation = Quaternion.Euler(0, 0, 0); var zoom = map.GetZoomLevel(); map.OnZoomStart += Map_OnZoomStart; map.OnZoomEnd += Map_OnZoomEnd; map.OnClick += Map_OnClick; map.OnCountryEnter += (int countryIndex, int regionIndex) => { var country = map.countries[countryIndex]; if (country.name.ToLower().Contains("taiwan")) { Country.text = "China"; Province.text = "TaiWan"; ShowSummary(country.latlonCenter); } else { Country.text = country.name; } }; map.OnCountryClick += (int countryIndex, int regionIndex) => { var country = map.countries[countryIndex]; if (country.name.ToLower().Contains("taiwan")) { var latLon = country.latlonCenter; EnterBigMap(latLon); } }; map.OnProvinceEnter += async (int provinceIndex, int regionIndex) => { var province = map.provinces[provinceIndex]; Province.text = province.name; latlonCenter = province.latlonCenter; time = 0f; showSummary = true; //ShowSummary(province.latlonCenter); }; map.OnProvinceExit += (int provinceIndex, int regionIndex) => { showSummary = false; }; map.OnProvinceClick += (int provinceIndex, int regionIndex) => { var province = map.provinces[provinceIndex]; var latLon = province.latlonCenter; EnterBigMap(latLon); }; } /// /// 显示概要信息 /// /// private async void ShowSummary(Vector2 latlonCenter) { var result = await mapApi.GetEarthData(latlonCenter.x, latlonCenter.y); if (result.result == false) { return; } var obj = JObject.FromObject(result.data); CountText.text = obj.Value("count"); OfficialText.text = obj.Value("officialCount"); RiderText.text = obj.Value("riderCount"); //for (int i = 0; i < content.transform.childCount; i++) //{ // DestroyImmediate(content.transform.GetChild(i)); //} foreach (Transform item in content.transform) { GameObject.Destroy(item.gameObject); } var list = JArray.FromObject(obj["list"]); foreach (var item in list) { var itemObject1 = (GameObject)Instantiate(itemObject, content.transform, false); var iii = itemObject1.GetComponent(); iii.SetModel(new Assets.Scripts.Apis.Models.NearRouteModel { Id = item.Value("Id"), Name = item.Value("Name"), TheHeat = item.Value("TheHat"), IsFire = item.Value("IsFire") }); } } /// /// 进入大地图 /// /// private void EnterBigMap(Vector2 latLon) { map.FlyToLocation(latLon.x, latLon.y, 1f, 0.1f).Then(() => { //Close(); //UIManager.ShowBigMapPanel(); }); maskImage.gameObject.SetActive(true); maskImage.DOFade(1f, 0.9f).SetEase(Ease.InSine).OnComplete(() => { Close(); UIManager.ShowBigMapPanel(latLon.x, latLon.y); }); } private void Map_OnClick(Vector3 sphereLocation, int mouseButtonIndex) { //Debug.Log("click"); Vector2 latLon = Conversion.GetLatLonFromSpherePoint(sphereLocation); Debug.Log("Clicked on Latitude: " + latLon.x + ", Longitude: " + latLon.y); } private void Map_OnZoomStart(float zoomLevel) { //throw new System.NotImplementedException(); Debug.Log(zoomLevel); } private void Map_OnZoomEnd(float zoomLevel) { Debug.Log(zoomLevel); } // Update is called once per frame void Update() { //var zoom = map.GetZoomLevel(); //Debug.Log(zoom); if (showSummary) { time += Time.deltaTime; if (time >= 0.2) { ShowSummary(latlonCenter); showSummary = false; } } //Debug.Log(showSummary + "," + time); } public void Show(double lat, double lon) { if (lat != 0 && lon != 0) { map.FlyToLocation(new Vector2((float)lat, (float)lon), 0.1f); } } public override void Close() { //base.Close(); DestroyImmediate(this.gameObject); } }