78 lines
1.6 KiB
C#
78 lines
1.6 KiB
C#
using UnityEngine;
|
|
using Mapbox.Unity.Map;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
|
|
//[ExecuteInEditMode]
|
|
public class LoadingPanelController : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
GameObject _content;
|
|
[SerializeField]
|
|
Text _text;
|
|
[SerializeField]
|
|
AnimationCurve _curve;
|
|
|
|
AbstractMap _map;
|
|
void Awake()
|
|
{
|
|
_map = FindObjectOfType<AbstractMap>();
|
|
_map.OnInitialized += _map_OnInitialized;
|
|
_map.OnTileFinished += _map_OnTileFinished;
|
|
_map.OnEditorPreviewEnabled += OnEditorPreviewEnabled;
|
|
_map.OnEditorPreviewDisabled += OnEditorPreviewDisabled;
|
|
|
|
}
|
|
|
|
private void _map_OnTileFinished(global::Mapbox.Unity.MeshGeneration.Data.UnityTile obj)
|
|
{
|
|
transform.gameObject.SetActive(false);
|
|
}
|
|
|
|
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)
|
|
{
|
|
|
|
// Uncommment me if you want the loading screen to show again
|
|
// when loading new tiles.
|
|
//_content.SetActive(true);
|
|
}
|
|
|
|
};
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|