tcp逻辑调整,历史逻辑增加赛事相关派生类
This commit is contained in:
1 parent
ec45246aa4
commit
d6a7cd798f
41 files changed
+5420
-3128
No files matched your search
@@ -16,267 +16,9 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
|
||||
//[ExecuteInEditMode]
|
||||
public class LoadingController : MonoBehaviour
|
||||
public class LoadingController : AbstratctLoadingController
|
||||
{
|
||||
#region GameObject
|
||||
Text mapName;
|
||||
AbstractMap _map;
|
||||
Text level;
|
||||
Text distance;
|
||||
Text elevaction;
|
||||
Text slope;
|
||||
Text rideNum;
|
||||
Text uploadByUserName;
|
||||
Text processText;
|
||||
Text mapDescText;
|
||||
RawImage head;
|
||||
RawImage country;
|
||||
RawImage mapCountry;
|
||||
RawImage mapRouteImage;
|
||||
RawImage altitudeGraph;
|
||||
Button rideNow;
|
||||
Button cancel;
|
||||
MapApi mapApi;
|
||||
GameObject panel;
|
||||
CanvasGroup canvasGroup;
|
||||
Transform mapRanking;
|
||||
Slider slider;
|
||||
#endregion
|
||||
GameObject loadingPanel;
|
||||
#region 属性
|
||||
float process = 0;//0-100 %
|
||||
#endregion
|
||||
CyclingController cyclingController;
|
||||
private void Start()
|
||||
{
|
||||
App.TextureCache.Clear();
|
||||
loadingPanel = transform.Find("Panel/LoadingPanel").gameObject;
|
||||
loadingPanel.showLoadingExtension();
|
||||
//InitGameObject();
|
||||
}
|
||||
public void InjectController(CyclingController controller)
|
||||
{
|
||||
cyclingController = controller;
|
||||
PFUIPanel mainPanel = transform.Find("Panel").GetComponent<PFUIPanel>();
|
||||
PFUIPanel modelPanel = transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
||||
cyclingController.SetUIManager(mainPanel, modelPanel);
|
||||
}
|
||||
//提供给主控制器初始化用
|
||||
public void Init(MapRoute route)
|
||||
{
|
||||
InitGameObject();
|
||||
InitGameObjectData(route);
|
||||
}
|
||||
//展示当前路书图片
|
||||
public void SetMapRouteImage(string url)
|
||||
{
|
||||
Utils.DisplayImage(mapRouteImage, url);
|
||||
}
|
||||
public void DrawMapRoute(MapDataModel mapData)
|
||||
{
|
||||
var url = Helper.GetMapboxApiUrl(mapData.List);
|
||||
if (App.TextureCache.ContainsKey(url))
|
||||
{
|
||||
mapRouteImage.texture = App.TextureCache[url];
|
||||
var canvasGroup = mapRouteImage.GetComponent<CanvasGroup>();
|
||||
canvasGroup.DOFade(1, 1);
|
||||
this.AddProcess(10);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, dowloadCallBack);
|
||||
this.AddProcess(10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void dowloadCallBack(string url)
|
||||
{
|
||||
if (!App.TextureCache.ContainsKey(url))
|
||||
{
|
||||
App.TextureCache.Add(url, mapRouteImage.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
App.TextureCache[url] = mapRouteImage.texture;
|
||||
}
|
||||
var canvasGroup = mapRouteImage.GetComponent<CanvasGroup>();
|
||||
canvasGroup.DOFade(1, 1);
|
||||
|
||||
}
|
||||
//设定当前loading进度
|
||||
public void AddProcess(float v)
|
||||
{
|
||||
process += v;
|
||||
slider.value = process;
|
||||
slider.onValueChanged.AddListener((f) =>
|
||||
{
|
||||
processText.text = $"{(f ).ToString("#0")}%";
|
||||
});
|
||||
|
||||
if (process == 100)
|
||||
{
|
||||
rideNow.interactable = true;
|
||||
rideNow.enabled = true;
|
||||
}
|
||||
}
|
||||
//创建排行榜
|
||||
public void CreateRankingList(List<MapRouteRanking> list)
|
||||
{
|
||||
var prefab = Resources.Load<GameObject>("UI/Prefab/Ride/RankingItem");
|
||||
var parent = transform.Find("Panel/MapRanking");
|
||||
var title = transform.Find("Panel/RankingTitle").gameObject;
|
||||
if (list.Count == 0)
|
||||
{
|
||||
title.SetActive(false);
|
||||
}
|
||||
foreach (var item in list)
|
||||
{
|
||||
GameObject newObj = (GameObject)Instantiate(prefab, parent);
|
||||
var selectPlayerItemScript = newObj.GetComponent<RankingItemScript>();
|
||||
selectPlayerItemScript.SetRanking(item.RowNumber.ToString());
|
||||
selectPlayerItemScript.SetName(item.NickName);
|
||||
selectPlayerItemScript.SetTimer(item.IsDNF?"DNF":item.TotalTime);
|
||||
selectPlayerItemScript.SetHead(item.WxHeadImg);
|
||||
var texture = cyclingController.GetCountryImageByCode(item.CountryCode);
|
||||
selectPlayerItemScript.SetCountry(texture);
|
||||
}
|
||||
}
|
||||
private void InitGameObject()
|
||||
{
|
||||
panel = transform.Find("Panel").gameObject;
|
||||
mapName = transform.Find("Panel/MapName").GetComponent<Text>();
|
||||
distance = transform.Find("Panel/Distance").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>();
|
||||
mapCountry = transform.Find("Panel/Country").GetComponent<RawImage>();
|
||||
|
||||
head = transform.Find("Panel/UploadByHead").GetComponent<RawImage>();
|
||||
mapRouteImage = transform.Find("Panel/MapRouteImage").GetComponent<RawImage>();
|
||||
altitudeGraph = transform.Find("Panel/AltitudeGraph").GetComponent<RawImage>();
|
||||
mapRanking = transform.Find("Panel/MapRanking");
|
||||
slider = transform.Find("Panel/Process").GetComponent<Slider>();
|
||||
processText = transform.Find("Panel/ProcessText").GetComponent<Text>();
|
||||
mapDescText = transform.Find("Panel/MapDesc").GetComponent<Text>();
|
||||
rideNow = transform.Find("Panel/RideNow").GetComponent<Button>();
|
||||
cancel = transform.Find("Panel/Cancel").GetComponent<Button>();
|
||||
var root = transform.parent;
|
||||
_map = root.Find("Map").GetComponent<AbstractMap>();
|
||||
canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
rideNow.enabled = false;
|
||||
rideNow.interactable = false;
|
||||
UIManager.AddEvent(rideNow.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, StartRide);
|
||||
UIManager.AddEvent(cancel.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Cancel);
|
||||
|
||||
}
|
||||
void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
var checkAnt = cyclingController.CheckAnt();
|
||||
#if UNITY_EDITOR
|
||||
checkAnt = true;
|
||||
#endif
|
||||
if (!checkAnt)
|
||||
{
|
||||
var alert = (GameObject)Instantiate(Resources.Load("UI/Prefab/Ride/Alert"), panel.transform);
|
||||
alert.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
cyclingController.ReSetUIManager();
|
||||
cyclingController.GoContinueRide();
|
||||
//启用ridenow
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
depressFlag = true;
|
||||
}
|
||||
}
|
||||
void Cancel(BaseEventData baseEvent)
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
private void InitGameObjectData(MapRoute route)
|
||||
{
|
||||
if (route != null)
|
||||
{
|
||||
#region 绑定路书基本信息
|
||||
mapName.text = route.Name;
|
||||
level.text = route.Hard;
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
||||
rideNum.text = route.TheHeat.ToString();
|
||||
distance.text = route.Distance.ToString("f1") + "KM";
|
||||
mapDescText.text = route.Dec;
|
||||
var userList = ConfigHelper.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(head, userList[0].HeadImage);//头像
|
||||
|
||||
country.texture = cyclingController.GetCountryImageByCode(route.CountryCode);//上传者国家
|
||||
mapCountry.texture = cyclingController.GetCountryImageByName(userList[0].Country);//路书国家
|
||||
|
||||
Utils.DisplayImage(altitudeGraph, route.AltitudeGraph);//海拔图
|
||||
}
|
||||
#endregion
|
||||
StartCoroutine(HiddenLoading());
|
||||
#region 地图注册 排行榜等接口
|
||||
_map.OnInitialized += _map_OnInitialized;
|
||||
_map.OnEditorPreviewEnabled += OnEditorPreviewEnabled;
|
||||
_map.OnEditorPreviewDisabled += OnEditorPreviewDisabled;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
IEnumerator HiddenLoading()
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
loadingPanel.SetActive(false);
|
||||
}
|
||||
void _map_OnInitialized()
|
||||
{
|
||||
var visualizer = _map.MapVisualizer;
|
||||
visualizer.OnMapVisualizerStateChanged += (s) =>
|
||||
{
|
||||
if (s == ModuleState.Finished)
|
||||
{
|
||||
AddProcess(40);
|
||||
}
|
||||
};
|
||||
}
|
||||
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