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

150 lines
5.0 KiB
C#
Raw Normal View History

2021-09-13 18:21:43 +08:00
using Assets.Scenes.Ride.Scripts;
using Assets.Scripts;
2021-04-23 09:22:12 +08:00
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.Scenes;
using Assets.Scripts.UI.Prefab.Device;
2021-04-23 09:22:12 +08:00
using Mapbox.Examples;
2021-08-26 15:08:02 +08:00
using System;
2021-04-14 15:02:33 +08:00
using System.Collections;
2021-03-25 16:53:39 +08:00
using System.Collections.Generic;
2021-04-23 09:22:12 +08:00
using System.Threading.Tasks;
2021-03-25 16:53:39 +08:00
using UnityEngine;
2021-04-19 14:36:08 +08:00
using UnityEngine.UI;
2021-03-25 16:53:39 +08:00
public class MainController : BaseScene
2021-03-25 16:53:39 +08:00
{
2021-04-14 15:02:33 +08:00
[SerializeField]GameObject root;
2021-04-19 14:36:08 +08:00
private Text Version;
protected override void Awake()
2021-04-14 15:02:33 +08:00
{
base.Awake();
Version = this.transform.Find("GameObject").Find("Version").GetComponent<Text>();
2021-04-23 09:22:12 +08:00
Version.text = "V"+App.AppVersion;
DeviceCache.Init(PFConstants.DeviceCacheFolder);
2021-06-08 10:30:26 +08:00
Loom.Initialize();
2021-08-24 17:50:14 +08:00
#if UNITY_ANDROID || UNITY_IOS
2021-08-25 14:32:49 +08:00
transform.GetComponent<CanvasScaler>().referenceResolution = new Vector2(844, 390);
2021-08-27 10:12:50 +08:00
//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;
2021-08-26 15:08:02 +08:00
//transform.Find("ModalPanel").GetComponent<RectTransform>().sizeDelta = new Vector2(844, 390);
#else
2021-11-04 13:24:40 +08:00
var modalRect = transform.Find("ModalPanel").GetComponent<RectTransform>();
modalRect.anchorMin = new Vector2(0.5f, 0.5f);
modalRect.anchorMax = new Vector2(0.5f, 0.5f);
modalRect.offsetMin = Vector2.zero;
modalRect.offsetMax = Vector2.zero;
modalRect.sizeDelta = new Vector2(1600, 900);
App.MainDeviceAdapter.StartScan();
2021-08-24 17:50:14 +08:00
#endif
2021-04-14 15:02:33 +08:00
2021-09-13 18:21:43 +08:00
}
2021-03-25 16:53:39 +08:00
// Start is called before the first frame update
2021-04-23 09:22:12 +08:00
async void Start()
2021-09-23 18:14:53 +08:00
{
2021-04-14 15:02:33 +08:00
UIManager.Instance.Root = root;
UIManager.Instance.MainPanel = this.transform.Find("Panel").GetComponent<PFUIPanel>();
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").GetComponent<PFUIPanel>();
2021-08-26 15:08:02 +08:00
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
2021-04-23 09:22:12 +08:00
{
await Login();
}
#endif
2021-03-25 16:53:39 +08:00
//MainMenu.transform.Find("Home").GetComponent<Button>().onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
2021-11-09 16:47:21 +08:00
//#if UNITY_ANDROID || UNITY_IOS
// if (!App.IsRowerMode.HasValue)
// {
// UIManager.ShowRowerSelector();
// return;
// }
// if (App.IsRowerMode == true)
// {
// UIManager.ShowRowerPanel();
// return;
// }
//#endif
2021-05-10 10:21:46 +08:00
if (App.MainSceneParam.ContainsKey("Name") && !string.IsNullOrEmpty(App.MainSceneParam["Name"]))
2021-04-14 15:02:33 +08:00
{
UIManager.ShowHomePanel();
2021-04-25 19:41:35 +08:00
if (App.MainSceneParam["Name"] == "MapListPanel")
2021-04-14 15:02:33 +08:00
{
UIManager.ShowMapListPanel();
}
2021-04-23 09:37:41 +08:00
if (App.MainSceneParam["Name"] == "UserInfoPanel")
{
UIManager.ShowUserInfoPanel();
}
if (App.MainSceneParam["Name"] == "RaceHomePanel")
{
UIManager.ShowRaceHomePanel();
}
2021-05-10 10:21:46 +08:00
App.MainSceneParam["Name"] = string.Empty;
2021-04-14 15:02:33 +08:00
}
else
{
UIManager.ShowHomePanel();
2021-04-14 15:02:33 +08:00
//UIManager.ShowUserInfoPanel();
//UIManager.ShowEditUserPanel();
//UIManager.ShowBigMapPanel();
2021-04-27 19:47:02 +08:00
//UIManager.ShowEarthPanel();
2021-04-14 15:02:33 +08:00
}
2021-09-23 18:14:53 +08:00
Task.Run(() => {
UIManager.UpdateJoinCompetition();//查询当前我参加的赛事
});
2021-03-25 16:53:39 +08:00
}
float t = 1f;
2021-09-13 18:21:43 +08:00
float scanTicks = 0;
2021-03-25 16:53:39 +08:00
// Update is called once per frame
2021-11-09 11:37:10 +08:00
protected override void Update()
2021-03-25 16:53:39 +08:00
{
2021-11-09 11:37:10 +08:00
base.Update();
2021-09-23 18:14:53 +08:00
if (App.canvasWidth != transform.GetComponent<RectTransform>().sizeDelta.x)
{
App.canvasWidth = transform.GetComponent<RectTransform>().sizeDelta.x;
Debug.Log(App.canvasWidth);
}
//Debug.Log(transform.GetComponent<RectTransform>().sizeDelta.x);
t -= Time.deltaTime;
while (t <= 0)
{
2021-07-29 20:01:38 +08:00
App.CurrentScene = "Main";
UIManager.SendCompetitionStartMessage("Main");
t = 1;
2021-09-13 18:21:43 +08:00
scanTicks++;
if (scanTicks == 10)
{
2021-09-15 14:17:11 +08:00
//App.MainDeviceAdapter.StopScan();
//Debug.Log("StopScan");
2021-09-13 18:21:43 +08:00
}
}
2021-03-25 16:53:39 +08:00
}
2021-04-23 09:22:12 +08:00
private async Task Login()
{
var result = await ConfigHelper.userApi.Login("13115011550", "laozhong", "");
App.CurrentUser = result.data;
}
2021-03-25 16:53:39 +08:00
}