powerfun-unity/Assets/Scenes/Ride/Scripts/LoadingPanelController.cs
2021-04-15 17:09:35 +08:00

103 lines
2.6 KiB
C#

using UnityEngine;
using Mapbox.Unity.Map;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
//[ExecuteInEditMode]
public class LoadingPanelController : MonoBehaviour
{
[SerializeField]
Text _text;
[SerializeField]
AnimationCurve _curve;
Text mapName;
AbstractMap _map;
Text level;
Text distance;
Text elevaction;
Text slope;
Text rideNum;
Text uploadByUserName;
private void Start()
{
var root = transform.parent.parent.parent;
_map = root.Find("Map").GetComponent<AbstractMap>();
var cyclingController = root.GetComponent<CyclingController>();
mapName = transform.Find("MapName").GetComponent<Text>();
level = transform.Find("level/Text").GetComponent<Text>();
elevaction = transform.Find("Elevaction").GetComponent<Text>();
slope = transform.Find("Slope").GetComponent<Text>();
rideNum = transform.Find("RideNum").GetComponent<Text>();
uploadByUserName = transform.Find("UploadByUserName").GetComponent<Text>();
var mapdata = cyclingController.GetMapData();
var route = cyclingController.GetRoute();
mapName.text = route.RouteInstance.Name;
level.text = route.RouteInstance.Hard;
elevaction.text = route.RouteInstance.EleDifference.ToString("g0");
slope.text = route.RouteInstance.AverageGrade.ToString() + "%";
rideNum.text = route.RouteInstance.TheHeat.ToString();
uploadByUserName.text = route.RouteInstance.UserId.ToString();
_map.OnInitialized += _map_OnInitialized;
_map.OnTileFinished += _map_OnTileFinished;
_map.OnEditorPreviewEnabled += OnEditorPreviewEnabled;
_map.OnEditorPreviewDisabled += OnEditorPreviewDisabled;
_map.OnUpdated += _map_OnUpdated;
}
private void _map_OnUpdated()
{
//Debug.Log("_map_OnUpdated");
}
private void _map_OnTileFinished(global::Mapbox.Unity.MeshGeneration.Data.UnityTile obj)
{
//transform.gameObject.SetActive(false);
Debug.Log("_map_OnTileFinished");
}
void _map_OnInitialized()
{
var visualizer = _map.MapVisualizer;
_text.text = "LOADING";
visualizer.OnMapVisualizerStateChanged += (s) =>
{
if (this == null)
return;
if (s == ModuleState.Finished)
{
transform.gameObject.SetActive(false);
}
else if (s == ModuleState.Working)
{
}
};
}
void OnEditorPreviewEnabled()
{
transform.gameObject.SetActive(false);
}
void OnEditorPreviewDisabled()
{
transform.gameObject.SetActive(true);
}
void Update()
{
var t = _curve.Evaluate(Time.time);
_text.color = Color.Lerp(Color.clear, Color.white, t);
}
}
}