protected override void OnSetUiInfo() { ControlUIInfo info = uiInfo; _baudrate = info.GetUIItem("Baudrate"); _id = info.GetUIItem("ID"); _returnDelay = info.GetUIItem("ReturnDelay"); _returnLevel = info.GetUIItem("ReturnLevel"); uiID.minValue = _id.minValue; uiID.maxValue = _id.maxValue; uiID.unitValue = 1; uiID.format = "f0"; uiID.Value = _id.value; uiReturnDelay.minValue = _returnDelay.minValue; uiReturnDelay.maxValue = _returnDelay.maxValue; uiReturnDelay.unitValue = 1; uiReturnDelay.format = "f0"; uiReturnDelay.Value = _returnDelay.value; OnChangedReturnDelay(); if (_returnLevel.value == 0) uiReturnLevel0.isOn = true; else if(_returnLevel.value == 1) uiReturnLevel1.isOn = true; else if (_returnLevel.value == 2) uiReturnLevel2.isOn = true; if(info.version == 1) { uiBaudrate.gameObject.SetActive(true); uiBPS.gameObject.SetActive(true); uiBaudrate2.gameObject.SetActive(false); uiBaudrate.minValue = _baudrate.minValue; uiBaudrate.maxValue = _baudrate.maxValue; uiBaudrate.unitValue = 1; uiBaudrate.format = "f0"; uiBaudrate.Value = _baudrate.value; OnChangedBaudrate(); } else if(info.version == 2) { uiBaudrate.gameObject.SetActive(false); uiBPS.gameObject.SetActive(false); uiBaudrate2.gameObject.SetActive(true); uiBaudrate2.value = _baudrate.value; } uiSave.interactable = false; }
protected override void OnSetUiInfo() { ControlUIInfo info = uiInfo; _preventEvent = true; _initializing = true; _maxTorque = info.GetUIItem("MaxTorque"); _punch = info.GetUIItem("Punch"); _torqueEnable = info.GetUIItem("TorqueEnable"); if (uiInfo.version == 1) { uiTorqueLimitView.gameObject.SetActive(true); _torqueLimit = info.GetUIItem("TorqueLimit"); _uiTorqueLimit = _torqueLimit.value; } else { uiTorqueLimitView.gameObject.SetActive(false); } _uiMaxTorque = _maxTorque.value; _uiPunch = _punch.value; _uiTorqueEnable = _torqueEnable.value; uiSave.interactable = false; _preventEvent = false; _initializing = false; }
protected override void OnSetUiInfo() { ControlUIInfo info = uiInfo; _preventEvent = true; _initializing = true; version = info.version; if (version == 1) { v1_uiView.gameObject.SetActive(true); v2_uiView.gameObject.SetActive(false); v3_uiView.gameObject.SetActive(false); v4_uiView.gameObject.SetActive(false); } else if(version == 2) { v1_uiView.gameObject.SetActive(false); v2_uiView.gameObject.SetActive(true); v3_uiView.gameObject.SetActive(false); v4_uiView.gameObject.SetActive(false); _buttonCount = info.GetUIItem("ButtonCount"); _uiButtonCount = _buttonCount.value; _sleepTimer = info.GetUIItem("SleepTimer"); _uiSleepTimer = _sleepTimer.value; } else if (version == 3) { v1_uiView.gameObject.SetActive(false); v2_uiView.gameObject.SetActive(false); v3_uiView.gameObject.SetActive(true); v4_uiView.gameObject.SetActive(false); } else if (version == 4) { v1_uiView.gameObject.SetActive(false); v2_uiView.gameObject.SetActive(false); v3_uiView.gameObject.SetActive(false); v4_uiView.gameObject.SetActive(true); _button = info.GetUIItem("Button"); _uiButton = _button.value; _led = info.GetUIItem("LED"); _uiLED = _led.value; } _preventEvent = false; _initializing = false; }
protected override void OnSetUiInfo() { ControlUIInfo info = uiInfo; _preventEvent = true; _initializing = true; _alramShutdown = info.GetUIItem("AlramShutdown"); _uiAlarmShutdown = _alramShutdown.value; _voltageLowLimit = info.GetUIItem("VoltageLowLimit"); _uiLowVoltageLimit = _voltageLowLimit.value; _voltageHighLimit = info.GetUIItem("VoltageHighLimit"); _uiHighVoltageLimit = _voltageHighLimit.value; _voltage = info.GetUIItem("Voltage"); _uiCurrentVoltage = _voltage.value; _temperatureHighLimit = info.GetUIItem("TemperatureHighLimit"); _uiHighTemperatureLimit = _temperatureHighLimit.value; _temperature = info.GetUIItem("Temperature"); _uiCurrentTemperature = _temperature.value; _led = info.GetUIItem("LED"); if (info.version == 1) { uiTitleAlarmLED.gameObject.SetActive(true); uiVoltageLED.gameObject.SetActive(true); uiAngleLED.gameObject.SetActive(true); uiOverheatingLED.gameObject.SetActive(true); uiRangeLED.gameObject.SetActive(true); uiChecksumLED.gameObject.SetActive(true); uiOverloadLED.gameObject.SetActive(true); uiInstructionLED.gameObject.SetActive(true); uiLED.gameObject.SetActive(true); uiLEDColor.gameObject.SetActive(false); uiLEDColorText.gameObject.SetActive(false); _alramLED = info.GetUIItem("AlramLED"); _uiAlarmLED = _alramLED.value; _uiLED = _led.value; } else if(info.version == 2) { uiTitleAlarmLED.gameObject.SetActive(false); uiVoltageLED.gameObject.SetActive(false); uiAngleLED.gameObject.SetActive(false); uiOverheatingLED.gameObject.SetActive(false); uiRangeLED.gameObject.SetActive(false); uiChecksumLED.gameObject.SetActive(false); uiOverloadLED.gameObject.SetActive(false); uiInstructionLED.gameObject.SetActive(false); uiLED.gameObject.SetActive(false); uiLEDColor.gameObject.SetActive(true); uiLEDColorText.gameObject.SetActive(true); _uiLEDColor = _led.value; } uiSave.interactable = false; _preventEvent = false; _initializing = false; }
protected override void OnSetUiInfo() { ControlUIInfo info = uiInfo; string[] tokens = info.uiParameters[0].Split(new char[] { '~' }); _minAngle = float.Parse(tokens[0]); _maxAngle = float.Parse(tokens[1]); tokens = info.uiParameters[1].Split(new char[] { '~' }); _minRPM = float.Parse(tokens[0]); _maxRPM = float.Parse(tokens[1]); _preventEvent = true; _initializing = true; _cwAngleLimit = info.GetUIItem("CWAngleLimit"); _ccwAngleLimit = info.GetUIItem("CCWAngleLimit"); _goalPosition = info.GetUIItem("GoalPosition"); _uiCWAngleLimit = _cwAngleLimit.value; _uiCCWAngleLimit = _ccwAngleLimit.value; if (info.version == 3) { _driveMode = info.GetUIItem("DriveMode"); if (_driveMode.value == 1) _uiJointMode = false; else if (_driveMode.value == 2) _uiJointMode = true; } else { if (_cwAngleLimit.value == _cwAngleLimit.minValue && _ccwAngleLimit.value == _ccwAngleLimit.minValue) _uiJointMode = false; else _uiJointMode = true; } _uiGoalPosition = _goalPosition.value; _presentPosition = info.GetUIItem("PresentPosition"); _uiPresentPosition = _presentPosition.value; _jointSpeed = info.GetUIItem("JointSpeed"); _uiJointSpeed = _jointSpeed.value; _presentJointSpeed = info.GetUIItem("PresentJointSpeed"); _uiPresentJointSpeed = _presentJointSpeed.value; _moving = info.GetUIItem("Moving"); _uiMoving = _moving.value; _presentLoad = info.GetUIItem("PresentLoad"); _uiPresentLoad = _presentLoad.value; _wheelSpeed = info.GetUIItem("WheelSpeed"); _uiWheelSpeed = _wheelSpeed.value; _presentWheelSpeed = info.GetUIItem("PresentWheelSpeed"); _uiPresentWheelSpeed = _presentWheelSpeed.value; uiSave.interactable = false; _preventEvent = false; _initializing = false; }
private bool DeleteItem(int nMode, ControlItemInfo info) { if (nMode == 0) //删除事件 { Card Card = card; //所属卡片 string CardName = Card.Name; //卡片名 string CardType = ""; //卡片类型 string CardID = ""; //卡片编号 if (CardName[2] == 'D') //普通卡片 { CardType = "Def"; CardID = CardName.Substring(3, CardName.Length - 3); } else { return(false); } //要删除的事件的编号 string ItemID = listi.Name.Substring(CardName.Length + 2, listi.Name.Length - (CardName.Length + 2)); //移除UI if (info.IsDelInUI) { list.Items.Remove(listi); } //标记为完成(不在文件中删除) if (!info.IsDelInFile && info.IsFinish) { //标记为完成(将编号向负数累加) Notes["Cards"][CardType][CardID][ItemID]["Finished"] = true; //将编号向负数累加 int nowFinishedNum = int.Parse(Notes["Cards"][CardType][CardID]["Finished"].ToString()) + 1; //要累加的编号数 Notes["Cards"][CardType][CardID]["Finished"] = nowFinishedNum.ToString(); //刷新编号数 Notes["Cards"][CardType][CardID]["Stat"] = (int.Parse(Notes["Cards"][CardType][CardID]["Stat"].ToString()) - 1).ToString(); JObject Item = new JObject(); //将编号向负数累加 Item.Add("Title", Notes["Cards"][CardType][CardID][ItemID]["Title"]); Item.Add("Finished", Notes["Cards"][CardType][CardID][ItemID]["Finished"]); Item.Add("CantDel", Notes["Cards"][CardType][CardID][ItemID]["CantDel"]); Notes["Cards"][CardType][CardID][(-nowFinishedNum).ToString()] = Item; Notes["Cards"][CardType][CardID][ItemID].Parent.Remove(); //移除本项 listi = new ListViewItem(); //清空对象 } //在文件中删除 if (info.IsDelInFile) { //循环删除 int i; for (i = int.Parse(ItemID); i < int.Parse(Notes["Cards"][CardType][CardID]["Stat"].ToString()); i++) { JObject Item = new JObject(); //将编号向负数累加 Item.Add("Title", Notes["Cards"][CardType][CardID][(i + 1).ToString()]["Title"]); Item.Add("Finished", Notes["Cards"][CardType][CardID][(i + 1).ToString()]["Finished"]); Item.Add("CantDel", Notes["Cards"][CardType][CardID][(i + 1).ToString()]["CantDel"]); Notes["Cards"][CardType][CardID][i.ToString()] = Item; } //移除最后一项 if (int.Parse(Notes["Cards"][CardType][CardID]["Stat"].ToString()) > 1) { Notes["Cards"][CardType][CardID][i.ToString()].Parent.Remove(); } else { Notes["Cards"][CardType][CardID][ItemID].Parent.Remove(); } //刷新事件总数 Notes["Cards"][CardType][CardID]["Stat"] = (int.Parse(Notes["Cards"][CardType][CardID]["Stat"].ToString()) - 1).ToString(); } SaveData(Notes); } else if (nMode == 1) //删除卡片 { Card Card = card; string CardName = Card.Name; string CardType = "Def"; string CardID = CardName.Substring(3, CardName.Length - 3); if (CardName[2] == 'D') //普通卡片 { Notes["Cards"][CardType][CardID].Parent.Remove(); Notes["Stat"]["NumOfDef"] = (int.Parse(Notes["Stat"]["NumOfDef"].ToString()) - 1).ToString(); } MainIn.Children.Remove(Card); MainIn.UnregisterName(Card.Name); } listi = new ListViewItem(); return(true); }
private void Load() { Sprite[] icons = Resources.LoadAll<Sprite>("Product/Icon"); List<ProductInfo> products = new List<ProductInfo>(); UnityEngine.Object[] list = Resources.LoadAll("Product", typeof(TextAsset)); for(int i=0; i<list.Length; i++) { TextAsset manifest = (TextAsset)list[i]; try { XmlDocument xml = new XmlDocument(); xml.LoadXml(manifest.text); XmlElement xmlEle = (XmlElement)xml.SelectSingleNode("/Product"); ProductInfo product = new ProductInfo(); product.key = xmlEle.Attributes["key"].Value; product.name = xmlEle.Attributes["name"].Value; product.type = xmlEle.Attributes["type"].Value; try { product.model = int.Parse(xmlEle.Attributes["model"].Value); } catch(Exception) { } product.firmware = Resources.Load<TextAsset>("Product/Firmware/" + product.key); if(product.firmware != null) { xmlEle = (XmlElement)xml.SelectSingleNode("/Product/Firmware"); product.firmwareVersion = float.Parse(xmlEle.Attributes["version"].Value); try { product.firmwareAddress = Convert.ToInt32(xmlEle.Attributes["address"].Value, 16); } catch (Exception) { } } xmlEle = (XmlElement)xml.SelectSingleNode("/Product/Calibration"); if(xmlEle != null) { product.calibration = Resources.Load<TextAsset>("Product/Calibration/" + product.key); if(product.calibration != null) product.calibrationVersion = float.Parse(xmlEle.Attributes["version"].Value); } product.image = Resources.Load<Sprite>("Product/Image/" + product.key); xmlEle = (XmlElement)xml.SelectSingleNode("/Product/Control"); string protocolValue = xmlEle.Attributes["protocol"].Value; if (protocolValue.Equals("CM")) product.protocol = PROTOCOL.CM; else if (protocolValue.Equals("DXL")) product.protocol = PROTOCOL.DXL; else if (protocolValue.Equals("DXL2")) product.protocol = PROTOCOL.DXL2; else product.protocol = PROTOCOL.UnKnown; List<ControlUIInfo> uis = new List<ControlUIInfo>(); XmlNodeList xmlNodes = xmlEle.SelectNodes("./UI"); for(int j=0; j<xmlNodes.Count; j++) { ControlUIInfo ui = new ControlUIInfo(); string stringValue = xmlNodes[j].Attributes["icon"].Value; for(int n=0; n<icons.Length; n++) { if(icons[n].name.Equals(stringValue) == true) { ui.icon = icons[n]; break; } } ui.name = xmlNodes[j].Attributes["name"].Value; ui.uiClass = xmlNodes[j].Attributes["class"].Value; ui.version = int.Parse(xmlNodes[j].Attributes["version"].Value); try { ui.uiParameters = xmlNodes[j].Attributes["param"].Value.Split(new char[] { ',' }); } catch(Exception) { } List<ControlItemInfo> items = new List<ControlItemInfo>(); XmlNodeList xmlNodes2 = xmlNodes[j].SelectNodes("./Item"); for(int k=0; k<xmlNodes2.Count; k++) { List<int> continueList = new List<int>(); try { string[] tokens = xmlNodes2[k].Attributes["continue"].Value.Split(new char[] { ',' }); for(int x=0; x<tokens.Length; x++) { string[] tokens2 = tokens[x].Split(new char[] { '~' }); int min = int.Parse(tokens2[0]); int max = min; if (tokens2.Length > 1) max = int.Parse(tokens2[1]); for (int y = min; y <= max; y++) continueList.Add(y); } } catch(Exception) { continueList.Add(0); } for (int l=0; l< continueList.Count; l++) { ControlItemInfo item = new ControlItemInfo(); item.name = xmlNodes2[k].Attributes["name"].Value; item.address = int.Parse(xmlNodes2[k].Attributes["address"].Value); stringValue = xmlNodes2[k].Attributes["access"].Value; if (stringValue.Equals("r") == true) item.access = ControlItemInfo.ACCESS.R; else if (stringValue.Equals("w") == true) item.access = ControlItemInfo.ACCESS.W; else if (stringValue.Equals("rw") == true) item.access = ControlItemInfo.ACCESS.RW; item.savable = bool.Parse(xmlNodes2[k].Attributes["save"].Value); item.bytes = int.Parse(xmlNodes2[k].Attributes["byte"].Value); try { item.defaultValue = int.Parse(xmlNodes2[k].Attributes["default"].Value); } catch (Exception) { item.defaultValue = 0; } try { string[] tokens = xmlNodes2[k].Attributes["range"].Value.Split(new char[] { '~' }); item.minValue = int.Parse(tokens[0]); item.maxValue = int.Parse(tokens[1]); } catch (Exception) { item.minValue = 0; item.maxValue = 256; for (int n = 1; n < item.bytes; n++) item.maxValue *= 256; item.maxValue--; } if(continueList.Count > 1) item.name += string.Format("{0:d}", continueList[l]); item.address += (continueList[l] * item.bytes); items.Add(item); } } ui.uiItems = items.ToArray(); uis.Add(ui); } product.uiList = uis.ToArray(); products.Add(product); } catch(Exception) { } } productList = products.ToArray(); }