示例#1
0
    public void Read(string configFile)
    {
        string configData = System.IO.File.ReadAllText(configFile);

        Jboy.JsonReader reader = new Jboy.JsonReader(configData);

        try
        {
            object         propertyName;
            Jboy.JsonToken token = Jboy.JsonToken.None;
            if (Jboy.JsonToken.ObjectStart == (token = reader.Read(out propertyName)))
            {
                while (Jboy.JsonToken.ObjectEnd != (token = reader.Read(out propertyName)))
                {
                    if (token != Jboy.JsonToken.PropertyName)
                    {
                        continue;
                    }

                    if (propertyName.Equals("ServerName"))
                    {
                        gameName = Jboy.Json.ReadObject <string>(reader);
                        continue;
                    }

                    if (propertyName.Equals("MasterRoleName"))
                    {
                        masterRoleName = Jboy.Json.ReadObject <string>(reader);
                        continue;
                    }

                    if (propertyName.Equals("Password"))
                    {
                        gamePassword = Jboy.Json.ReadObject <string>(reader);
                        continue;
                    }

                    if (propertyName.Equals("MapName"))
                    {
                        mapName = Jboy.Json.ReadObject <string>(reader);
                        continue;
                    }

                    if (propertyName.Equals("GameMode"))
                    {
                        gameMode = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("GameType"))
                    {
                        gameType = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("MapSeed"))
                    {
                        seedStr = Jboy.Json.ReadObject <string>(reader);
                        continue;
                    }

                    if (propertyName.Equals("TeamNum"))
                    {
                        teamNum = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("NumPerTeam"))
                    {
                        numPerTeam = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("TerrainType"))
                    {
                        terrainType = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("VegetationType"))
                    {
                        vegetationId = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("ClimateType"))
                    {
                        sceneClimate = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("MonsterYes"))
                    {
                        monsterYes = Jboy.Json.ReadObject <bool>(reader);
                        continue;
                    }

                    if (propertyName.Equals("IsPrivate"))
                    {
                        isPrivate = Jboy.Json.ReadObject <bool>(reader);
                        continue;
                    }

                    if (propertyName.Equals("ProxyServer"))
                    {
                        proxyServer = Jboy.Json.ReadObject <bool>(reader);
                        continue;
                    }

                    if (propertyName.Equals("UnlimitedRes"))
                    {
                        unlimitedRes = Jboy.Json.ReadObject <bool>(reader);
                        continue;
                    }

                    if (propertyName.Equals("TerrainHeight"))
                    {
                        terrainHeight = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("MapSize"))
                    {
                        mapSize = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("RiverDensity"))
                    {
                        riverDensity = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("RiverWidth"))
                    {
                        riverWidth = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    //a0.95
                    if (propertyName.Equals("PlainHeight"))
                    {
                        plainHeight = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }
                    if (propertyName.Equals("Flatness"))
                    {
                        flatness = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }
                    if (propertyName.Equals("BridgeMaxHeight"))
                    {
                        bridgeMaxHeight = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("AICount"))
                    {
                        AICount = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("UseSkillTree"))
                    {
                        useSkillTree = Jboy.Json.ReadObject <bool>(reader);
                        continue;
                    }

                    if (propertyName.Equals("DropDeadPercent"))
                    {
                        dropDeadPercent = Jboy.Json.ReadObject <int>(reader);
                        continue;
                    }

                    if (propertyName.Equals("UID"))
                    {
                        uid = Jboy.Json.ReadObject <string>(reader);
                        continue;
                    }

                    if (propertyName.Equals("ScriptsAvailable"))
                    {
                        scriptsAvailable = Jboy.Json.ReadObject <bool>(reader);
                        continue;
                    }
                }
            }
        }
        catch (Exception e)
        {
            if (LogFilter.logError)
            {
                Debug.LogErrorFormat("Read config file failed.\r\n{0}\r\n{1}\r\n{2}", configFile, e.Message, e.StackTrace);
            }
        }
        finally
        {
            reader.Close();
        }
    }