powerfun-unity/Assets/Scenes/Ride/Scripts/LoadingPanelController.cs

103 lines
2.6 KiB
C#
Raw Normal View History

2021-03-29 20:32:30 +08:00
using UnityEngine;
using Mapbox.Unity.Map;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
//[ExecuteInEditMode]
public class LoadingPanelController : MonoBehaviour
{
2021-04-15 17:09:35 +08:00
2021-03-29 20:32:30 +08:00
[SerializeField]
Text _text;
[SerializeField]
AnimationCurve _curve;
2021-04-15 17:09:35 +08:00
Text mapName;
2021-03-29 20:32:30 +08:00
AbstractMap _map;
2021-04-15 17:09:35 +08:00
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;
2021-04-15 10:13:01 +08:00
}
private void _map_OnUpdated()
{
//Debug.Log("_map_OnUpdated");
2021-03-29 20:32:30 +08:00
}
private void _map_OnTileFinished(global::Mapbox.Unity.MeshGeneration.Data.UnityTile obj)
{
2021-04-15 17:09:35 +08:00
//transform.gameObject.SetActive(false);
2021-04-15 10:13:01 +08:00
Debug.Log("_map_OnTileFinished");
2021-03-29 20:32:30 +08:00
}
void _map_OnInitialized()
{
var visualizer = _map.MapVisualizer;
_text.text = "LOADING";
visualizer.OnMapVisualizerStateChanged += (s) =>
{
if (this == null)
return;
if (s == ModuleState.Finished)
{
2021-04-15 17:09:35 +08:00
transform.gameObject.SetActive(false);
}
2021-03-29 20:32:30 +08:00
else if (s == ModuleState.Working)
{
2021-04-15 17:09:35 +08:00
2021-03-29 20:32:30 +08:00
}
};
}
void OnEditorPreviewEnabled()
{
2021-04-15 17:09:35 +08:00
transform.gameObject.SetActive(false);
2021-03-29 20:32:30 +08:00
}
void OnEditorPreviewDisabled()
{
2021-04-15 17:09:35 +08:00
transform.gameObject.SetActive(true);
2021-03-29 20:32:30 +08:00
}
void Update()
{
var t = _curve.Evaluate(Time.time);
_text.color = Color.Lerp(Color.clear, Color.white, t);
}
}
}