145 lines
5.2 KiB
C#
Raw Normal View History

2021-07-20 09:58:01 +08:00
using Assets.Scripts;
2021-07-27 18:36:49 +08:00
using DG.Tweening;
2021-07-20 09:58:01 +08:00
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; }
2021-07-27 18:36:49 +08:00
public override void Show()
{
base.Show();
transform.MyDOFade();
2021-07-27 18:36:49 +08:00
}
2021-07-20 09:58:01 +08:00
protected void StartTime()
{
timerFlag = true;
StartCoroutine(Timer());
}
protected void StopTime()
{
timerFlag = false;
}
/// <summary>
/// 通过消息调用,子给父传
/// </summary>
/// <param name="t"></param>
public void SetCurrentItem(Transform t)
{
2021-07-23 15:04:29 +08:00
if (t != null)
{
2021-08-27 15:06:56 +08:00
currentItem = t;
HandleTime();
2021-07-23 15:04:29 +08:00
StartTime();
}
else
{
StopTime();
}
2021-07-20 09:58:01 +08:00
}
2021-07-27 18:36:49 +08:00
private Transform avatar;
protected void handleAvatar()
{
avatar = transform.Find("Avatar");
if (avatar != null)
{
Debug.Log(App.CurrentUser.WxHeadImg);
Utils.DisplayImage(avatar.GetComponent<RawImage>(), App.CurrentUser.WxHeadImg, true);
UIManager.AddEvent(avatar.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
UIManager.ShowUserInfoPanel();
});
}
}
2021-07-20 09:58:01 +08:00
/*
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 (timerFlag)
{
yield return new WaitForSeconds(1.0f); // 停止执行1秒
HandleTime();
//time = UIManager.Now.GetDateTime().AddSeconds(1);
}
}
private void HandleTime()
{
if (currentItem != null && currentItem.Find("GetReadyContainer").gameObject.activeSelf)
{
var map = currentItem.GetComponent<RaceItemScript>().mapCompetition;
2021-07-27 10:32:39 +08:00
if (map.Status == 1)
2021-07-20 09:58:01 +08:00
{
2021-07-29 13:55:33 +08:00
currentItem.Find("GetReadyContainer/Title").GetComponent<Text>().text = "Start for Registration";
2021-07-28 14:59:21 +08:00
currentItem.Find("GetReadyContainer/Value").GetComponent<Text>().text =
2021-07-29 15:45:44 +08:00
map.StartApplyTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm");
2021-07-29 13:55:33 +08:00
currentItem.Find("GetReadyContainer-2/Title").GetComponent<Text>().text = "Deadline for Registration";
2021-07-27 10:32:39 +08:00
currentItem.Find("GetReadyContainer-2/Value").GetComponent<Text>().text =
2021-07-29 15:45:44 +08:00
map.EndApplyTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm");
2021-07-28 14:59:21 +08:00
2021-07-29 15:45:44 +08:00
if ((map.StartApplyTime.ToLocalTime() - UIManager.Now.GetDateTime()).TotalSeconds < 0 ||
(map.StartTime.ToLocalTime() - UIManager.Now.GetDateTime()).TotalSeconds < 0)
2021-07-28 14:59:21 +08:00
{
var res = ConfigHelper.mapCompetitionApi.GetById(map.Id);
if (res.result)
{
currentItem.GetComponent<RaceItemScript>().Initial(res.data, null);
}
}
}
2021-07-28 21:09:34 +08:00
else if (map.Status == 3)
{
currentItem.Find("GetReadyContainer/Title").GetComponent<Text>().text = "Start Time";
currentItem.Find("GetReadyContainer/Value").GetComponent<Text>().text =
2021-07-29 15:45:44 +08:00
map.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm");
2021-07-28 21:09:34 +08:00
}
2021-07-29 13:55:33 +08:00
//else if (map.Status == 4)
//{
// currentItem.Find("GetReadyContainer/Title").GetComponent<Text>().text = "End Time";
// currentItem.Find("GetReadyContainer/Value").GetComponent<Text>().text =
// map.FirstEndTime.HasValue ?
// map.FirstEndTime.Value.ToString("yyyy-MM-dd HH:mm") : map.EndTime.ToString("yyyy-MM-dd HH:mm");
//}
2021-07-28 14:59:21 +08:00
else
2021-07-20 09:58:01 +08:00
{
2021-07-27 10:32:39 +08:00
//Dictionary<int,>
2021-07-28 18:33:52 +08:00
var time = map.StartTime.ToLocalTime() - UIManager.Now.GetDateTime();
2021-07-27 10:32:39 +08:00
if (time.TotalSeconds < 0)
{
currentItem.Find("GetReadyContainer").GetComponent<CanvasGroup>().alpha = 0;
2021-07-27 18:36:49 +08:00
var res = ConfigHelper.mapCompetitionApi.GetById(map.Id);
2021-07-28 14:59:21 +08:00
if (res.result)
2021-07-27 18:36:49 +08:00
{
currentItem.GetComponent<RaceItemScript>().Initial(res.data, null);
}
2021-07-27 10:32:39 +08:00
}
else
{
currentItem.Find("GetReadyContainer").GetComponent<CanvasGroup>().alpha = 1;
currentItem.Find("GetReadyContainer/Title").GetComponent<Text>().text
2021-07-28 18:33:52 +08:00
= map.HasJoin ? "Get Ready" : "Start Time";
2021-07-27 10:32:39 +08:00
currentItem.Find("GetReadyContainer/Value").GetComponent<Text>().text
2021-07-29 15:45:44 +08:00
= map.HasJoin ? Utils.GetCountDown(time): map.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm");
2021-07-27 10:32:39 +08:00
}
2021-07-20 09:58:01 +08:00
}
}
}
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}