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

98 lines
2.9 KiB
C#

using Assets.Scripts;
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.Scenes;
using Assets.Scripts.UI.Prefab.Device;
using Mapbox.Examples;
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);
#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>();
#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.PushHome();
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();
}
UIManager.UpdateJoinCompetition();//查询当前我参加的赛事
}
float t = 1f;
// Update is called once per frame
void Update()
{
t -= Time.deltaTime;
while (t <= 0)
{
App.CurrentScene = "Main";
UIManager.SendCompetitionStartMessage("Main");
t = 1;
}
}
private async Task Login()
{
var result = await ConfigHelper.userApi.Login("13115011550", "laozhong", "");
App.CurrentUser = result.data;
}
}