提交 d4a1ee58 编写于 作者: T tanghai

配置文件都改成了组件式

上级 730f54dd
......@@ -47,6 +47,15 @@
<Compile Include="..\..\Unity\Assets\Scripts\Component\ConfigComponent.cs">
<Link>Component\ConfigComponent.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Component\Config\ClientConfig.cs">
<Link>Component\Config\ClientConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Component\Config\InnerConfig.cs">
<Link>Component\Config\InnerConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Component\Config\OuterConfig.cs">
<Link>Component\Config\OuterConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Component\EventComponent.cs">
<Link>Component\EventComponent.cs</Link>
</Compile>
......@@ -83,9 +92,18 @@
<Compile Include="..\..\Unity\Assets\Scripts\Config\ICategory.cs">
<Link>Config\ICategory.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Entity\Config\BuffConfig.cs">
<Link>Entity\Config\BuffConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Entity\Config\StartConfig.cs">
<Link>Entity\Config\StartConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Entity\Game.cs">
<Link>Entity\Game.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\Message.cs">
<Link>Entity\Message\Message.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Entity\Scene.cs">
<Link>Entity\Scene.cs</Link>
</Compile>
......@@ -137,27 +155,15 @@
<Compile Include="..\..\Unity\Assets\Scripts\Message\RpcException.cs">
<Link>Message\RpcException.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Model\Config\BuffConfig.cs">
<Link>Model\Config\BuffConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Model\Message\Message.cs">
<Link>Model\Message\Message.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\BsonClassMapRegister.cs">
<Link>Other\BsonClassMapRegister.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\ClientConfig.cs">
<Link>Other\ClientConfig.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\EntityType.cs">
<Link>Other\EntityType.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\Options.cs">
<Link>Other\Options.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\StartConfig.cs">
<Link>Other\StartConfig.cs</Link>
</Compile>
<Compile Include="Component\AppManagerComponent.cs" />
<Compile Include="Component\LogToClientComponent.cs" />
<Compile Include="Component\GateSessionKeyComponent.cs" />
......
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO;
using Base;
using Model;
using UnityEditor;
......@@ -11,9 +8,9 @@ namespace MyEditor
{
public class ClientConfigEditor : EditorWindow
{
private const string Path = "./ClientConfig.txt";
private const string Path = "./StartConfig.txt";
private ClientConfig config;
private StartConfig config;
[MenuItem("Tools/客户端配置")]
private static void ShowWindow()
......@@ -25,21 +22,23 @@ namespace MyEditor
{
if (!File.Exists(Path))
{
this.config = new ClientConfig();
this.config = new StartConfig();
this.config.AppType = AppType.Client;
this.config.ServerIP = "*";
this.config.AddComponent<ClientConfig>();
return;
}
string s = File.ReadAllText(Path);
this.config = MongoHelper.FromJson<ClientConfig>(s);
this.config = MongoHelper.FromJson<StartConfig>(s);
}
private void OnGUI()
{
this.config.Host = EditorGUILayout.TextField("地址: ", this.config.Host);
this.config.Port = EditorGUILayout.IntField("端口: ", this.config.Port);
GUILayout.BeginHorizontal();
ClientConfig clientConfig = this.config.GetComponent<ClientConfig>();
clientConfig.Host = EditorGUILayout.TextField("地址: ", clientConfig.Host);
clientConfig.Port = EditorGUILayout.IntField("端口: ", clientConfig.Port);
if (GUILayout.Button("保存"))
{
using (StreamWriter sw = new StreamWriter(new FileStream(Path, FileMode.Create)))
......
......@@ -14,12 +14,24 @@ namespace Model
public class ClientConfigComponent : Component
{
public ClientConfig Config { get; private set; }
public StartConfig Config { get; private set; }
public void Awake()
{
string s = File.ReadAllText("./ClientConfig.txt");
this.Config = MongoHelper.FromJson<ClientConfig>(s);
string s = File.ReadAllText("./StartConfig.txt");
this.Config = MongoHelper.FromJson<StartConfig>(s);
}
public override void Dispose()
{
if (this.Id == 0)
{
return;
}
base.Dispose();
this.Config.Dispose();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: a7ca76f312d51e7469f7578030024db0
guid: e98bd4118f88e1c428e3af0983722aa8
folderAsset: yes
timeCreated: 1477905041
timeCreated: 1478144281
licenseType: Pro
DefaultImporter:
userData:
......
fileFormatVersion: 2
guid: 500eb7f5c0a52e045a339f55912f8a2b
timeCreated: 1477315494
guid: befeb8cfbdbfc5b4ea5f967c200d4751
timeCreated: 1478144281
licenseType: Pro
MonoImporter:
serializedVersion: 2
......
using Base;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class InnerConfig : Component
{
public string Host { get; set; }
public int Port { get; set; }
[BsonIgnore]
public string Address
{
get
{
return $"{this.Host}:{this.Port}";
}
}
}
}
fileFormatVersion: 2
guid: 35f166fd86ee5e44aaec9326bb0a5454
timeCreated: 1478144281
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Base;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class OuterConfig : Component
{
public string Host { get; set; }
public int Port { get; set; }
[BsonIgnore]
public string Address
{
get
{
return $"{this.Host}:{this.Port}";
}
}
}
}
fileFormatVersion: 2
guid: 31224cfdac2f28c42bd641d5a2e80fe8
timeCreated: 1478144281
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.ComponentModel;
using MongoDB.Bson.Serialization.Attributes;
using Base;
namespace Model
{
/// <summary>
/// 每个Config的基类
/// </summary>
public abstract class AConfig: ISupportInitialize
public abstract class AConfig: Entity
{
[BsonId]
public long Id { get; set; }
public virtual void BeginInit()
public AConfig(string entityType): base(entityType)
{
}
public virtual void EndInit()
public AConfig(long id, string entityType): base(id, entityType)
{
}
}
......
......@@ -7,7 +7,15 @@ namespace Model
{
public string Name { get; set; }
public int Time { get; set; }
}
public BuffConfig(): base(EntityType.BuffConfig)
{
}
public BuffConfig(long id): base(id, EntityType.BuffConfig)
{
}
}
[Config(AppType.Client | AppType.Gate)]
public class BuffCategory : ACategory<BuffConfig>
......
......@@ -4,7 +4,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
public class StartConfig: Entity
public class StartConfig: AConfig
{
public int AppId { get; set; }
......
......@@ -8,5 +8,8 @@
public const string UI = "UI";
public const string Config = "Config";
public const string Network = "Network";
// Config
public const string BuffConfig = "BuffConfig";
}
}
\ No newline at end of file
......@@ -29,36 +29,4 @@ namespace Model
return MongoHelper.FromBson<Options>(MongoHelper.ToBson(this));
}
}
[BsonIgnoreExtraElements]
public class InnerConfig: Component
{
public string Host { get; set; }
public int Port { get; set; }
[BsonIgnore]
public string Address
{
get
{
return $"{this.Host}:{this.Port}";
}
}
}
[BsonIgnoreExtraElements]
public class OuterConfig: Component
{
public string Host { get; set; }
public int Port { get; set; }
[BsonIgnore]
public string Address
{
get
{
return $"{this.Host}:{this.Port}";
}
}
}
}
\ No newline at end of file
{ "_t" : "ClientConfig", "Host" : "127.0.0.1", "Port" : 10000 }
\ No newline at end of file
......@@ -13,7 +13,7 @@ namespace Controller
public async void Run()
{
Game.Scene.AddComponent<MessageDispatherComponent, AppType>(AppType.Client);
ClientConfig clientConfig = Game.Scene.AddComponent<ClientConfigComponent>().Config;
ClientConfig clientConfig = Game.Scene.AddComponent<ClientConfigComponent>().Config.GetComponent<ClientConfig>();
NetOuterComponent networkComponent = Game.Scene.AddComponent<NetOuterComponent>();
using (Session session = networkComponent.Create(clientConfig.Address))
{
......
{ "_t" : "StartConfig", "_id" : NumberLong("96871590002689"), "Type" : "Config", "components" : [{ "_t" : "ClientConfig", "_id" : NumberLong("96871590002690"), "Host" : "127.0.0.1", "Port" : 10000 }], "AppId" : 0, "AppType" : "None", "ServerIP" : null }
\ No newline at end of file
......@@ -83,6 +83,9 @@
<Compile Include="Assets\Scripts\Component\ChildrenComponent.cs" />
<Compile Include="Assets\Scripts\Component\ClientConfigComponent.cs" />
<Compile Include="Assets\Scripts\Component\ConfigComponent.cs" />
<Compile Include="Assets\Scripts\Component\Config\OuterConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\InnerConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\ClientConfig.cs" />
<Compile Include="Assets\Scripts\Component\EventComponent.cs" />
<Compile Include="Assets\Scripts\Component\GameObjectComponent.cs" />
<Compile Include="Assets\Scripts\Component\KVComponent.cs" />
......@@ -120,14 +123,13 @@
<Compile Include="Assets\Scripts\Message\MessageHandlerAttribute.cs" />
<Compile Include="Assets\Scripts\Message\OpcodeHelper.cs" />
<Compile Include="Assets\Scripts\Message\RpcException.cs" />
<Compile Include="Assets\Scripts\Model\Config\BuffConfig.cs" />
<Compile Include="Assets\Scripts\Model\Message\Message.cs" />
<Compile Include="Assets\Scripts\Entity\Config\BuffConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Message\Message.cs" />
<Compile Include="Assets\Scripts\Other\BsonClassMapRegister.cs" />
<Compile Include="Assets\Scripts\Other\ClientConfig.cs" />
<Compile Include="Assets\Scripts\Other\EntityType.cs" />
<Compile Include="Assets\Scripts\Other\GameException.cs" />
<Compile Include="Assets\Scripts\Other\Options.cs" />
<Compile Include="Assets\Scripts\Other\StartConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Config\StartConfig.cs" />
<Compile Include="Assets\Scripts\Other\UIType.cs" />
<Compile Include="Assets\Scripts\ReferenceCollector.cs" />
</ItemGroup>
......@@ -135,5 +137,6 @@
<None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\AsyncBridge.Net35.xml" />
<None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册