114 lines
2.6 KiB
C#
Raw Normal View History

2021-05-19 14:38:48 +08:00
using Assets.Scripts.Devices;
using Assets.Scripts.Devices.Ant;
2021-04-01 09:33:19 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
{
private bool isOn;
private Text mText;
2021-05-19 14:38:48 +08:00
public AbstractDevice DeviceInfo
2021-04-01 09:33:19 +08:00
{
get;set;
}
protected override void Awake()
{
mText = this.transform.Find("Name").GetComponent<Text>();
}
// Start is called before the first frame update
protected override void Start()
{
//this.currentSelectionState = SelectionState.Selected
mText.text = DeviceInfo.Name + "-" + DeviceInfo.DeviceNumber;
//if(DeviceInfo.State == DeviceState.Connected)
{
// this.SetSelectedStyle();
}
}
public override void OnPointerEnter(PointerEventData eventData)
{
//base.OnPointerEnter(eventData);
//Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
private void SetSelectedStyle()
{
ColorUtility.TryParseHtmlString("#F93086", out Color color);
mText.color = color;
var shadow = mText.gameObject.GetComponent<Shadow>();
if (shadow == null)
{
shadow = mText.gameObject.AddComponent<Shadow>();
}
2021-04-14 15:02:33 +08:00
shadow.enabled = true;
2021-04-01 09:33:19 +08:00
ColorUtility.TryParseHtmlString("#F93086", out Color color1);
shadow.effectColor = color1;
}
public override void Select()
{
//base.Select();
Debug.Log("select");
//SetSelectedStyle();
//UIManager.CloseModal();
}
public override void OnDeselect(BaseEventData eventData)
{
//base.OnDeselect(eventData);
Debug.Log("deselect");
//DeviceInfo.Disconnect();
}
// Update is called once per frame
void Update()
{
}
public void OnPointerClick(PointerEventData eventData)
{
//this.Select();
//DeviceInfo.Connect();
}
2021-04-14 15:02:33 +08:00
public bool GetStatus()
{
return this.isOn;
}
2021-04-01 09:33:19 +08:00
public void Set(bool value)
{
if(!this.IsActive() || this.interactable == false)
{
return;
}
this.isOn = value;
if (this.isOn)
{
SetSelectedStyle();
}
else
{
mText.color = Color.white;
2021-04-14 15:02:33 +08:00
var shadow = mText.gameObject.GetComponent<Shadow>();
if (shadow != null)
{
//shadow = mText.gameObject.AddComponent<Shadow>();
shadow.enabled = false;
}
2021-04-01 09:33:19 +08:00
}
}
}