private static void InitDict(string path) { _rootBehavior = null; _behaviorDict.Clear(); _connectionDict.Clear(); TextAsset json = Resources.Load <TextAsset>(path); string content = json.text.Replace("\r", "").Replace("\n", ""); Hashtable table = MiniJsonExtensions.hashtableFromJson(content); ArrayList nodeList = table["nodes"] as ArrayList; ArrayList connectionList = table["connections"] as ArrayList; for (int i = 0; i < nodeList.Count; i++) { Hashtable nodeTable = nodeList[i] as Hashtable; var id = 0; if (int.TryParse(nodeTable["$id"].ToString(), out id)) { AbsBehavior absBehavior = CreateBehavior(nodeTable, id); _behaviorDict[id] = absBehavior; if (_rootBehavior == null) { _rootBehavior = absBehavior; } else { if (absBehavior.Id < _rootBehavior.Id) { _rootBehavior = absBehavior; } } } else { LogHelper.PrintError("[BehaviorTreeFactory]try get node id error!"); } } for (int i = 0; i < connectionList.Count; i++) { Hashtable connectionTable = connectionList[i] as Hashtable; int source = 0; int target = 0; Hashtable scurceNode = connectionTable["_sourceNode"] as Hashtable; Hashtable targetNode = connectionTable["_targetNode"] as Hashtable; if (int.TryParse(scurceNode["$ref"].ToString(), out source) && int.TryParse(targetNode["$ref"].ToString(), out target)) { List <int> list; if (!_connectionDict.TryGetValue(source, out list)) { _connectionDict[source] = new List <int>(); list = _connectionDict[source]; } list.Add(target); } else { LogHelper.PrintError("[BehaviorTreeFactory]try get source id and target id error!"); } } }
private static void ReadConfig(string path) { _behaviorDict.Clear(); _connectionDict.Clear(); TextAsset json = Resources.Load <TextAsset>(path); string content = json.text.Replace("\r", "").Replace("\n", ""); Hashtable table = MiniJsonExtensions.hashtableFromJson(content); object nodes = table["nodes"]; }
/// <summary> /// This will be called by ConfigMachine manager automatically. /// If you called this directly, also call <see cref="ShowConfig"/> to apply them in UI. /// </summary> internal bool LoadConfig() { config = new Dictionary <string, string>(); rawConfig = rawConfigDef; if (!Configuable()) { return(true); } if (this is GeneratedOI && (this as GeneratedOI).mode == GeneratedOI.GenMode.BepInExConfig) { return((this as GeneratedOI).LoadBepConfig()); } if (!directory.Exists) { return(false); } //directory.Create(); string path = string.Concat(directory.FullName, "config.json"); if (File.Exists(path)) { this.rawConfig = File.ReadAllText(path, Encoding.UTF8); } else { return(false); } Dictionary <string, object> loadedConfig = MiniJsonExtensions.dictionaryFromJson(this.rawConfig); foreach (KeyValuePair <string, object> item in loadedConfig) { config.Add(item.Key, item.Value.ToString()); } try { ConfigOnChange(); } catch (Exception e) { Debug.Log("CompletelyOptional) Lost backward compatibility in Config! Reset Config."); Debug.Log(new LoadDataException(e.ToString())); File.Delete(path); config = new Dictionary <string, string>(); rawConfig = rawConfigDef; return(false); } return(true); }
public GameInfo(string rawJSON) { Hashtable gameInfo = MiniJsonExtensions.hashtableFromJson(rawJSON); Debug.Log("gameInfo Hashtable contains key games: " + gameInfo.ContainsKey("games")); ArrayList games = gameInfo["games"] as ArrayList; Debug.Log("Length of game array: " + games.Count); foreach (Hashtable hash in games) { Game game = new Game(hash); currentGames[game.name] = game; } }
/// <summary> /// Saving Config. It's called automatically. /// </summary> internal bool SaveConfig(Dictionary <string, string> newConfig) { if (!Configuable()) { return(true); } if (this is GeneratedOI && (this as GeneratedOI).mode == GeneratedOI.GenMode.BepInExConfig) { return((this as GeneratedOI).SaveBepConfig(newConfig)); } // Saving config is handled by BepInEx if (newConfig.Count < 1) { return(false); } //Nothing to Save. config = newConfig; if (!directory.Exists) { directory.Create(); } ConfigOnChange(); //Write in file try { string path = string.Concat(directory.FullName, "config.json"); Dictionary <string, object> temp = new Dictionary <string, object>(); foreach (KeyValuePair <string, string> item in newConfig) { temp.Add(item.Key, item.Value); } rawConfig = MiniJsonExtensions.toJson(temp); // Formatting rawConfig = rawConfig.Replace("{", "{\n "); rawConfig = rawConfig.Replace("}", "\n}"); rawConfig = rawConfig.Replace("\",\"", "\",\n \""); rawConfig = rawConfig.Replace("\":\"", "\" : \""); File.WriteAllText(path, this.rawConfig, Encoding.UTF8); return(true); } catch (Exception ex) { Debug.LogException(new SaveDataException(ex.ToString())); } return(false); }
/// <summary> /// 获取产品详细信息 /// </summary> /// <param name="productId"></param> /// <returns></returns> private Hashtable getProductDetail(string productId) { string text = httpPost("https://msdn.itellyou.cn/Category/GetProduct", string.Format("id={0}", productId)); return(MiniJsonExtensions.hashtableFromJson(text)); }
/// <summary> /// 获取产品列表 /// </summary> /// <param name="typeId"></param> /// <param name="lang"></param> /// <returns></returns> private Hashtable getProductList(string typeId, string lang) { string text = httpPost("https://msdn.itellyou.cn/Category/GetList", string.Format("id={0}&lang={1}&filter=true", typeId, lang)); return(MiniJsonExtensions.hashtableFromJson(text)); }
/// <summary> /// 获取产品系列的语言列表 /// </summary> /// <param name="typeId">资源类型id</param> /// <returns>多国语言、英语、中文 - 简体、中文 - 繁体...</returns> private Hashtable getLangList(string typeId) { string text = httpPost("https://msdn.itellyou.cn/Category/GetLang", string.Format("id={0}", typeId)); return(MiniJsonExtensions.hashtableFromJson(text)); }
/// <summary> /// 获取产品系列列表 /// </summary> /// <param name="cateId">分类id</param> /// <returns>win7、win8、win10...</returns> private ArrayList getSeriesList(string cateId) { string text = httpPost("https://msdn.itellyou.cn/Category/Index", string.Format("id={0}", cateId)); return(MiniJsonExtensions.arrayListFromJson(text)); }