using Assets.Scripts; using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class RaceScript : PFUIPanel { // Start is called before the first frame update protected Transform currentItem { get; set; } IEnumerator _timer { get; set; } public Dictionary caches { get; set; } public override void Show() { base.Show(); transform.MyDOFade(); } protected void StartTime() { if (_timer == null) { _timer = Timer(); } timerFlag = true; StartCoroutine(_timer); } protected void StopTime() { timerFlag = false; } /// /// 通过消息调用,子给父传 /// /// public void SetCurrentItem(Transform t) { if (t != null) { currentItem = t; HandleTime(); StartTime(); } else { StopCoroutine(_timer); //StopTime(); } } private Transform avatar; protected void handleAvatar() { avatar = transform.Find("Avatar"); if (avatar != null) { Debug.Log(App.CurrentUser.WxHeadImg); Utils.DisplayImage(avatar.GetComponent(), App.CurrentUser.WxHeadImg, true); UIManager.AddEvent(avatar.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => { UIManager.ShowUserInfoPanel(); }); } } /*参考代码 var second = Math.Ceiling((Now - mapCompetition.StartTime.ToLocalTime()).TotalSeconds); var ts = TimeSpan.FromSeconds(second); return $"{ (int)ts.TotalHours }:{ts:mm}:{ts:ss}";*/ private bool timerFlag = false; IEnumerator Timer() { while (true) { yield return new WaitForSeconds(1.0f); // HandleTime(); //time = UIManager.Now.GetDateTime().AddSeconds(1); } } private void HandleTime() { if (currentItem != null && currentItem.Find("GetReadyContainer").gameObject.activeSelf) { var map = currentItem.GetComponent().mapCompetition; if (map.Status == 1) { currentItem.Find("GetReadyContainer/Title").GetComponent().text = App.GetLocalString("Start for Registration"); currentItem.Find("GetReadyContainer/Value").GetComponent().text = map.StartApplyTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); currentItem.Find("GetReadyContainer-2/Title").GetComponent().text = App.GetLocalString("Deadline for Registration"); currentItem.Find("GetReadyContainer-2/Value").GetComponent().text = map.EndApplyTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); if ((map.StartApplyTime.ToLocalTime() - UIManager.Now.GetDateTime()).TotalSeconds < 0 || (map.StartTime.ToLocalTime() - UIManager.Now.GetDateTime()).TotalSeconds < 0) { var res = ConfigHelper.mapCompetitionApi.GetById(map.Id); if (res.result) { currentItem.GetComponent().Initial(res.data, null); } } } else if (map.Status == 3) { currentItem.Find("GetReadyContainer/Title").GetComponent().text = App.GetLocalString("Start Time"); currentItem.Find("GetReadyContainer/Value").GetComponent().text = map.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); } //else if (map.Status == 4) //{ // currentItem.Find("GetReadyContainer/Title").GetComponent().text = "End Time"; // currentItem.Find("GetReadyContainer/Value").GetComponent().text = // map.FirstEndTime.HasValue ? // map.FirstEndTime.Value.ToString("yyyy-MM-dd HH:mm") : map.EndTime.ToString("yyyy-MM-dd HH:mm"); //} else { //Dictionary var time = map.StartTime.ToLocalTime() - UIManager.Now.GetDateTime(); if (time.TotalSeconds < 0) { currentItem.Find("GetReadyContainer").GetComponent().alpha = 0; var res = ConfigHelper.mapCompetitionApi.GetById(map.Id); if (res.result) { currentItem.GetComponent().Initial(res.data, null); } } else { currentItem.Find("GetReadyContainer").GetComponent().alpha = 1; currentItem.Find("GetReadyContainer/Title").GetComponent().text = App.GetLocalString(map.HasJoin ? "Get Ready" : "Start Time"); currentItem.Find("GetReadyContainer/Value").GetComponent().text = map.HasJoin ? Utils.GetCountDown(time): map.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); } } } } protected override void Awake() { base.Awake(); caches = new Dictionary(); if (_timer == null) { _timer = Timer(); } } // Update is called once per frame void Update() { } protected override void OnDestroy() { caches = null; Resources.UnloadUnusedAssets(); GC.Collect(); Debug.Log("list empty"); } }