public override bool InitData(object _data) { XmlData.XmlClassData _xmldata = _data as XmlData.XmlClassData; if (_xmldata == null) { return(false); } m_BaseData.InitMyData(_xmldata); return(true); }
public void InitMyData(XmlData.XmlClassData data) { System.Reflection.FieldInfo field; int index = 0; foreach (var item in data) { if (DataFields == null || DataFieldsDict == null || !DataFieldsDict.ContainsKey(item.sName)) { Log.Error(this.GetType().Name + "该逻辑参数与xml配置不一致"); continue; } index = DataFieldsDict[item.sName]; field = DataFields[index]; if (field != null) { if (item.sType.Equals("System.Boolean")) { field.SetValue(this, Convert.ToBoolean(item.sValue)); } else if (item.sType.Equals("System.Int32")) { field.SetValue(this, Convert.ToInt32(item.sValue)); } else if (item.sType.Equals("System.Single")) { field.SetValue(this, Convert.ToSingle(item.sValue)); } else if (item.sType.Equals("System.String")) { field.SetValue(this, item.sValue); } } } }
public void ReadXml(ref Dictionary <int, XmlDataList> dict) { #if UNITY_EDITOR if (File.Exists(m_XmlPathInEditor)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc = new XmlDocument(); xmlDoc.Load(m_XmlPathInEditor); XmlElement root = xmlDoc.SelectSingleNode(sRoot) as XmlElement; if (root == null) { return; } foreach (XmlElement xml_data in root) { if (xml_data == null) { continue; } XmlDataList _data = new XmlDataList(); _data.iIndex = Convert.ToInt32(xml_data.GetAttribute(iIndex)); _data.sDescribe = xml_data.GetAttribute(sDes); foreach (XmlElement xml_class in xml_data) { XmlClassData _class = new XmlClassData(); _class.sLogicName = xml_class.LocalName; foreach (XmlElement xml_property in xml_class) { XmlParamItem _property = new XmlParamItem(); _property.sName = xml_property.LocalName; _property.sType = xml_property.GetAttribute("Type"); _property.sValue = xml_property.InnerText; _class.Add(_property); } _data.Add(_class); } if (dict.ContainsKey(_data.iIndex)) { dict.Remove(_data.iIndex); } dict.Add(_data.iIndex, _data); } } #else string strFileCon = ResourcesProxy.LoadTextString(m_XmlFilePath); if (string.IsNullOrEmpty(strFileCon)) { return; } XmlDocument xmlDoc = new XmlDocument(); xmlDoc = new XmlDocument(); try { byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strFileCon); MemoryStream ms = new MemoryStream(buffer); xmlDoc.Load(ms); } catch (XmlException e) { Log.Debug("LoadDefine error!"); Log.Debug("line : " + e.LineNumber + " pos : " + e.LinePosition); Log.Debug("reason : " + e.Message); } XmlElement root = xmlDoc.SelectSingleNode(sRoot) as XmlElement; if (root == null) { return; } foreach (XmlElement xml_data in root) { if (xml_data == null) { continue; } XmlDataList _data = new XmlDataList(); _data.iIndex = Convert.ToInt32(xml_data.GetAttribute(iIndex)); _data.sDescribe = xml_data.GetAttribute(sDes); foreach (XmlElement xml_class in xml_data) { XmlClassData _class = new XmlClassData(); _class.sLogicName = xml_class.LocalName; foreach (XmlElement xml_property in xml_class) { XmlParamItem _property = new XmlParamItem(); _property.sName = xml_property.LocalName; _property.sType = xml_property.GetAttribute("Type"); _property.sValue = xml_property.InnerText; _class.Add(_property); } _data.Add(_class); } if (dict.ContainsKey(_data.iIndex)) { dict.Remove(_data.iIndex); } dict.Add(_data.iIndex, _data); } #endif }