powerfun-unity/Assets/Scripts/UI/Prefab/Panel/DeviceController.cs
2021-04-23 09:22:12 +08:00

130 lines
3.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;
using DG.Tweening;
public class DeviceController : PFUIPanel
{
private float timer = 1.0f;
private Button mReturnBtn;
private Image antStatus;
private Sprite ant0;
private Sprite ant1;
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);
}
}
}
protected override void Awake()
{
base.Awake();
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>();
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");
ant1 = Resources.Load<Sprite>("Images/ANT+_2");
circuloCarga = Resources.Load<Sprite>("Images/icon-circulo-carga");
circuloCompleto = Resources.Load<Sprite>("Images/icon-circulo-completo");
base.SetRounded(bg, 64);
}
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if (timer <= 0)
{
Available = AntConnector.Instance().IsAvailable;
//if (AntConnector.Instance().IsAvailable)
//{
// antStatus.sprite = ant1;
//}
//else
//{
// antStatus.sprite = ant0;
//}
timer = 1.0f;
}
}
public override void Show()
{
var cg = this.GetComponent<CanvasGroup>();
cg.alpha = 0;
base.Show();
cg.DOFade(1f, 0.3f);
}
protected override void OnDisable()
{
}
}