You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
4.9 KiB
130 lines
4.9 KiB
1 year ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Events;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class DeviceItem : MonoBehaviour
|
||
|
{
|
||
|
public DeviceList BindData;
|
||
|
public Text ShowText;
|
||
|
public Button LocalBtn;
|
||
|
public Button ViewBtn;
|
||
|
public Image CanLocal;
|
||
|
void Start()
|
||
|
{
|
||
|
LocalBtn.onClick.AddListener(LocalBtn_Click);
|
||
|
ViewBtn.onClick.AddListener(ViewBtn_Click);
|
||
|
}
|
||
|
|
||
|
public void DataBind(DeviceList bindData, Color showColor)
|
||
|
{
|
||
|
BindData = bindData;
|
||
|
ShowText.text = bindData.deviceName;
|
||
|
LocalBtn.image.color = showColor;
|
||
|
}
|
||
|
private void ViewBtn_Click()
|
||
|
{
|
||
|
DeviceInfo.Instance.OnShow(BindData);
|
||
|
}
|
||
|
|
||
|
private void LocalBtn_Click()
|
||
|
{
|
||
|
if (DevicePanelManager.Instance.NowClickObject != null)
|
||
|
{
|
||
|
if (LocalBtn.image.color == Color.red)//解绑
|
||
|
{
|
||
|
MessageBox.Show("已经绑定该设备是否取消绑定?", Color.red, () =>
|
||
|
{
|
||
|
DeviceObjConfig config = new DeviceObjConfig();
|
||
|
config.DeviceId = BindData.deviceNo;
|
||
|
config.ObjName = "";
|
||
|
DevicePanelManager.Instance.SaveDeviceObjConfig(config);
|
||
|
});
|
||
|
}
|
||
|
else if (LocalBtn.image.color == Color.white)
|
||
|
{
|
||
|
bool hasbind = false;
|
||
|
foreach (var item in DevicePanelManager.Instance.BindObjectList)
|
||
|
{
|
||
|
if (item.ObjName == DevicePanelManager.Instance.NowClickObject.name)
|
||
|
{
|
||
|
hasbind = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (hasbind)
|
||
|
{
|
||
|
MessageBox.Show("设备已经被绑定是否更换绑定?", Color.red, () =>
|
||
|
{
|
||
|
foreach (var item in DevicePanelManager.Instance.BindObjectList)
|
||
|
{
|
||
|
if (item.ObjName == DevicePanelManager.Instance.NowClickObject.name)
|
||
|
{
|
||
|
item.ObjName = "";
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
DeviceObjConfig config = new DeviceObjConfig();
|
||
|
config.DeviceId = BindData.deviceNo;
|
||
|
config.ObjName = DevicePanelManager.Instance.NowClickObject.name;
|
||
|
DevicePanelManager.Instance.SaveDeviceObjConfig(config);
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("是否绑定该设备?", Color.red, () =>
|
||
|
{
|
||
|
DeviceObjConfig config = new DeviceObjConfig();
|
||
|
config.DeviceId = BindData.deviceNo;
|
||
|
config.ObjName = DevicePanelManager.Instance.NowClickObject.name;
|
||
|
DevicePanelManager.Instance.SaveDeviceObjConfig(config);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
bool hasbind = false;
|
||
|
foreach (var item in DevicePanelManager.Instance.BindObjectList)
|
||
|
{
|
||
|
if (item.ObjName == DevicePanelManager.Instance.NowClickObject.name)
|
||
|
{
|
||
|
hasbind = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (hasbind)
|
||
|
{
|
||
|
MessageBox.Show("设备已经被绑定是否更换绑定?", Color.red, () =>
|
||
|
{
|
||
|
foreach (var item in DevicePanelManager.Instance.BindObjectList)
|
||
|
{
|
||
|
if (item.ObjName == DevicePanelManager.Instance.NowClickObject.name)
|
||
|
{
|
||
|
item.ObjName = "";
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
DeviceObjConfig config = new DeviceObjConfig();
|
||
|
config.DeviceId = BindData.deviceNo;
|
||
|
config.ObjName = DevicePanelManager.Instance.NowClickObject.name;
|
||
|
DevicePanelManager.Instance.SaveDeviceObjConfig(config);
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("设备已经被绑定是否更换绑定?", Color.red, () =>
|
||
|
{
|
||
|
DeviceObjConfig config = new DeviceObjConfig();
|
||
|
config.DeviceId = BindData.deviceNo;
|
||
|
config.ObjName = DevicePanelManager.Instance.NowClickObject.name;
|
||
|
DevicePanelManager.Instance.SaveDeviceObjConfig(config);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|