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

92 lines
2.5 KiB
C#
Raw Normal View History

2021-04-23 09:22:12 +08:00
using Assets.Scripts;
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.UI.Prefab.Device;
2021-04-23 09:22:12 +08:00
using Mapbox.Examples;
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 : MonoBehaviour
{
2021-04-14 15:02:33 +08:00
[SerializeField]GameObject root;
2021-04-19 14:36:08 +08:00
private Text Version;
2021-04-14 15:02:33 +08:00
private void 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(Application.dataPath);
AntConnector.Instance((device2) => {
//自动连接
if (DeviceCache.Exist(device2))
{
Debug.Log("自动连接" + device2.DeviceNumber);
device2.Connect();
}
});
//Debug.Log(Application.dataPath);
2021-04-14 15:02:33 +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-03-25 16:53:39 +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-03-25 16:53:39 +08:00
2021-04-23 09:22:12 +08:00
if (App.CurrentUser == null)
{
await Login();
}
2021-03-25 16:53:39 +08:00
//MainMenu.transform.Find("Home").GetComponent<Button>().onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
2021-04-14 15:02:33 +08:00
if (App.MainSceneParam.ContainsKey("Name"))
{
2021-04-25 19:41:35 +08:00
UIManager.PushHome();
if (App.MainSceneParam["Name"] == "MapListPanel")
2021-04-14 15:02:33 +08:00
{
UIManager.ShowMapListPanel();
2021-04-25 19:41:35 +08:00
App.MainSceneParam["Name"] = string.Empty;
2021-04-14 15:02:33 +08:00
}
2021-04-23 09:37:41 +08:00
if (App.MainSceneParam["Name"] == "UserInfoPanel")
{
UIManager.ShowUserInfoPanel();
2021-04-25 19:41:35 +08:00
App.MainSceneParam["Name"] = string.Empty;
2021-04-23 09:37:41 +08:00
}
2021-04-14 15:02:33 +08:00
}
else
{
UIManager.ShowHomePanel();
//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-03-25 16:53:39 +08:00
}
// Update is called once per frame
void Update()
{
}
2021-04-23 09:22:12 +08:00
private async Task Login()
{
var result = await ConfigHelper.userApi.Login("13115011550", "laozhong", "");
App.CurrentUser = result.data;
}
private void OnApplicationQuit()
{
AntConnector.Instance().Dispose();
}
2021-03-25 16:53:39 +08:00
}