using UnityEngine; using Mapbox.Unity.Map; using DG.Tweening; using UnityEngine.UI; using Assets.Scripts.Apis; using System; using Assets.Scripts; using Assets.Scripts.Apis.Models; using System.Collections.Generic; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using System.Collections; using System.Threading.Tasks; namespace Assets.Scenes.Ride.Scripts { public class AbstratctLoadingController : MonoBehaviour { protected Text mapName; protected AbstractMap _map { get; set; } protected MapApi mapApi { get; set; } protected RawImage mapRouteImage; protected CanvasGroup canvasGroup; protected Slider slider; protected Text processText; protected Text rideNowText; protected Button rideNow; protected Button cancel; protected Text mapDescText; protected Text distance; protected Text elevaction; protected Text slope; protected GameObject panel; protected GameObject loadingPanel { get; set; } #region 属性 protected float process = 0;//0-100 % public float targetAlpha = 0f; public float alphaSpeed = 2.0f; private bool depressFlag = false; protected CyclingController cyclingController { get; set; } #endregion private float _timer = 15f; private bool _forceUpdate = false; protected virtual void Start() { App.TextureCache.Clear(); mapApi = new MapApi(); ShowLoading(); } public float GetProcess() { return process; } protected virtual void Update() { if (canvasGroup == null) { return; } if (targetAlpha != canvasGroup.alpha && depressFlag && slider.value >= 100 || _forceUpdate) { canvasGroup.blocksRaycasts = false; canvasGroup.alpha = Mathf.Lerp(canvasGroup.alpha, targetAlpha, alphaSpeed * Time.deltaTime); if (Mathf.Abs(targetAlpha - canvasGroup.alpha) <= 0.01f) { canvasGroup.alpha = targetAlpha; } if (canvasGroup.alpha == 0) { //StartGame(); transform.gameObject.SetActive(false); } } if (depressFlag) { _timer -= Time.deltaTime; if (_timer < 0 && tileHeightProcessed) { _forceUpdate = true; } } } //显示loading动画 protected virtual void ShowLoading() { } //在awake前触发。注入主控制器并设置UIManager public virtual void InjectController(CyclingController controller) { cyclingController = controller; } //初始化 public virtual void Init() { InitGameObject(); InitGameObjectData(); } //加载界面 protected virtual void InitGameObject() { mapName = panel.transform.Find("MapName").GetComponent(); distance = panel.transform.Find("Distance").GetComponent(); elevaction = panel.transform.Find("Elevaction").GetComponent(); slope = panel.transform.Find("Slope").GetComponent(); mapRouteImage = panel.transform.Find("MapRouteImage").GetComponent(); slider = panel.transform.Find("Process").GetComponent(); slider.gameObject.SetActive(false); processText = panel.transform.Find("ProcessText").GetComponent(); processText.gameObject.SetActive(false); mapDescText = panel.transform.Find("MapDesc").GetComponent(); rideNow = panel.transform.Find("RideNow").GetComponent