97 lines
2.6 KiB
C#
97 lines
2.6 KiB
C#
using Assets.Scripts.Devices.Ant;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class DeviceController : PFUIPanel
|
|
{
|
|
private float timer = 1.0f;
|
|
private Button mReturnBtn;
|
|
private Image antStatus;
|
|
private Sprite ant0;
|
|
private Sprite ant1;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
AntConnector.Instance();
|
|
|
|
Debug.Log("device awake");
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
//Button button = this.transform.Find("Button").GetComponent<Button>();
|
|
//button.onClick.AddListener(() =>
|
|
//{
|
|
// UIManager.ShowHomePanel();
|
|
//});
|
|
|
|
mReturnBtn = this.transform.Find("CloseBtn").GetComponent<Button>();
|
|
UIManager.AddEvent(mReturnBtn.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
|
|
{
|
|
//UIManager.ShowHomePanel();
|
|
//UIManager.CloseModal();
|
|
this.Close();
|
|
}));
|
|
//UIManager.AddEvent(mReturnBtn.gameObject, EventTriggerType.PointerUp, (e) =>
|
|
//{
|
|
// Debug.Log("aaaaaaaaaaaaaa");
|
|
//});
|
|
|
|
var bg = this.transform.Find("Status").Find("Bg");
|
|
antStatus = bg.Find("Ant+").GetComponent<Image>();
|
|
|
|
ant0 = Resources.Load<Sprite>("Images/ANT+_0");
|
|
ant1 = Resources.Load<Sprite>("Images/ANT+_2");
|
|
|
|
|
|
base.SetRounded(bg, 64);
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
timer -= Time.deltaTime;
|
|
if (timer <= 0)
|
|
{
|
|
if (AntConnector.Instance().IsAvailable)
|
|
{
|
|
antStatus.sprite = ant1;
|
|
}
|
|
else
|
|
{
|
|
antStatus.sprite = ant0;
|
|
}
|
|
//this.toggle.isOn = AntConnector.Instance().IsAvailable;
|
|
|
|
//foreach (var item in AntConnector.Instance().discoveredDevices)
|
|
//{
|
|
// if (!devices.ContainsKey(item.DeviceNumber))
|
|
// {
|
|
// var dev1 = Instantiate(device);
|
|
// dev1.transform.SetParent(this.grid.transform);
|
|
// var s1 = dev1.GetComponent<Assets.Scripts.UI.Devicea>();
|
|
// s1.Device = item;
|
|
|
|
// devices.Add(item.DeviceNumber, dev1);
|
|
// }
|
|
//}
|
|
|
|
timer = 1.0f;
|
|
}
|
|
}
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
AntConnector.Instance().Dispose();
|
|
}
|
|
}
|