301 lines
8.9 KiB
C#
301 lines
8.9 KiB
C#
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;
|
|
using UnityEngine.EventSystems;
|
|
using System;
|
|
|
|
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;
|
|
private GameObject panel;
|
|
private bool isTaiwanClick = false;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
mapApi = new MapApi();
|
|
|
|
canvas = this.transform.Find("Canvas").GetComponent<Canvas>();
|
|
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.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");
|
|
|
|
panel = rootPanel.Find("Panel").gameObject;
|
|
SetRounded(panel.transform, 60);
|
|
panel.gameObject.SetActive(false);
|
|
|
|
|
|
var goList = rootPanel.transform.Find("SwitchMode");
|
|
SetRounded(goList, 64);
|
|
UIManager.AddEvent(goList.Find("GoList").gameObject, EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
//UIManager.PopStack();
|
|
UIManager.ShowMapListPanel();
|
|
//this.gameObject.SetActive(false);
|
|
//DestroyImmediate(this.gameObject);
|
|
});
|
|
|
|
maskImage = rootPanel.Find("MaskImage").GetComponent<RawImage>();
|
|
|
|
Country = panel.transform.Find("Country").GetComponent<Text>();
|
|
Province = panel.transform.Find("Province").GetComponent<Text>();
|
|
CountText = panel.transform.Find("CountPanel").Find("Count").GetComponent<Text>();
|
|
OfficialText = panel.transform.Find("OfficialPanel").Find("Count").GetComponent<Text>();
|
|
RiderText = panel.transform.Find("RiderPanel").Find("Count").GetComponent<Text>();
|
|
|
|
//hotPanel = rootPanel.Find("HotPanel").gameObject;
|
|
//SetRounded(hotPanel.transform, 60);
|
|
//content = hotPanel.transform.Find("Scroll View").Find("Viewport").Find("Content").gameObject;
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
map.SetZoomLevel(2.6f);
|
|
//var zoom = map.GetZoomLevel();
|
|
//Debug.Log(zoom);
|
|
map.OnZoomStart += Map_OnZoomStart;
|
|
map.OnZoomEnd += Map_OnZoomEnd;
|
|
|
|
map.OnClick += Map_OnClick;
|
|
|
|
map.OnCountryEnter += (int countryIndex, int regionIndex) =>
|
|
{
|
|
map.autoRotationSpeed = 0f;
|
|
var country = map.countries[countryIndex];
|
|
if (country.name.ToLower().Contains("taiwan"))
|
|
{
|
|
Country.text = "China";
|
|
Province.text = "TaiWan";
|
|
ShowSummary(country.latlonCenter);
|
|
|
|
map.HighlightCountryRegion(173, 1, false, true, Color.white);
|
|
}
|
|
else {
|
|
Country.text = country.name;
|
|
}
|
|
};
|
|
|
|
map.OnCountryClick += (int countryIndex, int regionIndex) =>
|
|
{
|
|
|
|
var country = map.countries[countryIndex];
|
|
Debug.Log($"country click { country.name }, { countryIndex }, { regionIndex }");
|
|
if (country.name.ToLower().Contains("taiwan") || country.name.ToLower().Contains("china"))
|
|
{
|
|
//var latLon = map.countries[36].latlonCenter; //country.latlonCenter;
|
|
//EnterBigMap(latLon);
|
|
isTaiwanClick = true;
|
|
Invoke("DelayEnterBigMapForTaiwan", 0.01f);
|
|
}
|
|
};
|
|
|
|
map.OnProvinceEnter += (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) =>
|
|
{
|
|
isTaiwanClick = false;
|
|
Debug.Log("province click");
|
|
var province = map.provinces[provinceIndex];
|
|
var latLon = province.latlonCenter;
|
|
EnterBigMap(latLon);
|
|
};
|
|
|
|
//skybox = Camera.main.GetComponent<Skybox>();
|
|
}
|
|
|
|
private void DelayEnterBigMapForTaiwan()
|
|
{
|
|
if (!isTaiwanClick) return;
|
|
var latLon = map.countries[36].latlonCenter;
|
|
EnterBigMap(latLon);
|
|
}
|
|
|
|
//private float rot = 0;
|
|
//Skybox skybox;
|
|
/// <summary>
|
|
/// 显示概要信息
|
|
/// </summary>
|
|
/// <param name="latlonCenter"></param>
|
|
private async void ShowSummary(Vector2 latlonCenter)
|
|
{
|
|
if(panel.activeInHierarchy == false)
|
|
{
|
|
panel.SetActive(true);
|
|
panel.GetComponent<CanvasGroup>().alpha = 0;
|
|
panel.GetComponent<CanvasGroup>().DOFade(1f, 0.1f);
|
|
}
|
|
|
|
var result = await mapApi.GetEarthData(latlonCenter.x, latlonCenter.y);
|
|
if (result.result == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var obj = JObject.FromObject(result.data);
|
|
CountText.text = obj.Value<string>("count");
|
|
OfficialText.text = obj.Value<string>("officialCount");
|
|
RiderText.text = obj.Value<string>("riderCount");
|
|
|
|
|
|
//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<Item>();
|
|
// iii.SetModel(new Assets.Scripts.Apis.Models.NearRouteModel
|
|
// {
|
|
// Id = item.Value<int>("Id"),
|
|
// Name = item.Value<string>("Name"),
|
|
// TheHeat = item.Value<int>("TheHat"),
|
|
// IsFire = item.Value<bool>("IsFire")
|
|
// });
|
|
//}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入大地图
|
|
/// </summary>
|
|
/// <param name="latLon"></param>
|
|
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.PopStack();
|
|
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);
|
|
|
|
//rot += 0.1f * Time.deltaTime;
|
|
//rot %= 360;
|
|
//skybox.material.SetFloat("_Rotation", rot);
|
|
}
|
|
|
|
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();
|
|
map.Destroy();
|
|
DestroyImmediate(this.gameObject);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|