powerfun-unity/Assets/Scripts/Scenes/MainController.cs

125 lines
4.1 KiB
C#

using Assets.Scenes.Ride.Scripts;
using Assets.Scripts;
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.Scenes;
using Assets.Scripts.UI.Prefab.Device;
using Mapbox.Examples;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
public class MainController : BaseScene
{
[SerializeField]GameObject root;
private Text Version;
protected override void Awake()
{
base.Awake();
Version = this.transform.Find("GameObject").Find("Version").GetComponent<Text>();
Version.text = "V"+App.AppVersion;
DeviceCache.Init(PFConstants.DeviceCacheFolder);
Loom.Initialize();
#if UNITY_ANDROID || UNITY_IOS
transform.GetComponent<CanvasScaler>().referenceResolution = new Vector2(844, 390);
//transform.Find("Panel").GetComponent<RectTransform>().sizeDelta = new Vector2(844, 390);
var rectTransform = transform.Find("Panel").GetComponent<RectTransform>();
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
//var rect1 = transform.Find("GameObject").GetComponent<RectTransform>();
//rect1.anchorMin = Vector2.zero;
//rect1.anchorMax = Vector2.one;
//rect1.offsetMin = Vector2.zero;
//rect1.offsetMax = Vector2.zero;
//transform.Find("ModalPanel").GetComponent<RectTransform>().sizeDelta = new Vector2(844, 390);
#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>();
transform.Find("MobileInfo/BatteryText").GetComponent<Text>().text =
$"{Math.Round(SystemInfo.batteryLevel * 100, 0)}%";
transform.Find("MobileInfo/TimeText").GetComponent<Text>().text =
DateTime.Now.ToString("HH:mm");
#if UNITY_EDITOR
if (App.CurrentUser == null) //App.CurrentUser == null
{
await Login();
}
#endif
//MainMenu.transform.Find("Home").GetComponent<Button>().onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
if (App.MainSceneParam.ContainsKey("Name") && !string.IsNullOrEmpty(App.MainSceneParam["Name"]))
{
UIManager.ShowHomePanel();
if (App.MainSceneParam["Name"] == "MapListPanel")
{
UIManager.ShowMapListPanel();
}
if (App.MainSceneParam["Name"] == "UserInfoPanel")
{
UIManager.ShowUserInfoPanel();
}
if (App.MainSceneParam["Name"] == "RaceHomePanel")
{
UIManager.ShowRaceHomePanel();
}
App.MainSceneParam["Name"] = string.Empty;
}
else
{
UIManager.ShowHomePanel();
//UIManager.ShowUserInfoPanel();
//UIManager.ShowEditUserPanel();
//UIManager.ShowBigMapPanel();
//UIManager.ShowEarthPanel();
}
Task.Run(() => {
UIManager.UpdateJoinCompetition();//查询当前我参加的赛事
});
}
float t = 1f;
float scanTicks = 0;
// Update is called once per frame
void Update()
{
t -= Time.deltaTime;
while (t <= 0)
{
App.CurrentScene = "Main";
UIManager.SendCompetitionStartMessage("Main");
t = 1;
scanTicks++;
if (scanTicks == 10)
{
//App.MainDeviceAdapter.StopScan();
//Debug.Log("StopScan");
}
}
}
private async Task Login()
{
var result = await ConfigHelper.userApi.Login("13115011550", "laozhong", "");
App.CurrentUser = result.data;
}
}