egametang启动配置

egametang的启动配置文件可以在Unity的Tools->命令行配置中修改保存然后启动

如果需要添加自定义的启动配置项目,只需要修改客户端的

ServerCommandLineEditor.cs

 1             if (GUILayout.Button("添加一行配置"))
 2             {
 3                 StartConfig newStartConfig = new StartConfig();
 4 
 5                 newStartConfig.AppType = this.AppType;
 6 
 7                 if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager))
 8                 {
 9                     newStartConfig.AddComponent<OuterConfig>();
10                 }
11 
12                 if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager | AppType.Http | AppType.DB | AppType.Map | AppType.Location))
13                 {
14                     newStartConfig.AddComponent<InnerConfig>();
15                 }
16 
17                 if (this.AppType.Is(AppType.Benchmark))
18                 {
19                     newStartConfig.AddComponent<ClientConfig>();
20                 }
21 
22                 if (this.AppType.Is(AppType.Http))
23                 {
24                     newStartConfig.AddComponent<HttpConfig>();
25                 }
26 
27                 if (this.AppType.Is(AppType.DB))
28                 {
29                     newStartConfig.AddComponent<DBConfig>();
30                 }
31 
32                 this.startConfigs.Add(newStartConfig);
33             }

这段代码里可以修改AppType对应的startconfig包含的AConfigComponent子类

 

 1                 InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
 2                 if (innerConfig != null)
 3                 {
 4                     GUILayout.Label($"InnerHost:");
 5                     innerConfig.Host = EditorGUILayout.TextField(innerConfig.Host);
 6                     GUILayout.Label($"InnerPort:");
 7                     innerConfig.Port = EditorGUILayout.IntField(innerConfig.Port);
 8                 }
 9 
10                 OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
11                 if (outerConfig != null)
12                 {
13                     GUILayout.Label($"OuterHost:");
14                     outerConfig.Host = EditorGUILayout.TextField(outerConfig.Host);
15                     GUILayout.Label($"OuterHost2:");
16                     outerConfig.Host2 = EditorGUILayout.TextField(outerConfig.Host2);
17                     GUILayout.Label($"OuterPort:");
18                     outerConfig.Port = EditorGUILayout.IntField(outerConfig.Port);
19                 }
20 
21                 ClientConfig clientConfig = startConfig.GetComponent<ClientConfig>();
22                 if (clientConfig != null)
23                 {
24                     GUILayout.Label($"Host:");
25                     clientConfig.Host = EditorGUILayout.TextField(clientConfig.Host);
26                     GUILayout.Label($"Port:");
27                     clientConfig.Port = EditorGUILayout.IntField(clientConfig.Port);
28                 }
29 
30                 HttpConfig httpConfig = startConfig.GetComponent<HttpConfig>();
31                 if (httpConfig != null)
32                 {
33                     GUILayout.Label($"AppId:");
34                     httpConfig.AppId = EditorGUILayout.IntField(httpConfig.AppId);
35                     GUILayout.Label($"AppKey:");
36                     httpConfig.AppKey = EditorGUILayout.TextField(httpConfig.AppKey);
37                     GUILayout.Label($"Url:");
38                     httpConfig.Url = EditorGUILayout.TextField(httpConfig.Url);
39                     GUILayout.Label($"ManagerSystemUrl:");
40                     httpConfig.ManagerSystemUrl = EditorGUILayout.TextField(httpConfig.ManagerSystemUrl);
41                 }
42 
43                 DBConfig dbConfig = startConfig.GetComponent<DBConfig>();
44                 if (dbConfig != null)
45                 {
46                     GUILayout.Label($"Connection:");
47                     dbConfig.ConnectionString = EditorGUILayout.TextField(dbConfig.ConnectionString);
48 
49                     GUILayout.Label($"DBName:");
50                     dbConfig.DBName = EditorGUILayout.TextField(dbConfig.DBName);
51                 }

修改这段代码即可给新增或者修改的AConfigComponent子类字段赋值

 

注意如果派生新的AConfigComponent 子类,需要再AConfigComponent上使用BsonKnownTypes标记记录上去

 1 using MongoDB.Bson.Serialization.Attributes;
 2 
 3 namespace Model
 4 {
 5     /// <summary>
 6     /// 每个Config的基类
 7     /// </summary>
 8     [BsonKnownTypes(typeof(ClientConfig))]
 9     [BsonKnownTypes(typeof(InnerConfig))]
10     [BsonKnownTypes(typeof(OuterConfig))]
11     [BsonKnownTypes(typeof(HttpConfig))]
12     [BsonKnownTypes(typeof(DBConfig))]
13     [BsonKnownTypes(typeof(RunServerConfig))]
14     public abstract class AConfigComponent: ComponentDB
15     {
16     }
17 }

 

 

 

 

点击保存后,StartConfig是个Entity,Entity的Componet容器被标记了BsonElement,所以它包含的配置组件及其内容都会序列化成json保存在配置文件夹中。从项目根目录\Config\StartConfig中即可查看这些序列化出来的json配置文件,这些配置文件还包含了_t之类的bson特有字段,和通常的newtonsoft.json序列化出来的还是有点不同。

服务端进程启动时这些序列化好的配置文件会在Program.Main函数中的OptionComponent和StartConfigComponent被反序列化 服务端需要修改StartConfigComponent加入相关代码:

 

改完上面2处就可以在代码中引用了。

posted @ 2017-10-07 18:21  FancyBit  阅读(10972)  评论(3编辑  收藏  举报