Loading页面渐隐
This commit is contained in:
1 parent
10c82703f4
commit
018699c944
8 files changed
+3778
-3473
No files matched your search
@@ -0,0 +1,118 @@
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.Apis;
|
||||
using System;
|
||||
using Assets.Scripts;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
|
||||
//[ExecuteInEditMode]
|
||||
public class LoadingController : MonoBehaviour
|
||||
{
|
||||
Text mapName;
|
||||
AbstractMap _map;
|
||||
Text level;
|
||||
Text distance;
|
||||
Text elevaction;
|
||||
Text slope;
|
||||
Text rideNum;
|
||||
Text uploadByUserName;
|
||||
RawImage head;
|
||||
RawImage country;
|
||||
MapApi mapApi;
|
||||
GameObject panel;
|
||||
CanvasGroup canvasGroup;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
int routeId = App.RouteIdParam;
|
||||
mapApi = new MapApi();
|
||||
|
||||
panel = transform.Find("Panel").gameObject;
|
||||
mapName = transform.Find("Panel/MapName").GetComponent<Text>();
|
||||
level = transform.Find("Panel/level/Text").GetComponent<Text>();
|
||||
elevaction = transform.Find("Panel/Elevaction").GetComponent<Text>();
|
||||
slope = transform.Find("Panel/Slope").GetComponent<Text>();
|
||||
rideNum = transform.Find("Panel/RideNum").GetComponent<Text>();
|
||||
uploadByUserName = transform.Find("Panel/UploadByUserName").GetComponent<Text>();
|
||||
country = transform.Find("Panel/UploadByCountry").GetComponent<RawImage>();
|
||||
head = transform.Find("Panel/UploadByHead").GetComponent<RawImage>();
|
||||
var root = transform.parent;
|
||||
_map = root.Find("Map").GetComponent<AbstractMap>();
|
||||
canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
|
||||
if (routeId > 0)
|
||||
{
|
||||
var map = mapApi.GetById(routeId);
|
||||
var route = map.data;
|
||||
|
||||
|
||||
mapName.text = route.Name;
|
||||
level.text = route.Hard;
|
||||
elevaction.text = route.EleDifference.ToString("g0");
|
||||
slope.text = Math.Round(route.AverageGrade,2).ToString() + "%";
|
||||
rideNum.text = route.TheHeat.ToString();
|
||||
|
||||
var userList = mapApi.GetOnlineUserInfo(new int[] { route.UserId }).data;
|
||||
if (userList.Count > 0)
|
||||
{
|
||||
uploadByUserName.text = userList[0].Name;
|
||||
var countryUrl = App.Host + $"User/GetCountryImg?userid={userList[0].Id}";
|
||||
Utils.DisplayImage(StartCoroutine, head, userList[0].HeadImage);
|
||||
Utils.DisplayImage(StartCoroutine, country, countryUrl);
|
||||
}
|
||||
|
||||
_map.OnInitialized += _map_OnInitialized;
|
||||
_map.OnEditorPreviewEnabled += OnEditorPreviewEnabled;
|
||||
_map.OnEditorPreviewDisabled += OnEditorPreviewDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
void _map_OnInitialized()
|
||||
{
|
||||
var visualizer = _map.MapVisualizer;
|
||||
visualizer.OnMapVisualizerStateChanged += (s) =>
|
||||
{
|
||||
if (s == ModuleState.Finished)
|
||||
{
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
depressFlag = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
void OnEditorPreviewEnabled()
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnEditorPreviewDisabled()
|
||||
{
|
||||
transform.gameObject.SetActive(true);
|
||||
}
|
||||
public float targetAlpha = 0f;
|
||||
public float alphaSpeed = 2.0f;
|
||||
private bool depressFlag = false;
|
||||
void Update()
|
||||
{
|
||||
if (canvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetAlpha != canvasGroup.alpha && depressFlag)
|
||||
{
|
||||
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)
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user