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; public AbstractDevice DeviceInfo { get;set; } protected override void Awake() { mText = this.transform.Find("Name").GetComponent(); } // 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(); if (shadow == null) { shadow = mText.gameObject.AddComponent(); } 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(); if (shadow != null) { //shadow = mText.gameObject.AddComponent(); shadow.enabled = false; } } } }