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-06-09 11:27:11 +08:00
|
|
|
|
private Image network;
|
|
|
|
|
|
private Image signal;
|
|
|
|
|
|
private float timer = 0f;
|
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>();
|
2021-06-09 11:27:11 +08:00
|
|
|
|
network = this.transform.Find("Network").GetComponent<Image>();
|
|
|
|
|
|
signal = this.transform.Find("Signal").GetComponent<Image>();
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
|
protected override void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
//this.currentSelectionState = SelectionState.Selected
|
2021-11-15 15:21:22 +08:00
|
|
|
|
if (DeviceInfo == null)
|
|
|
|
|
|
return;
|
2021-06-04 10:35:58 +08:00
|
|
|
|
mText.text = DeviceInfo.Name;// + "-" + DeviceInfo.DeviceNumber;
|
|
|
|
|
|
if(DeviceInfo.Network == NetworkType.ANT)
|
|
|
|
|
|
{
|
|
|
|
|
|
mText.text += "-" + DeviceInfo.DeviceNumber;
|
|
|
|
|
|
}
|
2021-04-01 09:33:19 +08:00
|
|
|
|
//if(DeviceInfo.State == DeviceState.Connected)
|
|
|
|
|
|
{
|
|
|
|
|
|
// this.SetSelectedStyle();
|
|
|
|
|
|
}
|
2021-06-04 10:35:58 +08:00
|
|
|
|
|
2021-06-09 11:27:11 +08:00
|
|
|
|
if(DeviceInfo.Network == NetworkType.BLE)
|
|
|
|
|
|
{
|
|
|
|
|
|
network.sprite = Resources.Load<Sprite>("Images/link_bluetooth_2");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
signal.enabled = false;
|
|
|
|
|
|
}
|
2021-06-10 17:46:43 +08:00
|
|
|
|
SetSignal();
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-09 11:27:11 +08:00
|
|
|
|
private void SetSignal()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(DeviceInfo == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-06-22 13:50:08 +08:00
|
|
|
|
Debug.Log(DeviceInfo.SignalStrength);
|
2021-06-09 11:27:11 +08:00
|
|
|
|
|
2021-06-09 18:16:35 +08:00
|
|
|
|
//signal.enabled = true;
|
|
|
|
|
|
|
2021-06-09 11:27:11 +08:00
|
|
|
|
var signalValue = DeviceInfo.SignalStrength * -1;
|
2021-06-09 18:16:35 +08:00
|
|
|
|
if (signalValue >= 0 && signalValue <= 20)
|
2021-06-09 11:27:11 +08:00
|
|
|
|
{
|
|
|
|
|
|
signal.sprite = Resources.Load<Sprite>("Images/Signal_1");
|
|
|
|
|
|
}
|
2021-06-09 18:16:35 +08:00
|
|
|
|
else if (signalValue > 20 && signalValue <= 60)
|
2021-06-09 11:27:11 +08:00
|
|
|
|
{
|
|
|
|
|
|
signal.sprite = Resources.Load<Sprite>("Images/Signal_2");
|
|
|
|
|
|
}
|
2021-06-22 13:50:08 +08:00
|
|
|
|
else if (signalValue > 60)//&& signalValue <= 97
|
2021-06-09 11:27:11 +08:00
|
|
|
|
{
|
|
|
|
|
|
signal.sprite = Resources.Load<Sprite>("Images/Signal_3");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-01 09:33:19 +08:00
|
|
|
|
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;
|
2021-06-09 11:27:11 +08:00
|
|
|
|
|
|
|
|
|
|
network.color = color1;
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Select()
|
|
|
|
|
|
{
|
|
|
|
|
|
//base.Select();
|
|
|
|
|
|
Debug.Log("select");
|
|
|
|
|
|
//SetSelectedStyle();
|
|
|
|
|
|
|
|
|
|
|
|
//UIManager.CloseModal();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnDeselect(BaseEventData eventData)
|
|
|
|
|
|
{
|
|
|
|
|
|
//base.OnDeselect(eventData);
|
2021-06-04 18:28:11 +08:00
|
|
|
|
//Debug.Log("deselect");
|
2021-04-01 09:33:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//DeviceInfo.Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
2021-06-09 11:27:11 +08:00
|
|
|
|
if (timer >= 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
timer = 0f;
|
|
|
|
|
|
|
|
|
|
|
|
SetSignal();
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
timer += Time.deltaTime;
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
2022-05-31 18:25:53 +08:00
|
|
|
|
var manager = FindObjectOfType<ConnectDeviceModal>();
|
|
|
|
|
|
manager.SelectDevice(this);
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mText.color = Color.white;
|
2021-06-09 11:27:11 +08:00
|
|
|
|
network.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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|