powerfun-unity/Assets/Scripts/UI/Prefab/Panel/DeviceController.cs

130 lines
3.6 KiB
C#
Raw Normal View History

2021-03-30 14:23:41 +08:00
using Assets.Scripts.Devices.Ant;
using System;
2021-03-29 09:10:59 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using DG.Tweening;
2021-03-29 09:10:59 +08:00
2021-03-30 14:23:41 +08:00
public class DeviceController : PFUIPanel
2021-03-29 09:10:59 +08:00
{
2021-03-30 14:23:41 +08:00
private float timer = 1.0f;
2021-04-01 14:29:58 +08:00
private Button mReturnBtn;
private Image antStatus;
private Sprite ant0;
private Sprite ant1;
2021-04-23 09:22:12 +08:00
private Sprite circuloCarga;
private Sprite circuloCompleto;
RectTransform circulo;
private bool _available = false;
private bool Available
{
get
{
return _available;
}
set
{
if (value == _available)
return;
_available = value;
if (_available)
{
antStatus.sprite = ant1;
//circulo.gameObject.SetActive(false);
DOTween.Kill(circulo, false);
circulo.GetComponent<Image>().sprite = circuloCompleto;
}
else
{
antStatus.sprite = ant0;
//circulo.gameObject.SetActive(true);
circulo.GetComponent<Image>().sprite = circuloCarga;
circulo.DOLocalRotate(new Vector3(0, 0, 360), 1f, RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1);
}
}
}
2021-03-30 14:23:41 +08:00
protected override void Awake()
{
2021-04-14 15:02:33 +08:00
base.Awake();
Debug.Log("device awake");
2021-03-30 14:23:41 +08:00
}
2021-03-29 09:10:59 +08:00
// Start is called before the first frame update
2021-03-30 14:23:41 +08:00
protected override void Start()
2021-03-29 09:10:59 +08:00
{
2021-03-30 14:23:41 +08:00
base.Start();
2021-04-01 09:33:19 +08:00
//Button button = this.transform.Find("Button").GetComponent<Button>();
//button.onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
2021-03-30 14:23:41 +08:00
2021-04-14 15:02:33 +08:00
mReturnBtn = this.transform.Find("CloseBtn").GetComponent<Button>();
UIManager.AddEvent(mReturnBtn.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
2021-04-01 14:29:58 +08:00
{
2021-04-14 15:02:33 +08:00
//UIManager.ShowHomePanel();
2021-04-15 17:09:35 +08:00
//UIManager.CloseModal();
this.Close();
2021-04-01 14:29:58 +08:00
}));
2021-04-19 14:36:08 +08:00
//UIManager.AddEvent(mReturnBtn.gameObject, EventTriggerType.PointerUp, (e) =>
//{
// Debug.Log("aaaaaaaaaaaaaa");
//});
var bg = this.transform.Find("Status").Find("Bg");
antStatus = bg.Find("Ant+").GetComponent<Image>();
2021-04-23 09:22:12 +08:00
circulo = bg.Find("Image").GetComponent<RectTransform>();
//circulo.DORotate(new Vector3(0, 0, 360), 1.5f, RotateMode.Fast).SetLoops(-1);
circulo.DOLocalRotate(new Vector3(0, 0, 360), 1f, RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1);
ant0 = Resources.Load<Sprite>("Images/ANT+_0");
2021-04-19 14:36:08 +08:00
ant1 = Resources.Load<Sprite>("Images/ANT+_2");
2021-04-23 09:22:12 +08:00
circuloCarga = Resources.Load<Sprite>("Images/icon-circulo-carga");
circuloCompleto = Resources.Load<Sprite>("Images/icon-circulo-completo");
2021-04-14 15:02:33 +08:00
2021-04-19 14:36:08 +08:00
base.SetRounded(bg, 64);
2021-03-29 09:10:59 +08:00
}
2021-04-14 15:02:33 +08:00
2021-03-29 09:10:59 +08:00
// Update is called once per frame
void Update()
{
2021-03-30 14:23:41 +08:00
timer -= Time.deltaTime;
if (timer <= 0)
{
2021-04-23 09:22:12 +08:00
Available = AntConnector.Instance().IsAvailable;
//if (AntConnector.Instance().IsAvailable)
2021-03-30 14:23:41 +08:00
//{
2021-04-23 09:22:12 +08:00
// antStatus.sprite = ant1;
//}
//else
//{
// antStatus.sprite = ant0;
2021-03-30 14:23:41 +08:00
//}
2021-03-29 09:10:59 +08:00
2021-03-30 14:23:41 +08:00
timer = 1.0f;
}
2021-03-29 09:10:59 +08:00
}
2021-04-01 09:33:19 +08:00
public override void Show()
{
var cg = this.GetComponent<CanvasGroup>();
cg.alpha = 0;
base.Show();
cg.DOFade(1f, 0.3f);
}
2021-04-23 09:22:12 +08:00
protected override void OnDisable()
2021-04-01 09:33:19 +08:00
{
2021-04-23 09:22:12 +08:00
2021-04-01 09:33:19 +08:00
}
2021-03-29 09:10:59 +08:00
}