122 lines
2.9 KiB
C#
122 lines
2.9 KiB
C#
using Assets.Scripts.Devices;
|
|
using Assets.Scripts.Devices.Ant;
|
|
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;
|
|
private Text mType;
|
|
public AbstractDevice DeviceInfo
|
|
{
|
|
get;set;
|
|
}
|
|
|
|
protected override void Awake()
|
|
{
|
|
mText = this.transform.Find("Name").GetComponent<Text>();
|
|
mType = this.transform.Find("Type").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.Network == NetworkType.ANT)
|
|
{
|
|
mText.text += "-" + DeviceInfo.DeviceNumber;
|
|
}
|
|
//if(DeviceInfo.State == DeviceState.Connected)
|
|
{
|
|
// this.SetSelectedStyle();
|
|
}
|
|
|
|
mType.text = DeviceInfo.Network.ToString();
|
|
}
|
|
|
|
|
|
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>();
|
|
}
|
|
shadow.enabled = true;
|
|
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();
|
|
}
|
|
public bool GetStatus()
|
|
{
|
|
return this.isOn;
|
|
}
|
|
|
|
public void Set(bool value)
|
|
{
|
|
if(!this.IsActive() || this.interactable == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.isOn = value;
|
|
if (this.isOn)
|
|
{
|
|
SetSelectedStyle();
|
|
}
|
|
else
|
|
{
|
|
mText.color = Color.white;
|
|
var shadow = mText.gameObject.GetComponent<Shadow>();
|
|
if (shadow != null)
|
|
{
|
|
//shadow = mText.gameObject.AddComponent<Shadow>();
|
|
shadow.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|