登录增加loading&赛事提醒修改

This commit is contained in:
lishuo committed 2021-09-13 18:21:43 +08:00
1 parent 51cea743be
commit dfb80658dd
23 files changed
+2137 -34355

No files matched your search

+1 -1
View File
@@ -76,7 +76,7 @@ namespace Assets.Scripts.Devices.Ble
{
return;
}
if(!this.hwInterface.BleState.Equals(BleState.On) || this.State != DeviceState.Disconnected)
if(!this.hwInterface.BleState.Equals(BleState.On) || (this.State != DeviceState.Disconnected && this.State != DeviceState.Connecting))
{
return;
}
@@ -35,20 +35,22 @@ namespace Assets.Scripts.Devices.Ble
this.managerStatusChanged -= value;
}
}
WclBleManagerStatus statusEnum = WclBleManagerStatus.RadioOff;
internal BleMobileThread() {
var self = this;
//初始蓝牙
BluetoothLEHardwareInterface.Initialize(true, false, () => {
statusEnum = WclBleManagerStatus.RadioOn;
managerInitialized?.Invoke(self);
},
(error) => {
statusEnum = WclBleManagerStatus.RadioOff;
BluetoothLEHardwareInterface.Log("Error: " + error);
if (error.Contains("Bluetooth LE Not Enabled"))
BluetoothLEHardwareInterface.BluetoothEnable(true);
}, (status) => {
var statusEnum = WclBleManagerStatus.RadioOn;
statusEnum = WclBleManagerStatus.RadioOn;
switch (status)
{
case 13:
@@ -66,11 +68,50 @@ namespace Assets.Scripts.Devices.Ble
}
public void StartWatcher() {
BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(ServiceUuids.GetServiceUuidList().ToArray(), null, (address, name, rssi, bytes) =>
var self = this;
if (statusEnum == WclBleManagerStatus.RadioOff)
{
ScanInfoReceived?.Invoke(this, address, name, rssi, bytes);
}, true);
BluetoothLEHardwareInterface.BluetoothEnable(true);
BluetoothLEHardwareInterface.Initialize(true, false, () =>
{
managerInitialized?.Invoke(self);
BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(ServiceUuids.GetServiceUuidList().ToArray(), null, (address, name, rssi, bytes) =>
{
ScanInfoReceived?.Invoke(self, address, name, rssi, bytes);
}, true);
},
(error) =>
{
statusEnum = WclBleManagerStatus.RadioOff;
BluetoothLEHardwareInterface.Log("Error: " + error);
if (error.Contains("Bluetooth LE Not Enabled"))
BluetoothLEHardwareInterface.BluetoothEnable(true);
}, (status) =>
{
statusEnum = WclBleManagerStatus.RadioOn;
switch (status)
{
case 13:
statusEnum = WclBleManagerStatus.RadioOff;
break;
case 11:
statusEnum = WclBleManagerStatus.RadioOn;
break;
}
if (managerStatusChanged != null)
{
managerStatusChanged.Invoke(self, statusEnum);
}
});
}
else
{
BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(ServiceUuids.GetServiceUuidList().ToArray(), null, (address, name, rssi, bytes) =>
{
ScanInfoReceived?.Invoke(self, address, name, rssi, bytes);
}, true);
}
}
public void Stop()
+12
View File
@@ -36,5 +36,17 @@ namespace Assets.Scripts.Scenes
MapUDPService.Dispose();
App.MainDeviceAdapter.Dispose();
}
private void OnApplicationPause(bool focus)
{
if (focus)
{
Debug.Log("我休眠了");
}
else
{
UIManager.InitNow();//重置当前时间
}
}
}
}
+42 -3
View File
@@ -1,6 +1,7 @@
using Assets.Scripts;
using Assets.Scripts.Apis;
using Assets.Scripts.Apis.Models;
using Assets.Scripts.Scenes;
using Assets.Scripts.UI.Control;
using Assets.Scripts.UI.Prefab.Login;
using DG.Tweening;
@@ -17,6 +18,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using UnityEngine;
using UnityEngine.Android;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
@@ -56,8 +58,10 @@ public class SignForm
public Dropdown countrys { get; set; }
public Dropdown units { get; set; }
}
public class LoginController : MonoBehaviour
public class LoginController : BaseScene
{
public GameObject loadingPanel { get; set; }
private Transform mainContent;
/*初始页面*/
private Transform quickContainer;
@@ -113,6 +117,16 @@ public class LoginController : MonoBehaviour
// Start is called before the first frame update
void Start()
{
#if UNITY_ANDROID || UNITY_IOS
loadingPanel = transform.Find("LoadingPanel").gameObject;
#endif
#if UNITY_ANDROID
if (!Permission.HasUserAuthorizedPermission(Permission.FineLocation))
Permission.RequestUserPermission(Permission.FineLocation);
if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
Permission.RequestUserPermission(Permission.ExternalStorageRead);
#endif
Init();
if (loginScrollView != null)
{
@@ -1114,6 +1128,9 @@ public class LoginController : MonoBehaviour
/// <param name="gou"></param>
void goMain(Transform gou)
{
#if (UNITY_ANDROID || UNITY_IOS)
StartCoroutine("Loading");
#endif
var data = userResult;
if (data == null) return;
//ConfigHelper.CurrentUser = res.data;
@@ -1135,8 +1152,30 @@ public class LoginController : MonoBehaviour
App.CurrentUser = data;
App.RideSetting.Sensitivity = data.Sensitivity;
//查询我参加的比赛
UIManager.UpdateJoinCompetition();
SceneManager.LoadSceneAsync("MainScene");
Task.Run(() =>
{
UIManager.UpdateJoinCompetition();
});
//SceneManager.LoadSceneAsync("MainScene");
StartCoroutine("LoadMain");
}
private IEnumerator Loading()
{
yield return null;
DontDestroyOnLoad(loadingPanel);
Utils.showLoadingExtension(loadingPanel);
}
private IEnumerator LoadMain()
{
yield return new WaitForSeconds(1f);
SceneManager.LoadSceneAsync("MainScene").completed += QuickLoginUser_completed;
}
private void QuickLoginUser_completed(AsyncOperation obj)
{
//Utils.hideLoadingExtension(loadingPanel);
}
/// <summary>
/// 缓存打钩的用户信息
+15 -5
View File
@@ -1,4 +1,5 @@
using Assets.Scripts;
using Assets.Scenes.Ride.Scripts;
using Assets.Scripts;
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.Scenes;
using Assets.Scripts.UI.Prefab.Device;
@@ -35,14 +36,16 @@ public class MainController : BaseScene
//rect1.offsetMin = Vector2.zero;
//rect1.offsetMax = Vector2.zero;
//transform.Find("ModalPanel").GetComponent<RectTransform>().sizeDelta = new Vector2(844, 390);
#else
App.MainDeviceAdapter.StartScan();
#endif
}
App.MainDeviceAdapter.StartScan();
}
// Start is called before the first frame update
async void Start()
{
{
UIManager.Instance.Root = root;
UIManager.Instance.MainPanel = this.transform.Find("Panel").GetComponent<PFUIPanel>();
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").GetComponent<PFUIPanel>();
@@ -94,6 +97,7 @@ public class MainController : BaseScene
float t = 1f;
float scanTicks = 0;
// Update is called once per frame
void Update()
{
@@ -103,6 +107,12 @@ public class MainController : BaseScene
App.CurrentScene = "Main";
UIManager.SendCompetitionStartMessage("Main");
t = 1;
scanTicks++;
if (scanTicks == 10)
{
App.MainDeviceAdapter.StopScan();
Debug.Log("StopScan");
}
}
}
@@ -30,6 +30,8 @@ namespace Assets.Scenes.Ride.Scripts
private GameObject CancelJoin { get; set; }
private GameObject ReadMore { get; set; }
CompetitionUIManager competitionUI { get; set; }
public override void InjectController(CyclingController controller)
{
cyclingController = controller;
@@ -45,7 +47,6 @@ namespace Assets.Scenes.Ride.Scripts
CompetitionDesc = panel.transform.Find("CompetitionDesc").GetComponent<RawImage>();
SponsorLogoImage = panel.transform.Find("SponsorTitle/Sponsor").GetComponent<RawImage>();
cyclingController.SetUIManager(mainPanel, modelPanel);
}
protected override void Start()
{
@@ -259,6 +260,8 @@ namespace Assets.Scenes.Ride.Scripts
Utils.showToast(gameObject, "race close");
return;
}
competitionUI = cyclingController.singleUIManager as CompetitionUIManager;
competitionUI?.SetMobileViewButton(false);
base.StartRide(baseEvent);
}
//观察
@@ -18,16 +18,18 @@ namespace Assets.Scenes.Ride.Scripts
Text title { get; set; }
Text timer { get; set; }
GameObject raceViewBtn { get; set; }
GameObject timerIcon { get; set; }
protected override void Start()
{
base.Start();
reviewPanel.SetActive(false);
//隐藏单人骑行时间
var spilitLineH2 = uipanel.transform.Find("ComputerPanel/SpilitLineH2").gameObject;
raceViewBtn = uipanel.transform.Find("RaceViewButton").gameObject;
#if UNITY_IOS || UNITY_ANDROID
viewButton.enabled = mainController.isWatch;
viewButton.interactable = mainController.isWatch;
timerIcon = uipanel.transform.Find("ComputerPanel/TimerIcon").gameObject;
timerIcon.SetActive(false);
#else
viewButton.gameObject.SetActive(false);
#endif
@@ -202,6 +204,14 @@ namespace Assets.Scenes.Ride.Scripts
}
}
public void SetMobileViewButton(bool enabled)
{
#if UNITY_IOS || UNITY_ANDROID
//viewButton.enabled = enabled;
viewButton.interactable = enabled;
#endif
}
protected override void StopRide(BaseEventData baseEventData)
{
if (!App.MainSceneParam.ContainsKey("Name"))
@@ -384,8 +384,8 @@ namespace Assets.Scenes.Ride.Scripts
if (mainController.competitionId > 0)
{
var showLeft = watchList.Count > 0;
viewButton.enabled = true;
viewButton.interactable = true;
//viewButton.enabled = true;
//viewButton.interactable = true;
distanceIconCompetition.SetActive(!showLeft);
totalDistanceCompetition.gameObject.SetActive(!showLeft);
totalDistance.gameObject.SetActive(showLeft);
@@ -93,11 +93,13 @@ public class CyclingController : DeviceServiceMonoBase
competitionId = App.CompetionId;
App.CompetionId = 0;//清空比赛参数
Resources.UnloadUnusedAssets();
}
void OnDestroy()
{
App.TextureCache.Clear();
//App.TextureCache.Clear();
Resources.UnloadUnusedAssets();
}
Transform target;
GameObject watcher;
@@ -437,7 +439,7 @@ public class CyclingController : DeviceServiceMonoBase
chartDataSourceScript.InitHorizontalScrolling(index);
}
//SingleUIManager singleUIManager;
BaseUIManager singleUIManager;
public BaseUIManager singleUIManager;
public void GameStart()
{
singleUIManager.StartRide();
@@ -2,10 +2,11 @@
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
namespace Assets.Scenes.Ride.Scripts
{
public class GameEvent { }
public class GameEvent { string key { get; set; } }
public class EventQueueSystem : MonoSingleton<EventQueueSystem>
{
@@ -25,7 +26,11 @@ namespace Assets.Scenes.Ride.Scripts
//注册侦听事件(持续)
public static void AddListener<T>(EventDelegate<T> del) where T : GameEvent
{
Instance.AddDelegate(del);
if (!HasListener(del))
{
Debug.Log(30);
Instance.AddDelegate(del);
}
}
//注册侦听事件(一次)
@@ -39,7 +44,8 @@ namespace Assets.Scenes.Ride.Scripts
//判定侦听事件是否存在
public static bool HasListener<T>(EventDelegate<T> del) where T : GameEvent
{
return Instance.delegateLookup.ContainsKey(del);
return Instance.delegateLookup.Keys.Where(c => c.GetType() == del.GetType()).Any();
//return Instance.delegateLookup.ContainsKey(del);
}
//移除侦听事件
@@ -114,6 +120,18 @@ namespace Assets.Scenes.Ride.Scripts
return;
Instance.eventQueue.Enqueue(e);
}
static List<string> keyList = new List<string>();
public static void QueueEventOnce(GameEvent e,string key)
{
if (!Instance.delegates.ContainsKey(e.GetType()))
return;
if (keyList.Contains(key))
return;
keyList.Add(key);
Debug.Log(126);
Instance.eventQueue.Enqueue(e);
}
float timer = 0.0f;
//事件队列触发处理
void Update()
@@ -16,6 +16,7 @@ public class QuickLoginUser : MonoBehaviour
{
QUserInfo user;
Transform top;
GameObject loadingPanel { get; set; }
// Start is called before the first frame update
void Start()
{
@@ -30,6 +31,8 @@ public class QuickLoginUser : MonoBehaviour
goMain();
});
#else
var loginController = FindObjectOfType<LoginController>();
loadingPanel = loginController.loadingPanel;
gameObject.GetComponent<Button>().onClick.AddListener(() => { goMain(); });
#endif
//transform.GetComponent<Button>().onClick.AddListener();
@@ -49,6 +52,10 @@ public class QuickLoginUser : MonoBehaviour
}
async void goMain()
{
#if (UNITY_ANDROID || UNITY_IOS)
StartCoroutine("Loading");
#endif
ApiBase.SetCookie(user.Cookie);
var r = await ConfigHelper.userApi.QuickLogin();
if (r.result)
@@ -56,13 +63,31 @@ public class QuickLoginUser : MonoBehaviour
top.GetComponent<LoginController>().SaveInfo(r.data);
App.CurrentUser = r.data;
App.RideSetting.Sensitivity = App.CurrentUser.Sensitivity;
SceneManager.LoadScene("MainScene");
//SceneManager.LoadScene("MainScene");
StartCoroutine("LoadMain");
}
else
{
Utils.showToast(gameObject, r.errMsg);
}
}
private IEnumerator Loading()
{
yield return null;
DontDestroyOnLoad(loadingPanel);
Utils.showLoadingExtension(loadingPanel);
}
private IEnumerator LoadMain() {
yield return new WaitForSeconds(1f);
SceneManager.LoadSceneAsync("MainScene").completed += QuickLoginUser_completed;
}
private void QuickLoginUser_completed(AsyncOperation obj)
{
//Utils.hideLoadingExtension(loadingPanel);
}
private void OnDestroy()
{
}
@@ -10,7 +10,7 @@ namespace Assets.Scenes.Ride.Scripts
public class RaceAlertController : PFUIPanel
{
public Text Content { get; set; }
//public Text Timer { get; set; }
public Text Timer { get; set; }
public GameObject GoBtn { get; set; }
public GameObject Card { get; set; }
public GameObject StayBtn { get; set; }
@@ -23,7 +23,7 @@ namespace Assets.Scenes.Ride.Scripts
protected override void Awake()
{
//Card
//Timer = this.transform.Find("Card/Timer").GetComponent<Text>();
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;
@@ -35,16 +35,19 @@ namespace Assets.Scenes.Ride.Scripts
float t = 1f;
private void Update()
{
//t -= Time.deltaTime;
//while (t <= 0)
//{
// if (ticks > 0)
// {
// ticks--;
// Timer.text = Helper.FormatTicks(ticks);
// }
// t = 1f;
//}
t -= Time.deltaTime;
while (t <= 0)
{
if (ticks > 0)
{
ticks--;
if (Timer != null)
{
Timer.text = Helper.FormatTicks(ticks);
}
}
t += 1f;
}
}
public void Set(DateTime startTime, DateTime now,string title, string sceneName, int competitionId,int routeId)
@@ -69,6 +72,8 @@ namespace Assets.Scenes.Ride.Scripts
{
App.CompetitionIdList.Add(CompetitionId);
this.Close();
Utils.DestroyChildren(transform);
DestroyImmediate(gameObject);
}
}
}
@@ -79,7 +79,7 @@ public class LocalRouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterH
Name.text = record.RouteName;
Time.text = record.StartTime.ToString();
RidingTime.text = $"<color={titleColor}>Riding time:</color>{record.Ticks}";
RidingTime.text = $"<color={titleColor}>Riding time:</color>{Helper.FormatTicks(record.Ticks)}";
RidingDistance.text = $"<color={titleColor}>Mileage:</color>{record.EndDistance.ToString("#0.00")}KM";
Device.text = $"<color={titleColor}>Cycling equipment:</color>{record.ManufacturerName}";
}
+36 -11
View File
@@ -117,7 +117,7 @@ public class UIManager : MonoBehaviour
{
get
{
return this.GetPanelInstance("RaceAlertPanel", ref this.mRaceAlertPanel);
return this.GetPanelNewInstance<RaceAlertController>("RaceAlertPanel");
}
}
@@ -126,7 +126,7 @@ public class UIManager : MonoBehaviour
{
get
{
return this.GetPanelInstance("RaceAlertBandPanel", ref this.mRaceAlertBandPanel);
return this.GetPanelNewInstance<RaceAlertController>("RaceAlertBandPanel");
}
}
@@ -269,6 +269,7 @@ public class UIManager : MonoBehaviour
}
EventQueueSystem.AddListener<CompetitonStartMessageEvent>(CompetitonStartHandler);
}
//比赛即将开始消息提醒
private void CompetitonStartHandler(CompetitonStartMessageEvent e)
{
@@ -282,14 +283,12 @@ public class UIManager : MonoBehaviour
}
else if (App.CurrentScene.Equals("Main"))
{
ShowRaceAlertBanelPanel();
if (mRaceAlertBandPanel != null)
var raceAlertBandPanel = ShowRaceAlertBanelPanel();
if (raceAlertBandPanel != null)
{
mRaceAlertBandPanel.Set(e.StartTime.ToLocalTime(), Now.GetDateTime(), e.title, e.SceneName, e.competitionId, e.routeId);
raceAlertBandPanel.Set(e.StartTime.ToLocalTime(), Now.GetDateTime(), e.title, e.SceneName, e.competitionId, e.routeId);
}
}
}
// Start is called before the first frame update
void Start()
@@ -328,14 +327,38 @@ public class UIManager : MonoBehaviour
{
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(), sceneName));
EventQueueSystem.QueueEventOnce(new CompetitonStartMessageEvent(item.Title, item.Id, item.RouteId, item.StartTime.ToLocalTime(), sceneName),"CompetitionAlert"+item.Id.ToString());
}
}
}
}
private T GetPanelNewInstance<T>(string prefabName)
{
T internalComponent = default(T);
{
#if !(UNITY_ANDROID || UNITY_IOS)
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/" + prefabName);
#else
UnityEngine.Object @object = Resources.Load("UI/Prefab/Panel/Mobile/" + prefabName);
#endif
if (@object != null)
{
GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(@object, base.transform.parent, false);
if (gameObject != null)
{
internalComponent = gameObject.GetComponent<T>();
}
}
}
return internalComponent;
}
private T GetPanelInstance<T>(string prefabName, ref T internalComponent)
{
if (internalComponent == null)
@@ -548,9 +571,11 @@ public class UIManager : MonoBehaviour
UIManager.Show(UIManager.Instance.RaceAlertPanel, null, true);
}
public static void ShowRaceAlertBanelPanel()
public static RaceAlertController ShowRaceAlertBanelPanel()
{
UIManager.Show(UIManager.Instance.RaceAlertBandPanel, null, true);
var raceAlertBandPanel = UIManager.Instance.RaceAlertBandPanel;
UIManager.Show(raceAlertBandPanel, null, true);
return raceAlertBandPanel;
}
//LoadingPf loading;
@@ -867,7 +892,7 @@ public class UIManager : MonoBehaviour
}
}
private async void InitNow()
public static async void InitNow()
{
var now = await ConfigHelper.userApi.GetNow();
_now = new CustomDateTime(now);
+11
View File
@@ -164,6 +164,7 @@ namespace Assets.Scripts
public static void showLoadingExtension(this GameObject game)
{
game.SetActive(true);
var loading = game.transform.Find("Loading");
if (loading == null)
{
@@ -175,6 +176,16 @@ namespace Assets.Scripts
}
loading.GetComponent<LoadingPf>().Show();
}
public static void hideLoadingExtension(this GameObject game)
{
var loading = game.transform.Find("Loading");
if (loading != null)
{
loading.GetComponent<LoadingPf>().Close();
}
game.SetActive(false);
}
public static void hideLoading(this GameObject game)
{
var parent = Utils.FindUpParent(game.transform);