123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using ET.Client;
- using ET.EventType;
- using FairyGUI;
- using System.Collections.Generic;
- using UnityEngine;
- namespace ET
- {
- [Event]
- public class RankEventHandler : BEvent<RankChangeEvent>
- {
- protected override async ETTask OnEvent(RankChangeEvent a)
- {
- GameoverEventHandler.RankList = a.InfoList;
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class GameoverEventHandler : BEvent<EventType.GameoverEvent>
- {
- public static List<RankInfo> RankList = new();
- public static bool IsGameOver = false;
- protected override async ETTask OnEvent(EventType.GameoverEvent args)
- {
- IsGameOver = true;
- GComponent view;
- if(args.winForce == 1)
- {
- view = await UIHelper.Create("CommonDialog", "GameoverSuccess");
- }
- else
- {
- view = await UIHelper.Create("CommonDialog", "GameoverFailed");
- }
- //等1秒,等排行榜数据
- await TimerComponent.Instance.WaitAsync(1000);
- view.GetChild("btn_ok").onClick.Set(async () =>
- {
- GRoot.inst.RemoveChild(view);
- view = await UIHelper.Create("paiming", "paiming");
- InitRankView(view);
- view.GetChild("btn_ok").onClick.Set(() =>
- {
- RankList = null;
- IsGameOver = false;
- UIHelper.RemoveAllUiExceptSth();
- GlobalViewMgr.Instance.ReOpenGame();
- EventSystem.Instance.Publish<ReOpenGame>();
- });
- });
- }
- //展示排行榜
- private void InitRankView(GComponent view)
- {
- var list = view.GetChild("list").asList;
- var data = RankList ?? new List<RankInfo>();
- int i = 0;
- GComponent chd;
- for (; i < data.Count; i++)
- {
- if (i >= list.numChildren)
- {
- chd = UIPackage.CreateObject("paiming", $"paiming_0{((i<3) ? (i+1) : 4)}").asCom;
- list.AddChild(chd);
- }
- else
- {
- chd = list.GetChildAt(i).asCom;
- chd.visible = true;
- }
- if(i >= 3)
- {
- chd.GetChild("rank").text = (i + 1).ToString();
- }
- chd.GetChild("name").text = data[i].Name;
- chd.GetChild("score").text = data[i].Value.ToString();
- var mask = chd.GetChild("icon").asCom;
- var icon = mask.GetChild("iconLoader").asLoader;
- var url = data[i].Url;
- if (!string.IsNullOrEmpty(url))
- {
- LoadHeadIcon(icon, url).Coroutine();
- }
- }
- for (; i < list.numChildren; i++)
- {
- list.GetChildAt(i).visible = false;
- }
- }
- private async ETTask LoadHeadIcon(GLoader loader, string url)
- {
- var tex = await UrlImageLoader.Instance.LoadImage(url);
- if (tex != null)
- {
- if (GRoot.inst.GetChild("paiming") != null)
- {
- loader.texture = new NTexture(tex);
- }
- }
- }
- }
- }
|