using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Threading.Tasks; using Unity.VisualScripting; using UnityEngine; using static BaseConf; /// /// 设备-查询 /// [AddComponentMenu("设备查询"), Serializable] public class DeviceQuery : MonoBehaviour { public Conf2 conf2; public DeviceList deviceList = new DeviceList(); public GameObject hight; private void OnEnable() { #region new getRacksInfo(); #endregion #region old //if (deviceList.type == "2" && // deviceList.deviceType == "1" && // string.IsNullOrEmpty(deviceList.rackId)) //{ // var ParentGo = GameManager.Inst.FindParent(gameObject, GameManager.Inst.IsDesiredParent); // if (!ParentGo) // return; // deviceList.rackId = ParentGo.GetComponent().deviceList.id; // if (!string.IsNullOrEmpty(deviceList.id)) // gameObject.name = deviceList.id; //} //else if (deviceList.type == "2" && // deviceList.deviceType == "3" && // string.IsNullOrEmpty(deviceList.shelfId)) //{ // //if (transform.parent.GetComponent()) // var sb = GameManager.Inst.FindParent(gameObject, GameManager.Inst.IsFindRacks_goORTmsCards_go); // if (sb && sb.GetComponent()) // { // //var d = transform.parent.GetComponent(); // var d = sb.GetComponent(); // if (d.deviceList.deviceType == "1" && !string.IsNullOrEmpty(d.deviceList.id)) // { // //deviceList.shelfId = transform.parent.GetComponent().deviceList.id; // deviceList.shelfId = d.deviceList.id; // } // } // if (!string.IsNullOrEmpty(deviceList.id)) // gameObject.name = deviceList.id; //} #endregion } private void Awake() { } private void Start() { //await initAsync(""); } //public async Task initAsync() //{ // var jsonResult = await CombineJSON.GetJson_POST(GameManager.Inst.Jk_URL.sb_cx, GameManager.Inst.token); // Root root = JsonConvert.DeserializeObject(jsonResult); // foreach (var item in root.data) // { // if (item.id == deviceList.id) // { // deviceList = item; // break; // } // } //} [ContextMenu("同步模型编号、容积")] public void addscript() { deviceList.modelNum = transform.name; deviceList.occupyNum = GetComponent().volume.ToString(); } public void setTag() { //Transform //try //{ //} //catch //{ // xuhao = transform.parent; // U = xuhao.parent; // cabinet = U.parent; //} //var xuhao = transform.parent; //var U = xuhao.parent; //var cabinet = U.parent; } public bool getRacksInfo() { //if (conf2.module_type != ModuleType.板卡) // return false; GameManager manager = new GameManager(); if (deviceList.type == "2" && deviceList.deviceType == "3") { var Cabine = manager.FindParent(gameObject, manager.IsDesiredParent); var sb = manager.FindParent(gameObject, manager.IsFindRacks_goORMachineSlots_go); if (Cabine && sb && sb.GetComponent()) { var d = sb.GetComponent(); var c = Cabine.GetComponent(); deviceList.rackId = c.deviceList.id; if (d.deviceList.deviceType == "1" && string.IsNullOrEmpty(deviceList.shelfId)) { deviceList.shelfId = d.deviceList.id; } else if (d.deviceList.deviceType == "2" && string.IsNullOrEmpty(deviceList.slotId)) { deviceList.slotId = d.deviceList.id; } return true; } return false; } else if (deviceList.type == "2" && deviceList.deviceType == "1") { var sb = manager.FindParent(gameObject, manager.IsDesiredParent); if (sb && sb.GetComponent()) { var d = sb.GetComponent(); if (string.IsNullOrEmpty(deviceList.rackId)) { deviceList.rackId = d.deviceList.id; } if (!string.IsNullOrEmpty(deviceList.id)) gameObject.name = deviceList.id; return true; } return false; } return false; } #region JSON [Serializable] public class DeviceList { /// /// 设备ID /// [Tooltip("设备ID")] public string id; /// /// 名称 /// [Tooltip("名称")] public string deviceName; /// /// 设备编号 /// [Tooltip("设备编号")] public string deviceCode; /// /// 类型:1-机柜;2-设备 /// [Tooltip("类型:1-机柜;2-设备")] public string type; /// /// 类型 /// [Tooltip("类型")] public string typeStr; /// /// 设备类型:1-机框;2-机槽;3-板卡 /// [Tooltip("板卡类型:1-处理板;2-交叉板;3-光口板;4-线路板;5-主控板;6-以太网板")] public string deviceType; /// /// 设备类型 /// [Tooltip("设备类型")] public string deviceTypeStr; /// /// 所属机柜id /// [Tooltip("所属机柜id")] public string rackId; /// /// 所属机框id /// [Tooltip("所属机框id")] public string shelfId; /// /// 所属机槽id /// [Tooltip("所属机槽id")] public string slotId; /// /// 设备位置 /// [Tooltip("设备位置")] public string devicePosition; /// /// 机柜型号 /// [Tooltip("机柜型号")] public string machineModel; /// /// 状态:1-正常;0-禁用 /// [Tooltip("状态:1-正常;0-禁用")] public string status; /// /// 对联设备名称 /// [Tooltip("对联设备名称")] public string conDeviceName; /// /// 机柜类型:1-通信机柜;2-非通信机柜 /// [Tooltip("机柜类型:1-通信机柜;2-非通信机柜")] public string rackType; /// /// 柜门是否打开:1-开;0-关 /// [Tooltip("柜门是否打开:1-开;0-关")] public string openFlag; /// /// 后柜门是否打开:1-开;0-关 /// [Tooltip("后柜门是否打开:1-开;0-关")] public string backDoorFlag; /// /// 模型编号 /// [Tooltip("模型编号")] public string modelNum; /// /// U位占用数量 /// [Tooltip("U位占用数量")] public string occupyNum; /// /// U位剩余数量 /// [Tooltip("U位剩余数量")] public string residueNum; /// /// 投运时间 /// [Tooltip("投运时间")] public string operationTime; /// /// 负责人 /// [Tooltip("负责人")] public string directorName; /// /// 手机号 /// [Tooltip("手机号")] public string phone; /// /// 生产厂家 /// [Tooltip("生产厂家")] public string manufacturer; /// /// 电源属性 /// [Tooltip("电源属性")] public string powerProperties; /// /// 维护单位 /// [Tooltip("维护单位")] public string maintenanceUnit; /// /// 机框高度 /// [Tooltip("机框高度")] public string machineFrameHigh; /// /// 机框宽度 /// [Tooltip("机框宽度")] public string machineFrameWide; /// /// 机框厚度 /// [Tooltip("机框厚度")] public string machineFrameThick; /// /// 插槽数量 /// [Tooltip("插槽数量")] public string slotNum; /// /// 插槽排列方式 /// [Tooltip("插槽排列方式")] public string slotSort; /// /// 安装方式 /// [Tooltip("安装方式")] public string installMethod; /// /// 所属机框 /// [Tooltip("所属机框")] public string affiliationFrame; /// /// 父插槽名称 /// [Tooltip("父插槽名称")] public string parentSlotName; /// /// 插槽类型 /// [Tooltip("插槽类型")] public string slotType; /// /// 占用状态 /// [Tooltip("占用状态")] public string occupyStatus; /// /// 所属机槽名称 /// [Tooltip("所属机槽名称")] public string affiliationSlot; /// /// 端口数量 /// [Tooltip("端口数量")] public string portNum; /// /// 板卡功能 /// [Tooltip("板卡功能")] public string cardFunction; /// /// 板卡类型 /// [Tooltip("板卡类型")] public string cardType; /// /// 运行状态 /// [Tooltip("运行状态")] public string runStatus; /// /// /// [Tooltip("")] public string tmsId; /// /// 备注 /// [Tooltip("备注")] public string remark; /// /// /// [Tooltip("")] public string deviceTypeCode; /// /// 功能说明 /// [Tooltip("功能说明")] public string functionDescription; /// /// /// [Tooltip("")] public string createTime; /// /// /// [Tooltip("")] public string createName; /// /// 网络等级(1国网;2华东网;3省网;4地区网) /// [Tooltip("网络等级")] public string networkLevel; } [Serializable] public class Root { /// /// /// public string code; /// /// 操作成功 /// public string message; /// /// /// public List data; /// /// /// public string serverTime; } #endregion }