public static void LoadCfgInfo(Action <bool> callback) { #if !UNITY_WEBPLAYER string cfgStr; if (File.Exists(CfgPath)) { cfgStr = Utils.LoadFile(CfgPath); //CfgInfo = LoadXMLText<CfgInfo>(cfgStr); CfgInfoNew = LoadCfgInfoList(cfgStr); if (callback != null) { DriverLib.Invoke(() => callback(CfgInfoNew != null && CfgInfoNew.Count > 0 ? true : false)); } } else { #endif var cfgUrl = Utils.LoadResource(Utils.GetFileNameWithoutExtention(CFG_FILE)); LoggerHelper.Info("cfgUrl: " + cfgUrl); var programVerStr = ""; var programVer = Resources.Load(VERSION_URL_KEY) as TextAsset; if (programVer && !String.IsNullOrEmpty(programVer.text)) { programVerStr = "V" + VersionManager.Instance.GetVersionInXML(programVer.text).ProgramVersion; } var s = Application.persistentDataPath.Split('/'); //Debug.Log(s.Length); for (int i = s.Length - 1; i >= 0; i--) { //Debug.Log(s[i]); if (s[i] == "files" && i - 1 >= 0) { BundleIdentifier = s[i - 1]; LoggerHelper.Info("bundleIdentifier: " + BundleIdentifier); break; } } Action erraction = () => { if (callback != null) { DriverLib.Invoke(() => callback(false)); } }; Action <string> suaction = null; suaction = (res) => { var parentinfo = LoadCfgInfoList(res); foreach (var pair in parentinfo) { if (!CfgInfoNew.ContainsKey(pair.Key)) { CfgInfoNew.Add(pair.Key, pair.Value); } } if (!string.IsNullOrEmpty(BundleIdentifier) && parentinfo.ContainsKey(BundleIdentifier))//根据包名做特殊处理 { CfgInfoNew.Clear(); DownloadMgr.Instance.AsynDownLoadText(parentinfo[BundleIdentifier], suaction, erraction); } else if (parentinfo.ContainsKey(programVerStr))//根据版本做特殊处理 { CfgInfoNew.Clear(); DownloadMgr.Instance.AsynDownLoadText(parentinfo[programVerStr], suaction, erraction); } else if (parentinfo.ContainsKey(CFG_PARENT_KEY)) { DownloadMgr.Instance.AsynDownLoadText(parentinfo[CFG_PARENT_KEY], suaction, erraction); } else if (callback != null) { DriverLib.Invoke(() => callback(CfgInfoNew != null && CfgInfoNew.Count > 0 ? true : false)); } }; DownloadMgr.Instance.AsynDownLoadText(cfgUrl, suaction, erraction); #if !UNITY_WEBPLAYER } #endif }
public static Dictionary <int, Dictionary <string, string> > LoadIntMap(SecurityElement xml, string source) { Dictionary <int, Dictionary <string, string> > dictionary = new Dictionary <int, Dictionary <string, string> >(); int num = 0; foreach (SecurityElement element in xml.Children) { num++; if ((element.Children == null) || (element.Children.Count == 0)) { LoggerHelper.Warning(string.Concat(new object[] { "empty row in row NO.", num, " of ", source }), true); } else { SecurityElement element2 = element.Children[0] as SecurityElement; if (!element2.Tag.StartsWith("id")) { LoggerHelper.Error(string.Format("First element '{0}' not name as 'id_i', in {1}.", element2.Tag, source), true); } int key = int.Parse(element2.Text); if (dictionary.ContainsKey(key)) { LoggerHelper.Warning(string.Format("Key {0} already exist, in {1}.", key, source), true); } else { Dictionary <string, string> dictionary2 = new Dictionary <string, string>(); dictionary.Add(key, dictionary2); for (int i = 1; i < element.Children.Count; i++) { string tag; SecurityElement element3 = element.Children[i] as SecurityElement; if (element3.Tag.Length < 3) { tag = element3.Tag; } else { string str2 = element3.Tag.Substring(element3.Tag.Length - 2, 2); if (((((str2 == "_i") || (str2 == "_s")) || ((str2 == "_f") || (str2 == "_l"))) || (str2 == "_k")) || (str2 == "_m")) { tag = element3.Tag.Substring(0, element3.Tag.Length - 2); } else { tag = element3.Tag; } } if ((element3 != null) && !dictionary2.ContainsKey(tag)) { if (string.IsNullOrEmpty(element3.Text)) { dictionary2.Add(tag, ""); } else { dictionary2.Add(tag, element3.Text.Trim()); } } else { LoggerHelper.Warning(string.Format("Key {0} already exist, index {1} of {2}.", element3.Tag, i, element3.ToString()), true); } } } } } return(dictionary); }
/// <summary> /// 从指定的 XML 文档加载 map 数据。 /// </summary> /// <param name="xml">XML 文档</param> /// <returns>map 数据</returns> public static Dictionary <Int32, Dictionary <String, String> > LoadIntMap(SecurityElement xml, string source) { var result = new Dictionary <Int32, Dictionary <String, String> >(); var index = 0; foreach (SecurityElement subMap in xml.Children) { index++; if (subMap.Children == null || subMap.Children.Count == 0) { LoggerHelper.Warning("empty row in row NO." + index + " of " + source); continue; } Int32 key = Int32.Parse((subMap.Children[0] as SecurityElement).Text); if (result.ContainsKey(key)) { LoggerHelper.Warning(String.Format("Key {0} already exist, in {1}.", key, source)); continue; } var children = new Dictionary <String, String>(); result.Add(key, children); for (int i = 1; i < subMap.Children.Count; i++) { var node = subMap.Children[i] as SecurityElement; //对属性名称部分后缀进行裁剪 string tag; if (node.Tag.Length < 3) { tag = node.Tag; } else { var tagTial = node.Tag.Substring(node.Tag.Length - 2, 2); if (tagTial == "_i" || tagTial == "_s" || tagTial == "_f" || tagTial == "_l" || tagTial == "_k" || tagTial == "_m") { tag = node.Tag.Substring(0, node.Tag.Length - 2); } else { tag = node.Tag; } } if (node != null && !children.ContainsKey(tag)) { if (String.IsNullOrEmpty(node.Text)) { children.Add(tag, ""); } else { children.Add(tag, node.Text.Trim()); } } else { LoggerHelper.Warning(String.Format("Key {0} already exist, index {1} of {2}.", node.Tag, i, node.ToString())); } } } return(result); }