合并后微调,增加赛事提醒功能

This commit is contained in:
lishuo 2021-07-23 18:07:12 +08:00
parent 21529db9dc
commit 7f8ac10d47
17 changed files with 1508 additions and 25 deletions

View File

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RaceButtonGroupScript : MonoBehaviour
{
@ -28,7 +29,9 @@ public class RaceButtonGroupScript : MonoBehaviour
}
void GoEnter()
{
Debug.Log(map);
App.RouteIdParam = map.RouteId;
App.CompetionId = map.Id;
SceneManager.LoadScene("Ride");
}
void GoCancel()
{

View File

@ -112,8 +112,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 98.5, y: -109}
m_SizeDelta: {x: 82, y: 22}
m_AnchoredPosition: {x: 108.5, y: -109}
m_SizeDelta: {x: 102, y: 22}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4634055342823246341
CanvasRenderer:
@ -149,13 +149,13 @@ MonoBehaviour:
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 4
m_Alignment: 3
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Total time
m_Text: Riding Time
--- !u!1 &8655198199642205025
GameObject:
m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 593994e2f8e5e644796cbad931c5338b
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -37,9 +37,9 @@ namespace Assets.Scripts.Apis
};
}
//查询我参与的比赛列表
public JsonResult<List<JoinedCompetitionModel>> GetMyCompetitionList(string name)
public JsonResult<List<JoinedCompetitionModel>> GetMyCompetitionList()
{
var list = Get<JsonResult<dynamic>>($"/MapCompetition/GetMyList?name={ name }");
var list = Get<JsonResult<dynamic>>($"/MapCompetition/v0/GetMyList");
return new JsonResult<List<JoinedCompetitionModel>>
{

View File

@ -51,6 +51,9 @@ public static class App
//public static string AppDownloadUrl { get; internal set; }
//public static string AppVersionCode { get; internal set; }
public static List<JoinedCompetitionModel> JoinedCompetitionList { get; set; }//我参加的比赛
public static List<int> CompetitionIdList = new List<int>();
private static MainDeviceAdapter mainDeviceAdapter;
public static MainDeviceAdapter MainDeviceAdapter
{

View File

@ -1056,6 +1056,8 @@ public class LoginController : MonoBehaviour
}
App.CurrentUser = data;
App.RideSetting.Sensitivity = data.Sensitivity;
//查询我参加的比赛
UIManager.UpdateJoinCompetition();
SceneManager.LoadScene("MainScene");
}
/// <summary>

View File

@ -53,6 +53,11 @@ public class MainController : BaseScene
{
UIManager.ShowUserInfoPanel();
}
if (App.MainSceneParam["Name"] == "RaceHomePanel")
{
UIManager.ShowRaceHomePanel();
}
App.MainSceneParam["Name"] = string.Empty;
}
else
@ -63,14 +68,21 @@ public class MainController : BaseScene
//UIManager.ShowBigMapPanel();
//UIManager.ShowEarthPanel();
}
UIManager.UpdateJoinCompetition();//查询当前我参加的赛事
}
float t = 1f;
// Update is called once per frame
void Update()
{
t -= Time.deltaTime;
while (t <= 0)
{
UIManager.SendCompetitionStartMessage("Main");
t = 1;
}
}
private async Task Login()

View File

@ -193,6 +193,7 @@ namespace Assets.Scenes.Ride.Scripts
this.gameObject.SetActive(false);
this.Destroy();
SceneManager.LoadScene("MainScene");
App.MainSceneParam["Name"] = "RaceHomePanel";
}
}
}

View File

@ -55,7 +55,7 @@ namespace Assets.Scenes.Ride.Scripts
{
//显示倒计时面板信息
//ShowCountDown(s.Item1, "remaining");
ShowCountDown(cyclingController.currentPlayer.TotalTicks, "Riding Time");
ShowCountDown(s.Item1, "Remaining Time");
}
//显示当前选手骑行时间
Timer.gameObject.SetActive(true);

View File

@ -159,7 +159,7 @@ namespace Assets.Scenes.Ride.Scripts
processText.text = $"{(f).ToString("#0")}%";
});
if (process == 100)
if (process >= 100)
{
rideNow.interactable = true;
rideNow.enabled = true;

View File

@ -148,6 +148,10 @@ public class CyclingController : DeviceServiceMonoBase
if (timer <= 0)//定时器 一秒执行一次
{
TcpHandler();
if (competitionId == 0)
{
UIManager.SendCompetitionStartMessage("Ride");
}
timer = 1.0f;
}
}

View File

@ -4,6 +4,8 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using Assets.Scripts.Apis.Models;
using System;
namespace Assets.Scenes.Ride.Scripts
{
@ -65,4 +67,21 @@ namespace Assets.Scenes.Ride.Scripts
this.url = url;
}
}
//赛事开始事件3
public class CompetitonStartMessageEvent : GameEvent
{
public string title;//赛事标题
public int competitionId;//赛事id
public int routeId;//路书id
public DateTime StartTime;//赛事开始时间
public CompetitonStartMessageEvent(string Title, int Id, int RouteId, DateTime StartTime)
{
this.title = Title;
this.competitionId = Id;
this.routeId = RouteId;
this.StartTime = StartTime;
}
}
}

View File

@ -1,4 +1,5 @@
using Assets.Scripts;
using Assets.Scenes.Ride.Scripts;
using Assets.Scripts;
using Assets.Scripts.Apis;
using Assets.Scripts.Apis.Models;
using Assets.Scripts.UI.Control;
@ -74,7 +75,8 @@ public class HomeController : PFUIPanel
UIManager.AddEvent(userInfo.Find("BtnMore").gameObject, EventTriggerType.PointerClick, x =>
{
UIManager.ShowUserInfoPanel();
// UIManager.ShowUserInfoPanel();
UIManager.ShowRaceAlertPanel();
//UIManager.ShowConfirm("Quit", "Do you want to quit PowerFun?", null);
});
//GetSummary();
@ -113,14 +115,7 @@ public class HomeController : PFUIPanel
//进入比赛
private void GoMatch(BaseEventData e)
{
//TODO:进入比赛列表
UIManager.ShowRaceHomePanel();
return;
#region
App.CompetionId = 1048;
App.RouteIdParam = 1215;
SceneManager.LoadScene("Ride");
#endregion
}
private void OnHover(BaseEventData e)
{

View File

@ -0,0 +1,62 @@
using Assets.Scripts;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
public class RaceAlertController : PFUIPanel
{
public Text Content { get; set; }
public Text Timer { get; set; }
public GameObject GoBtn { get; set; }
public GameObject StayBtn { get; set; }
public int ticks = 0;
public int CompetitionId { get; set; }
public int RouteId { get; set; }
protected override void Awake()
{
Timer = this.transform.Find("Card/Timer").GetComponent<Text>();
Content = this.transform.Find("Card/Content").GetComponent<Text>();
GoBtn = this.transform.Find("Card/Go").gameObject;
StayBtn = this.transform.Find("Card/Stay").gameObject;
UIManager.AddEvent(GoBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Go);
UIManager.AddEvent(StayBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Stay);
}
float t = 1f;
private void Update()
{
t -= Time.deltaTime;
while (t <= 0)
{
if (ticks > 0)
{
ticks--;
Timer.text = Helper.FormatTicks(ticks);
}
t = 1f;
}
}
//切换到当前用户视角
public void Go(BaseEventData baseEventData)
{
App.CompetitionIdList.Add(CompetitionId);
App.CompetionId = CompetitionId;
App.RouteIdParam = RouteId;
SceneManager.LoadScene("Ride");
}
public void Stay(BaseEventData baseEventData)
{
App.CompetitionIdList.Add(CompetitionId);
this.Close();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1640d8d75dcdfa744896cf9c703dca2b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,6 +13,7 @@ using Assets.Scripts.Apis.Models;
using System.Linq;
using Newtonsoft.Json.Linq;
using System;
using Assets.Scenes.Ride.Scripts;
public class UIManager : MonoBehaviour
{
@ -110,12 +111,12 @@ public class UIManager : MonoBehaviour
}
}
private CyclingController mCyclingController;
public CyclingController CyclingController
private RaceAlertController mRaceAlertPanel;
public RaceAlertController RaceAlertPanel
{
get
{
return this.GetPanelInstance("CyclingController", ref this.mCyclingController);
return this.GetPanelInstance("RaceAlertPanel", ref this.mRaceAlertPanel);
}
}
@ -207,12 +208,24 @@ public class UIManager : MonoBehaviour
Debug.Log(123);
InitNow();
}
EventQueueSystem.AddListener<CompetitonStartMessageEvent>(CompetitonStartHandler);
}
//比赛即将开始消息提醒
private void CompetitonStartHandler(CompetitonStartMessageEvent e)
{
ShowRaceAlertPanel();
if (mRaceAlertPanel != null)
{
mRaceAlertPanel.ticks = (int)(e.StartTime.ToLocalTime() - Now.GetDateTime()).TotalSeconds;
mRaceAlertPanel.Content.text = $"Your {e.title} race about to start";
mRaceAlertPanel.CompetitionId = e.competitionId;
mRaceAlertPanel.RouteId = e.routeId;
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
@ -220,6 +233,39 @@ public class UIManager : MonoBehaviour
{
}
//重新查询已经参赛列表
public static void UpdateJoinCompetition()
{
try
{
if (App.CurrentUser != null)
{
var api = ConfigHelper.mapCompetitionApi;
var s = api.GetMyCompetitionList();
App.JoinedCompetitionList = s.data;
}
}
catch (Exception)
{
}
}
//通知用户当前最近的一场比赛开始
public static void SendCompetitionStartMessage(string sceneName)
{
if (App.JoinedCompetitionList != null)
{
foreach (var item in App.JoinedCompetitionList)
{
var onStart = (item.StartTime.ToLocalTime() - Now.GetDateTime()).TotalMinutes <= 5 && (item.StartTime.ToLocalTime() - Now.GetDateTime()).TotalMinutes >= 0;
var notify = App.CompetitionIdList.Contains(item.Id);
if (onStart && !notify)
{
EventQueueSystem.QueueEvent(new CompetitonStartMessageEvent(item.Title, item.Id, item.RouteId, item.StartTime.ToLocalTime()));
}
}
}
}
private T GetPanelInstance<T>(string prefabName, ref T internalComponent)
{
@ -410,6 +456,11 @@ public class UIManager : MonoBehaviour
UIManager.Show(UIManager.Instance.EditUserPanel, UIManager.Instance.MainPanel);
}
public static void ShowRaceAlertPanel()
{
UIManager.Show(UIManager.Instance.RaceAlertPanel, null, true);
}
//LoadingPf loading;
public static void ShowLoadingDialogBox()
{