using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Xml; namespace JC.Unity.Picker { public class LocationParseComponent : MonoBehaviour { [SerializeField] TextAsset xmlFileText; LocationParser locationParser; public static LocationParseComponent ins; void Awake() { ins = this; locationParser = new LocationParser(xmlFileText); } void OnDestroy() { if (ins == this) ins = null; } public Tuple ParseNameByCode(string countryCode, string stateCode, string cityCode) { string countryName = ""; string stateName = ""; string cityName = ""; XmlNodeList stateNodeList = null; XmlNodeList cityNodeList = null; foreach (var countryNode in locationParser.CountryRegionList) { if (countryNode.Attributes["Code"].Value == countryCode) { countryName = countryNode.Attributes["Name"].Value; stateNodeList = countryNode.SelectNodes("State"); break; } } if (stateNodeList != null) { for (int i = 0; i < stateNodeList.Count; i++) { XmlNode stateNode = stateNodeList[i]; XmlAttribute CodeAtb = stateNode.Attributes["Code"]; if (CodeAtb != null) { if (stateCode == CodeAtb.Value) { XmlAttribute NameAtb = stateNode.Attributes["Name"]; if (NameAtb != null) { stateName = NameAtb.Value; cityNodeList = stateNode.SelectNodes("City"); break; } } } else if (CodeAtb == null && string.IsNullOrEmpty(stateCode)) { cityNodeList = stateNode.SelectNodes("City"); break; } } } if (cityNodeList != null) { for (int i = 0; i < cityNodeList.Count; i++) { XmlNode cityNode = cityNodeList[i]; XmlAttribute CodeAtb = cityNode.Attributes["Code"]; if (CodeAtb != null) { if (cityCode == CodeAtb.Value) { XmlAttribute NameAtb = cityNode.Attributes["Name"]; if (NameAtb != null) { cityName = NameAtb.Value; break; } } } } } return new Tuple(countryName, stateName, cityName); } } }