Przeglądaj źródła

Entity改成可以继承,代码会简单很多

tanghai 9 lat temu
rodzic
commit
754275d47f
51 zmienionych plików z 258 dodań i 232 usunięć
  1. 7 7
      Server/App/Program.cs
  2. 5 5
      Server/App/Start.txt
  3. 0 21
      Server/Base/Server.Base.csproj
  4. 1 1
      Server/Controller/Message/C2G_LoginGateHandler.cs
  5. 5 5
      Server/Controller/Message/C2M_ReloadHandler.cs
  6. 3 3
      Server/Controller/Message/C2R_LoginHandler.cs
  7. 1 1
      Server/Controller/Message/C2R_SubscribeLogHandler.cs
  8. 2 2
      Server/Controller/Message/M2A_ReloadHandler.cs
  9. 1 1
      Server/Controller/Message/R2G_GetLoginKeyHandler.cs
  10. 4 4
      Server/Model/Component/AppManagerComponent.cs
  11. 3 3
      Server/Model/Component/LogToClientComponent.cs
  12. 3 3
      Server/Model/Component/RealmGateAddressComponent.cs
  13. 1 2
      Server/Model/Component/StartConfigComponent.cs
  14. 27 3
      Server/Model/Server.Model.csproj
  15. 2 2
      Unity/Assets/Editor/ServerCommandLineEditor/Component.meta
  16. 12 12
      Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs
  17. 2 2
      Unity/Assets/Editor/ServerManagerEditor/ServerManagerEditor.cs
  18. 0 26
      Unity/Assets/Plugins/Base/Game.cs
  19. 7 2
      Unity/Assets/Plugins/Base/Object/Component.cs
  20. 3 4
      Unity/Assets/Plugins/Base/Object/Entity.cs
  21. 17 17
      Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
  22. 14 16
      Unity/Assets/Scripts/Component/NetworkComponent.cs
  23. 9 0
      Unity/Assets/Scripts/Entity.meta
  24. 24 0
      Unity/Assets/Scripts/Entity/Game.cs
  25. 2 2
      Unity/Assets/Scripts/Entity/Game.cs.meta
  26. 9 1
      Unity/Assets/Scripts/Entity/Scene.cs
  27. 0 0
      Unity/Assets/Scripts/Entity/Scene.cs.meta
  28. 20 34
      Unity/Assets/Scripts/Entity/Session.cs
  29. 2 2
      Unity/Assets/Scripts/Entity/Session.cs.meta
  30. 9 1
      Unity/Assets/Scripts/Entity/UI.cs
  31. 0 0
      Unity/Assets/Scripts/Entity/UI.cs.meta
  32. 4 3
      Unity/Assets/Scripts/Message/AMEvent.cs
  33. 2 2
      Unity/Assets/Scripts/Message/AMEvent.cs.meta
  34. 1 1
      Unity/Assets/Scripts/Message/AMessage.cs
  35. 2 2
      Unity/Assets/Scripts/Message/AMessage.cs.meta
  36. 5 3
      Unity/Assets/Scripts/Message/IMRegister.cs
  37. 2 2
      Unity/Assets/Scripts/Message/IMRegister.cs.meta
  38. 1 1
      Unity/Assets/Scripts/Message/MessageAttribute.cs
  39. 2 2
      Unity/Assets/Scripts/Message/MessageAttribute.cs.meta
  40. 1 1
      Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs
  41. 2 2
      Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs.meta
  42. 1 1
      Unity/Assets/Scripts/Message/RpcException.cs
  43. 2 2
      Unity/Assets/Scripts/Message/RpcException.cs.meta
  44. 12 1
      Unity/Assets/Scripts/Other/ClientConfig.cs
  45. 3 0
      Unity/Assets/Scripts/Other/EntityType.cs
  46. 5 7
      Unity/Assets/Scripts/Other/StartConfig.cs
  47. 1 1
      Unity/ClientConfig.txt
  48. 4 4
      Unity/Controller/Event/InitSceneStartEvent_InitGame.cs
  49. 1 1
      Unity/Controller/Message/R2C_ServerLogHandler.cs
  50. 2 11
      Unity/Unity.CSharp.Plugins.csproj
  51. 10 3
      Unity/Unity.CSharp.csproj

+ 7 - 7
Server/App/Program.cs

@@ -20,21 +20,21 @@ namespace App
 
 				StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string[]>(args).MyConfig;
 
-				LogManager.Configuration.Variables["appType"] = startConfig.Options.AppType;
-				LogManager.Configuration.Variables["appId"] = startConfig.Options.Id.ToString();
+				LogManager.Configuration.Variables["appType"] = startConfig.AppType;
+				LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString();
 
 				Log.Info("server start........................");
 
 				Game.Scene.AddComponent<EventComponent>();
 				Game.Scene.AddComponent<TimerComponent>();
 
-				InnerConfig innerConfig = startConfig.Config.GetComponent<InnerConfig>();
+				InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
 				Game.Scene.AddComponent<NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port);
-				Game.Scene.AddComponent<MessageDispatherComponent, string>(startConfig.Options.AppType);
+				Game.Scene.AddComponent<MessageDispatherComponent, string>(startConfig.AppType);
 
 				// 根据不同的AppType添加不同的组件
-				OuterConfig outerConfig = startConfig.Config.GetComponent<OuterConfig>();
-				switch (startConfig.Options.AppType)
+				OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
+				switch (startConfig.AppType)
 				{
 					case AppType.Manager:
 						Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
@@ -49,7 +49,7 @@ namespace App
 						Game.Scene.AddComponent<GateSessionKeyComponent>();
 						break;
 					default:
-						throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.Options.AppType}");
+						throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
 				}
 
 				while (true)

+ 5 - 5
Server/App/Start.txt

@@ -1,5 +1,5 @@
-{ "_t" : "StartConfig", "Options" : { "_id" : 1, "AppType" : "Manager" }, "IP" : "*", "Config" : { "_id" : NumberLong("9223372036854775804"), "Type" : "StartConfig", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10000 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775802"), "Host" : "192.168.12.188", "Port" : 10001 }] } }
-{ "_t" : "StartConfig", "Options" : { "_id" : 2, "AppType" : "Realm" }, "IP" : "*", "Config" : { "_id" : NumberLong("9223372036854775804"), "Type" : "StartConfig", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10002 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775802"), "Host" : "192.168.12.188", "Port" : 10003 }] } }
-{ "_t" : "StartConfig", "Options" : { "_id" : 3, "AppType" : "Gate" }, "IP" : "*", "Config" : { "_id" : NumberLong("9223372036854775804"), "Type" : "StartConfig", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10004 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775802"), "Host" : "192.168.12.188", "Port" : 10005 }] } }
-{ "_t" : "StartConfig", "Options" : { "_id" : 4, "AppType" : "Gate" }, "IP" : "*", "Config" : { "_id" : NumberLong("9223372036854775804"), "Type" : "StartConfig", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10006 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775802"), "Host" : "192.168.12.188", "Port" : 10007 }] } }
-{ "_t" : "StartConfig", "Options" : { "_id" : 5, "AppType" : "Gate" }, "IP" : "*", "Config" : { "_id" : NumberLong("9223372036854775804"), "Type" : "StartConfig", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10008 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775802"), "Host" : "192.168.12.188", "Port" : 10009 }] } }
+{ "_t" : "StartConfig", "_id" : NumberLong("9223372036854775805"), "Type" : "Config", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775804"), "Host" : "192.168.12.188", "Port" : 20000 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10000 }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("9223372036854775805"), "Type" : "Config", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775804"), "Host" : "192.168.12.188", "Port" : 20001 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10001 }], "AppId" : 2, "AppType" : "Realm", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("9223372036854775805"), "Type" : "Config", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775804"), "Host" : "192.168.12.188", "Port" : 20002 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10002 }], "AppId" : 3, "AppType" : "Gate", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("9223372036854775805"), "Type" : "Config", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775804"), "Host" : "192.168.12.188", "Port" : 20003 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10003 }], "AppId" : 4, "AppType" : "Gate", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("9223372036854775805"), "Type" : "Config", "components" : [{ "_t" : "InnerConfig", "_id" : NumberLong("9223372036854775804"), "Host" : "192.168.12.188", "Port" : 20004 }, { "_t" : "OuterConfig", "_id" : NumberLong("9223372036854775803"), "Host" : "192.168.12.188", "Port" : 10004 }], "AppId" : 5, "AppType" : "Gate", "ServerIP" : "*" }

+ 0 - 21
Server/Base/Server.Base.csproj

@@ -80,9 +80,6 @@
     <Compile Include="..\..\Unity\Assets\Plugins\Base\Event\IEvent.cs">
       <Link>Event\IEvent.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Plugins\Base\Game.cs">
-      <Link>Game.cs</Link>
-    </Compile>
     <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\ArrayHelper.cs">
       <Link>Helper\ArrayHelper.cs</Link>
     </Compile>
@@ -125,24 +122,6 @@
     <Compile Include="..\..\Unity\Assets\Plugins\Base\LogType.cs">
       <Link>LogType.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\AMessage.cs">
-      <Link>Message\AMessage.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\AMEvent.cs">
-      <Link>Message\AMEvent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\IMRegister.cs">
-      <Link>Message\IMRegister.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\MessageAttribute.cs">
-      <Link>Message\MessageAttribute.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\MessageHandlerAttribute.cs">
-      <Link>Message\MessageHandlerAttribute.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\RpcException.cs">
-      <Link>Message\RpcException.cs</Link>
-    </Compile>
     <Compile Include="..\..\Unity\Assets\Plugins\Base\MultiMap.cs">
       <Link>MultiMap.cs</Link>
     </Compile>

+ 1 - 1
Server/Controller/Message/C2G_LoginGateHandler.cs

@@ -7,7 +7,7 @@ namespace Controller
 	[MessageHandler(AppType.Gate)]
 	public class C2G_LoginGateHandler : AMRpcEvent<C2G_LoginGate, G2C_LoginGate>
 	{
-		protected override void Run(Entity scene, C2G_LoginGate message, Action<G2C_LoginGate> reply)
+		protected override void Run(Session session, C2G_LoginGate message, Action<G2C_LoginGate> reply)
 		{
 			bool isCheckOK = Game.Scene.GetComponent<GateSessionKeyComponent>().Check(message.Key);
 			G2C_LoginGate g2CLoginGate = new G2C_LoginGate();

+ 5 - 5
Server/Controller/Message/C2M_ReloadHandler.cs

@@ -7,7 +7,7 @@ namespace Controller
 	[MessageHandler(AppType.Manager)]
 	public class C2M_ReloadHandler: AMRpcEvent<C2M_Reload, M2C_Reload>
 	{
-		protected override async void Run(Entity session, C2M_Reload message, Action<M2C_Reload> reply)
+		protected override async void Run(Session session, C2M_Reload message, Action<M2C_Reload> reply)
 		{
 			M2C_Reload m2CReload = new M2C_Reload();
 			try
@@ -16,13 +16,13 @@ namespace Controller
 				NetInnerComponent netInnerComponent = Game.Scene.GetComponent<NetInnerComponent>();
 				foreach (StartConfig startConfig in startConfigComponent.GetAll())
 				{
-					if (!message.AppType.Contains(startConfig.Options.AppType))
+					if (!message.AppType.Contains(startConfig.AppType))
 					{
 						continue;
 					}
-					InnerConfig innerConfig = startConfig.Config.GetComponent<InnerConfig>();
-					Entity serverSession = netInnerComponent.Get(innerConfig.Address);
-					await serverSession.GetComponent<MessageComponent>().Call<M2A_Reload, A2M_Reload>(new M2A_Reload());
+					InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
+					Session serverSession = netInnerComponent.Get(innerConfig.Address);
+					await serverSession.Call<M2A_Reload, A2M_Reload>(new M2A_Reload());
 				}
 			}
 			catch (Exception e)

+ 3 - 3
Server/Controller/Message/C2R_LoginHandler.cs

@@ -7,7 +7,7 @@ namespace Controller
 	[MessageHandler(AppType.Realm)]
 	public class C2R_LoginHandler: AMRpcEvent<C2R_Login, R2C_Login>
 	{
-		protected override async void Run(Entity session, C2R_Login message, Action<R2C_Login> reply)
+		protected override async void Run(Session session, C2R_Login message, Action<R2C_Login> reply)
 		{
 			R2C_Login r2CLogin;
 			if (message.Account != "abcdef" || message.Password != "111111")
@@ -21,10 +21,10 @@ namespace Controller
 			Entity config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
 			Log.Info($"gate address: {MongoHelper.ToJson(config)}");
 			string innerAddress = $"{config.GetComponent<InnerConfig>().Host}:{config.GetComponent<InnerConfig>().Port}";
-			Entity gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
+			Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
 			
 			// 向gate请求一个key,客户端可以拿着这个key连接gate
-			G2R_GetLoginKey g2RGetLoginKey = await gateSession.GetComponent<MessageComponent>().Call<R2G_GetLoginKey, G2R_GetLoginKey>(new R2G_GetLoginKey());
+			G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call<R2G_GetLoginKey, G2R_GetLoginKey>(new R2G_GetLoginKey());
 			
 			string outerAddress = $"{config.GetComponent<OuterConfig>().Host}:{config.GetComponent<OuterConfig>().Port}";
 			r2CLogin = new R2C_Login {Address = outerAddress, Key = g2RGetLoginKey.Key};

+ 1 - 1
Server/Controller/Message/C2R_SubscribeLogHandler.cs

@@ -7,7 +7,7 @@ namespace Controller
 	[MessageHandler(AppType.Realm)]
 	public class C2R_SubscribeLogHandler : AMRpcEvent<C2R_SubscribeLog, R2C_SubscribeLog>
 	{
-		protected override void Run(Entity entity, C2R_SubscribeLog message, Action<R2C_SubscribeLog> reply)
+		protected override void Run(Session session, C2R_SubscribeLog message, Action<R2C_SubscribeLog> reply)
 		{
 			Log.Info(MongoHelper.ToJson(message));
 

+ 2 - 2
Server/Controller/Message/M2A_ReloadHandler.cs

@@ -8,7 +8,7 @@ namespace Controller
 	[MessageHandler(AppType.Manager, AppType.Realm, AppType.Gate)]
 	public class M2A_ReloadHandler : AMRpcEvent<M2A_Reload, A2M_Reload>
 	{
-		protected override void Run(Entity session, M2A_Reload message, Action<A2M_Reload> reply)
+		protected override void Run(Session session, M2A_Reload message, Action<A2M_Reload> reply)
 		{
 			A2M_Reload a2MReload = new A2M_Reload();
 			try
@@ -19,7 +19,7 @@ namespace Controller
 			{
 				a2MReload.Error = ErrorCode.ERR_ReloadFail;
 				StartConfig myStartConfig = Game.Scene.GetComponent<StartConfigComponent>().MyConfig;
-				InnerConfig innerConfig = myStartConfig.Config.GetComponent<InnerConfig>();
+				InnerConfig innerConfig = myStartConfig.GetComponent<InnerConfig>();
 				a2MReload.Message = $"{innerConfig.Address} reload fail, {e}";
 			}
 			reply(a2MReload);

+ 1 - 1
Server/Controller/Message/R2G_GetLoginKeyHandler.cs

@@ -7,7 +7,7 @@ namespace Controller
 	[MessageHandler(AppType.Gate)]
 	public class R2G_GetLoginKeyHandler : AMRpcEvent<R2G_GetLoginKey, G2R_GetLoginKey>
 	{
-		protected override void Run(Entity scene, R2G_GetLoginKey message, Action<G2R_GetLoginKey> reply)
+		protected override void Run(Session session, R2G_GetLoginKey message, Action<G2R_GetLoginKey> reply)
 		{
 			long key = Game.Scene.GetComponent<GateSessionKeyComponent>().Get();
 			G2R_GetLoginKey g2RGetLoginKey = new G2R_GetLoginKey(key);

+ 4 - 4
Server/Model/Component/AppManagerComponent.cs

@@ -26,12 +26,12 @@ namespace Model
 			StartConfig[] startConfigs = Game.Scene.GetComponent<StartConfigComponent>().GetAll();
 			foreach (StartConfig startConfig in startConfigs)
 			{
-				if (!ips.Contains(startConfig.IP) && startConfig.IP != "*")
+				if (!ips.Contains(startConfig.ServerIP) && startConfig.ServerIP != "*")
 				{
 					continue;
 				}
 
-				if (startConfig.Options.AppType == AppType.Manager)
+				if (startConfig.AppType == AppType.Manager)
 				{
 					continue;
 				}
@@ -39,10 +39,10 @@ namespace Model
 
 #if __MonoCS__
 				const string exe = @"mono";
-				string arguments = $"--debug App.exe --id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
+				string arguments = $"--debug App.exe --id={startConfig.AppId} --appType={startConfig.AppType}";
 #else
 				const string exe = @"App.exe";
-				string arguments = $"--id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
+				string arguments = $"--id={startConfig.AppId} --appType={startConfig.AppType}";
 #endif
 
 				Log.Info($"{exe} {arguments}");

+ 3 - 3
Server/Model/Component/LogToClientComponent.cs

@@ -18,8 +18,8 @@ namespace Model
 
 		public void Awake()
 		{
-			this.appType = Game.Scene.GetComponent<StartConfigComponent>().MyConfig.Options.AppType;
-			this.appId = Game.Scene.GetComponent<StartConfigComponent>().MyConfig.Options.Id;
+			this.appType = Game.Scene.GetComponent<StartConfigComponent>().MyConfig.AppType;
+			this.appId = Game.Scene.GetComponent<StartConfigComponent>().MyConfig.AppId;
 			Log.Callback.Add(this.Id, this.LogToClient);
 		}
 
@@ -29,7 +29,7 @@ namespace Model
 			{
 				return;
 			}
-			this.GetComponent<MessageComponent>().Send(new R2C_ServerLog { AppType = this.appType, AppId = this.appId, Type = type, Log = message });
+			this.GetOwner<Session>().Send(new R2C_ServerLog { AppType = this.appType, AppId = this.appId, Type = type, Log = message });
 		}
 
 		public override void Dispose()

+ 3 - 3
Server/Model/Component/RealmGateAddressComponent.cs

@@ -14,18 +14,18 @@ namespace Model
 
 	public class RealmGateAddressComponent : Component
 	{
-		private readonly List<Entity> GateAddress = new List<Entity>();
+		private readonly List<StartConfig> GateAddress = new List<StartConfig>();
 
 		public void Awake()
 		{
 			StartConfig[] startConfigs = this.GetComponent<StartConfigComponent>().GetAll();
 			foreach (StartConfig config in startConfigs)
 			{
-				if (config.Options.AppType != "Gate")
+				if (config.AppType != "Gate")
 				{
 					continue;
 				}
-				this.GateAddress.Add(config.Config);
+				this.GateAddress.Add(config);
 			}
 		}
 

+ 1 - 2
Server/Model/Component/StartConfigComponent.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.IO;
 using Base;
 using CommandLine;
-using MongoDB.Bson.Serialization;
 
 namespace Model
 {
@@ -38,7 +37,7 @@ namespace Model
 				{
 					StartConfig startConfig = MongoHelper.FromJson<StartConfig>(s2);
 					this.allConfigs.Add(startConfig);
-					this.configDict.Add(startConfig.Options.Id, startConfig);
+					this.configDict.Add(startConfig.AppId, startConfig);
 				}
 				catch (Exception)
 				{

+ 27 - 3
Server/Model/Server.Model.csproj

@@ -47,9 +47,6 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Component\KVComponent.cs">
       <Link>Component\KVComponent.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Component\MessageComponent.cs">
-      <Link>Component\MessageComponent.cs</Link>
-    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Component\MessageDispatherComponent.cs">
       <Link>Component\MessageDispatherComponent.cs</Link>
     </Compile>
@@ -65,18 +62,45 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Component\TimerComponent.cs">
       <Link>Component\TimerComponent.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Game.cs">
+      <Link>Entity\Game.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Scene.cs">
+      <Link>Entity\Scene.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Session.cs">
+      <Link>Entity\Session.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\AMessage.cs">
+      <Link>Message\AMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\AMEvent.cs">
+      <Link>Message\AMEvent.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Message\AppType.cs">
       <Link>Message\AppType.cs</Link>
     </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Message\ErrorCode.cs">
       <Link>Message\ErrorCode.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\IMRegister.cs">
+      <Link>Message\IMRegister.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Message\Message.cs">
       <Link>Message\Message.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\MessageAttribute.cs">
+      <Link>Message\MessageAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\MessageHandlerAttribute.cs">
+      <Link>Message\MessageHandlerAttribute.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Message\OpcodeHelper.cs">
       <Link>Message\OpcodeHelper.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\RpcException.cs">
+      <Link>Message\RpcException.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Other\BsonClassMapRegister.cs">
       <Link>Other\BsonClassMapRegister.cs</Link>
     </Compile>

+ 2 - 2
Unity/Assets/Plugins/Base/Message.meta → Unity/Assets/Editor/ServerCommandLineEditor/Component.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
-guid: 32549de57e26990479432c71eabaa8dd
+guid: 24f0b40b39c2f954d9e5e63bbb17f3d6
 folderAsset: yes
-timeCreated: 1476426533
+timeCreated: 1476673759
 licenseType: Pro
 DefaultImporter:
   userData: 

+ 12 - 12
Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs

@@ -61,14 +61,14 @@ namespace MyEditor
 			{
 				StartConfig startConfig = this.startConfigs[i];
 				GUILayout.BeginHorizontal();
-				GUILayout.Label($"Id:");
-				startConfig.Options.Id = EditorGUILayout.IntField(startConfig.Options.Id);
+				GUILayout.Label($"AppId:");
+				startConfig.AppId = EditorGUILayout.IntField(startConfig.AppId);
 				GUILayout.Label($"服务器IP:");
-				startConfig.IP = EditorGUILayout.TextField(startConfig.IP);
+				startConfig.ServerIP = EditorGUILayout.TextField(startConfig.ServerIP);
 				GUILayout.Label($"AppType:");
-				startConfig.Options.AppType = EditorGUILayout.TextField(startConfig.Options.AppType);
+				startConfig.AppType = EditorGUILayout.TextField(startConfig.AppType);
 
-				InnerConfig innerConfig = startConfig.Config.GetComponent<InnerConfig>();
+				InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
 				if (innerConfig != null)
 				{
 					GUILayout.Label($"Host:");
@@ -77,7 +77,7 @@ namespace MyEditor
 					innerConfig.Port = EditorGUILayout.IntField(innerConfig.Port);
 				}
 
-				OuterConfig outerConfig = startConfig.Config.GetComponent<OuterConfig>();
+				OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
 				if (outerConfig != null)
 				{
 					GUILayout.Label($"OuterHost:");
@@ -97,7 +97,7 @@ namespace MyEditor
 					for (int j = 1; j < this.copyNum + 1; ++j)
 					{
 						StartConfig newStartConfig = (StartConfig)startConfig.Clone();
-						newStartConfig.Options.Id += j;
+						newStartConfig.AppId += j;
 						this.startConfigs.Add(newStartConfig);
 					}
 					break;
@@ -118,12 +118,12 @@ namespace MyEditor
 			{
 				StartConfig newStartConfig = new StartConfig();
 
-				newStartConfig.Options.AppType = this.AppType;
-				newStartConfig.Config.AddComponent<InnerConfig>();
+				newStartConfig.AppType = this.AppType;
+				newStartConfig.AddComponent<InnerConfig>();
 
 				if (this.AppType == Model.AppType.Gate || this.AppType == Model.AppType.Realm || this.AppType == Model.AppType.Manager)
 				{
-					newStartConfig.Config.AddComponent<OuterConfig>();
+					newStartConfig.AddComponent<OuterConfig>();
 				}
 
 				this.startConfigs.Add(newStartConfig);
@@ -149,7 +149,7 @@ namespace MyEditor
 				StartConfig startConfig = null;
 				foreach (StartConfig config in this.startConfigs)
 				{
-					if (config.Options.AppType == Model.AppType.Manager)
+					if (config.AppType == Model.AppType.Manager)
 					{
 						startConfig = config;
 					}
@@ -161,7 +161,7 @@ namespace MyEditor
 					return;
 				}
 				
-				string arguments = $"--id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
+				string arguments = $"--id={startConfig.AppId} --appType={startConfig.AppType}";
 
 				ProcessStartInfo info = new ProcessStartInfo(@"App.exe", arguments)
 				{

+ 2 - 2
Unity/Assets/Editor/ServerManagerEditor/ServerManagerEditor.cs

@@ -67,10 +67,10 @@ namespace MyEditor
 					}
 				}
 				NetworkComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();
-				Entity session = networkComponent.Get($"{this.managerAddress}");
+				Session session = networkComponent.Get($"{this.managerAddress}");
 				try
 				{
-					session.GetComponent<MessageComponent>().Call<C2M_Reload, M2C_Reload>(new C2M_Reload { AppType = selected });
+					session.Call<C2M_Reload, M2C_Reload>(new C2M_Reload { AppType = selected });
 				}
 				catch (RpcException e)
 				{

+ 0 - 26
Unity/Assets/Plugins/Base/Game.cs

@@ -1,26 +0,0 @@
-namespace Base
-{
-	public sealed class Game
-	{
-		private static Entity game;
-
-		public static Entity Scene
-		{
-			get
-			{
-				if (game == null)
-				{
-					game = new Entity("Scene");
-				}
-				return game;
-			}
-		}
-
-		public static void Close()
-		{
-			Entity scene = game;
-			game = null;
-			scene.Dispose();
-		}
-	}
-}

+ 7 - 2
Unity/Assets/Plugins/Base/Object/Component.cs

@@ -8,7 +8,12 @@ namespace Base
 	public abstract class Component : Object
 	{
 		[BsonIgnore]
-		public Entity Owner { get; set; }
+		public Entity Owner { protected get; set; }
+
+		protected T GetOwner<T>() where T: Entity
+		{
+			return this.Owner as T;
+		}
 
 		protected Component()
 		{
@@ -20,7 +25,7 @@ namespace Base
 			ObjectManager.Add(this);
 		}
 
-		public T GetComponent<T>() where T: Component
+		protected T GetComponent<T>() where T: Component
 		{
 			return this.Owner.GetComponent<T>();
 		}

+ 3 - 4
Unity/Assets/Plugins/Base/Object/Entity.cs

@@ -1,12 +1,11 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using Base;
 using MongoDB.Bson.Serialization.Attributes;
 
 namespace Base
 {
-	public sealed class Entity: Object
+	public class Entity: Object
 	{
 		public string Type { get; set; }
 
@@ -16,13 +15,13 @@ namespace Base
 		[BsonIgnore]
 		private Dictionary<Type, Component> componentDict = new Dictionary<Type, Component>();
 
-		public Entity(string entityType)
+		protected Entity(string entityType)
 		{
 			this.Type = entityType;
 			ObjectManager.Add(this);
 		}
 
-		public Entity(long id, string entityType) : base(id)
+		protected Entity(long id, string entityType) : base(id)
 		{
 			this.Type = entityType;
 			ObjectManager.Add(this);

+ 17 - 17
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs

@@ -35,8 +35,8 @@ namespace Model
 		}
 
 		private string AppType;
-		private Dictionary<ushort, List<Action<Entity, MessageInfo>>> handlers;
-		private Dictionary<ushort, Action<Entity, MessageInfo>> rpcHandlers;
+		private Dictionary<ushort, List<Action<Session, MessageInfo>>> handlers;
+		private Dictionary<ushort, Action<Session, MessageInfo>> rpcHandlers;
 		private Dictionary<Type, MessageAttribute> messageOpcode { get; set; } = new Dictionary<Type, MessageAttribute>();
 		
 		public void Awake(string appType)
@@ -47,8 +47,8 @@ namespace Model
 
 		public void Load()
 		{
-			this.handlers = new Dictionary<ushort, List<Action<Entity, MessageInfo>>>();
-			this.rpcHandlers = new Dictionary<ushort, Action<Entity, MessageInfo>>();
+			this.handlers = new Dictionary<ushort, List<Action<Session, MessageInfo>>>();
+			this.rpcHandlers = new Dictionary<ushort, Action<Session, MessageInfo>>();
 			this.messageOpcode = new Dictionary<Type, MessageAttribute>();
 
 			Assembly[] assemblies = Object.ObjectManager.GetAssemblies();
@@ -103,13 +103,13 @@ namespace Model
 			return this.messageOpcode[type].Opcode;
 		}
 
-		public void RegisterHandler<Message>(ushort opcode, Action<Entity, Message> action) where Message: AMessage
+		public void RegisterHandler<Message>(ushort opcode, Action<Session, Message> action) where Message: AMessage
 		{
 			if (!this.handlers.ContainsKey(opcode))
 			{
-				this.handlers.Add(opcode, new List<Action<Entity, MessageInfo>>());
+				this.handlers.Add(opcode, new List<Action<Session, MessageInfo>>());
 			}
-			List<Action<Entity, MessageInfo>> actions = this.handlers[opcode];
+			List<Action<Session, MessageInfo>> actions = this.handlers[opcode];
 
 			actions.Add((entity, messageInfo) =>
 			{
@@ -128,7 +128,7 @@ namespace Model
 			});
 		}
 		
-		public void RegisterRpcHandler<Request, Response>(ushort opcode, Action<Entity, Request, Action<Response>> action) 
+		public void RegisterRpcHandler<Request, Response>(ushort opcode, Action<Session, Request, Action<Response>> action) 
 			where Request: ARequest 
 			where Response: AResponse
 		{
@@ -137,7 +137,7 @@ namespace Model
 				Log.Error($"rpc消息不能注册两次! opcode: {opcode}");
 				return;
 			}
-			this.rpcHandlers.Add(opcode, (entity, messageInfo) =>
+			this.rpcHandlers.Add(opcode, (session, messageInfo) =>
 			{
 				Request request;
 				try
@@ -150,18 +150,18 @@ namespace Model
 					throw new Exception("解释消息失败:" + opcode, ex);
 				}
 
-				action(entity, request, response =>
+				action(session, request, response =>
 					{
-						entity.GetComponent<MessageComponent>().Reply(messageInfo.RpcId, response); 
+						session.Reply(messageInfo.RpcId, response); 
 					} 
 				);
 			});
 		}
 
 
-		public void Handle(Entity entity, ushort opcode, byte[] messageBytes, int offset)
+		public void Handle(Session session, ushort opcode, byte[] messageBytes, int offset)
 		{
-			List<Action<Entity, MessageInfo>> actions;
+			List<Action<Session, MessageInfo>> actions;
 			if (!this.handlers.TryGetValue(opcode, out actions))
 			{
 				Log.Error($"消息 {opcode} 没有处理");
@@ -172,7 +172,7 @@ namespace Model
 			{
 				try
 				{
-					ev(entity, new MessageInfo { MessageBytes = messageBytes, Offset = offset, Count = messageBytes.Length - offset });
+					ev(session, new MessageInfo { MessageBytes = messageBytes, Offset = offset, Count = messageBytes.Length - offset });
 				}
 				catch (Exception e)
 				{
@@ -181,9 +181,9 @@ namespace Model
 			}
 		}
 
-		public void HandleRpc(Entity entity, ushort opcode, byte[] messageBytes, int offset, uint rpcId)
+		public void HandleRpc(Session session, ushort opcode, byte[] messageBytes, int offset, uint rpcId)
 		{
-			Action<Entity, MessageInfo> action;
+			Action<Session, MessageInfo> action;
 			if (!this.rpcHandlers.TryGetValue(opcode, out action))
 			{
 				Log.Error($"Rpc消息 {opcode} 没有处理");
@@ -192,7 +192,7 @@ namespace Model
 
 			try
 			{
-				action(entity, new MessageInfo { MessageBytes = messageBytes, Offset = offset, Count = messageBytes.Length - offset, RpcId = rpcId });
+				action(session, new MessageInfo { MessageBytes = messageBytes, Offset = offset, Count = messageBytes.Length - offset, RpcId = rpcId });
 			}
 			catch (Exception e)
 			{

+ 14 - 16
Unity/Assets/Scripts/Component/NetworkComponent.cs

@@ -9,8 +9,8 @@ namespace Model
 	{
 		private AService Service;
 
-		private readonly Dictionary<long, Entity> sessions = new Dictionary<long, Entity>();
-		private readonly Dictionary<string, Entity> adressSessions = new Dictionary<string, Entity>();
+		private readonly Dictionary<long, Session> sessions = new Dictionary<long, Session>();
+		private readonly Dictionary<string, Session> adressSessions = new Dictionary<string, Session>();
 
 		protected void Awake(NetworkProtocol protocol)
 		{
@@ -55,40 +55,39 @@ namespace Model
 
 				AChannel channel = await this.Service.AcceptChannel();
 
-				Entity session = new Entity(EntityType.Session);
+				Session session = new Session(channel);
 				channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
-				session.AddComponent<MessageComponent, AChannel>(channel);
 				this.Add(session);
 			}
 		}
 
-		private void Add(Entity session)
+		private void Add(Session session)
 		{
 			this.sessions.Add(session.Id, session);
-			this.adressSessions.Add(session.GetComponent<MessageComponent>().RemoteAddress, session);
+			this.adressSessions.Add(session.RemoteAddress, session);
 		}
 
 		public void Remove(long id)
 		{
-			Entity session;
+			Session session;
 			if (!this.sessions.TryGetValue(id, out session))
 			{
 				return;
 			}
 			this.sessions.Remove(id);
-			this.adressSessions.Remove(session.GetComponent<MessageComponent>().RemoteAddress);
+			this.adressSessions.Remove(session.RemoteAddress);
 		}
 
-		public Entity Get(long id)
+		public Session Get(long id)
 		{
-			Entity session;
+			Session session;
 			this.sessions.TryGetValue(id, out session);
 			return session;
 		}
 
-		public Entity Get(string address)
+		public Session Get(string address)
 		{
-			Entity session;
+			Session session;
 			if (this.adressSessions.TryGetValue(address, out session))
 			{
 				return session;
@@ -98,9 +97,8 @@ namespace Model
 			int port = int.Parse(ss[1]);
 			string host = ss[0];
 			AChannel channel = this.Service.ConnectChannel(host, port);
-			session = new Entity(EntityType.Session);
+			session = new Session(channel);
 			channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
-			session.AddComponent<MessageComponent, AChannel>(channel);
 			this.Add(session);
 
 			return session;
@@ -115,9 +113,9 @@ namespace Model
 
 			base.Dispose();
 
-			foreach (Entity entity in this.sessions.Values.ToArray())
+			foreach (Session session in this.sessions.Values.ToArray())
 			{
-				entity.Dispose();
+				session.Dispose();
 			}
 			
 			this.Service.Dispose();

+ 9 - 0
Unity/Assets/Scripts/Entity.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: d2b1f66f808fc9a4ba043d89e5d982f9
+folderAsset: yes
+timeCreated: 1477361235
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 24 - 0
Unity/Assets/Scripts/Entity/Game.cs

@@ -0,0 +1,24 @@
+using Model;
+
+namespace Base
+{
+	public sealed class Game
+	{
+		private static Scene scene;
+
+		public static Scene Scene
+		{
+			get
+			{
+				return scene ?? (scene = new Scene());
+			}
+		}
+
+		public static void Close()
+		{
+			Scene s = scene;
+			scene = null;
+			s.Dispose();
+		}
+	}
+}

+ 2 - 2
Unity/Assets/Plugins/Base/Game.cs.meta → Unity/Assets/Scripts/Entity/Game.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 55f8ee3c9055ec44cb405533e23f8ad7
-timeCreated: 1476430040
+guid: 8b09c881ef13d1a468c08473032049e5
+timeCreated: 1477361446
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 9 - 1
Unity/Assets/Scripts/Component/Scene.cs → Unity/Assets/Scripts/Entity/Scene.cs

@@ -17,7 +17,7 @@ namespace Model
 		Realm,
 	}
 
-	public sealed class Scene: Component
+	public sealed class Scene: Entity
 	{
 		public Scene Parent { get; set; }
 
@@ -25,6 +25,14 @@ namespace Model
 
 		public SceneType SceneType { get; private set; }
 
+		public Scene(): base(EntityType.Scene)
+		{
+		}
+
+		public Scene(long id): base(id, EntityType.Scene)
+		{
+		}
+
 		public override void Dispose()
 		{
 			if (this.Id == 0)

+ 0 - 0
Unity/Assets/Scripts/Component/Scene.cs.meta → Unity/Assets/Scripts/Entity/Scene.cs.meta


+ 20 - 34
Unity/Assets/Scripts/Component/MessageComponent.cs → Unity/Assets/Scripts/Entity/Session.cs

@@ -6,29 +6,15 @@ using Base;
 
 namespace Model
 {
-	[ObjectEvent]
-	public class MessageComponentEvent : ObjectEvent<MessageComponent>, IAwake<AChannel>
-	{
-		public void Awake(AChannel aChannel)
-		{
-			this.GetValue().Awake(aChannel);
-		}
-	}
-	
-	/// <summary>
-	/// 消息收发
-	/// </summary>
-	public class MessageComponent: Component
+	public sealed class Session: Entity
 	{
 		private static uint RpcId { get; set; }
 		private readonly Dictionary<uint, Action<byte[], int, int>> requestCallback = new Dictionary<uint, Action<byte[], int, int>>();
-		private AChannel channel;
-		private MessageDispatherComponent messageDispather;
-		
-		public void Awake(AChannel aChannel)
+		private readonly AChannel channel;
+
+		public Session(AChannel channel) : base(EntityType.Session)
 		{
-			this.messageDispather = Game.Scene.GetComponent<MessageDispatherComponent>();
-			this.channel = aChannel;
+			this.channel = channel;
 			this.StartRecv();
 		}
 
@@ -39,7 +25,7 @@ namespace Model
 				return this.channel.RemoteAddress;
 			}
 		}
-		
+
 		private async void StartRecv()
 		{
 			while (true)
@@ -93,7 +79,7 @@ namespace Model
 			{
 				offset = 6;
 			}
-			
+
 			this.RunDecompressedBytes(opcode, rpcId, rpcFlag, messageBytes, offset);
 		}
 
@@ -102,7 +88,7 @@ namespace Model
 			// 普通消息
 			if (rpcId == 0)
 			{
-				this.messageDispather.Handle(this.Owner, opcode, messageBytes, offset);
+				Game.Scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset);
 				return;
 			}
 
@@ -120,14 +106,14 @@ namespace Model
 			}
 			else // 这是一个rpc请求消息
 			{
-				this.messageDispather.HandleRpc(this.Owner, opcode, messageBytes, offset, rpcId);
+				Game.Scene.GetComponent<MessageDispatherComponent>().HandleRpc(this, opcode, messageBytes, offset, rpcId);
 			}
 		}
 
 		/// <summary>
 		/// Rpc调用
 		/// </summary>
-		public Task<Response> Call<Request, Response>(Request request, CancellationToken cancellationToken) 
+		public Task<Response> Call<Request, Response>(Request request, CancellationToken cancellationToken)
 			where Request : ARequest
 			where Response : AResponse
 		{
@@ -161,12 +147,12 @@ namespace Model
 		/// <summary>
 		/// Rpc调用,发送一个消息,等待返回一个消息
 		/// </summary>
-		public Task<Response> Call<Request, Response>(Request request) 
-			where Request: ARequest 
+		public Task<Response> Call<Request, Response>(Request request)
+			where Request : ARequest
 			where Response : AResponse
 		{
 			this.SendMessage(++RpcId, request);
-			
+
 			var tcs = new TaskCompletionSource<Response>();
 			this.requestCallback[RpcId] = (bytes, offset, count) =>
 			{
@@ -175,7 +161,7 @@ namespace Model
 					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
 					if (response.Error != 0)
 					{
-						tcs.SetException(new RpcException(response.Error,  response.Message));
+						tcs.SetException(new RpcException(response.Error, response.Message));
 						return;
 					}
 					tcs.SetResult(response);
@@ -185,29 +171,29 @@ namespace Model
 					tcs.SetException(new Exception($"Rpc Error: {typeof(Response).FullName}", e));
 				}
 			};
-			
+
 			return tcs.Task;
 		}
 
-		public void Send<Message>(Message message) where Message: AMessage
+		public void Send<Message>(Message message) where Message : AMessage
 		{
 			this.SendMessage(0, message);
 		}
 
-		public void Reply<Response>(uint rpcId, Response message) where Response: AResponse
+		public void Reply<Response>(uint rpcId, Response message) where Response : AResponse
 		{
 			this.SendMessage(rpcId, message, false);
 		}
 
 		private void SendMessage(uint rpcId, object message, bool isCall = true)
 		{
-			ushort opcode = this.messageDispather.GetOpcode(message.GetType());
+			ushort opcode = Game.Scene.GetComponent<MessageDispatherComponent>().GetOpcode(message.GetType());
 			byte[] opcodeBytes = BitConverter.GetBytes(opcode);
 			if (!isCall)
 			{
 				rpcId = rpcId | 0x40000000;
 			}
-			
+
 			byte[] messageBytes = MongoHelper.ToBson(message);
 			if (messageBytes.Length > 100)
 			{
@@ -220,7 +206,7 @@ namespace Model
 			}
 
 			byte[] seqBytes = BitConverter.GetBytes(rpcId);
-			
+
 			channel.Send(new List<byte[]> { opcodeBytes, seqBytes, messageBytes });
 		}
 

+ 2 - 2
Unity/Assets/Scripts/Component/MessageComponent.cs.meta → Unity/Assets/Scripts/Entity/Session.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 3ad2d94454456394ab8af33f059f9254
-timeCreated: 1476550923
+guid: 73d149d0c325fa24d91a94843bd520b8
+timeCreated: 1477361540
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 9 - 1
Unity/Assets/Scripts/Component/UI.cs → Unity/Assets/Scripts/Entity/UI.cs

@@ -4,7 +4,7 @@ using Component = Base.Component;
 
 namespace Model
 {
-	public sealed class UI: Component
+	public sealed class UI: Entity
 	{
 		public Entity Scene { get; set; }
 
@@ -23,5 +23,13 @@ namespace Model
 
 			base.Dispose();
 		}
+
+		public UI(): base(EntityType.UI)
+		{
+		}
+
+		public UI(long id): base(id, EntityType.UI)
+		{
+		}
 	}
 }

+ 0 - 0
Unity/Assets/Scripts/Component/UI.cs.meta → Unity/Assets/Scripts/Entity/UI.cs.meta


+ 4 - 3
Unity/Assets/Plugins/Base/Message/AMEvent.cs → Unity/Assets/Scripts/Message/AMEvent.cs

@@ -1,10 +1,11 @@
 using System;
+using Base;
 
-namespace Base
+namespace Model
 {
 	public abstract class AMEvent<Message>: IMRegister where Message: AMessage
 	{
-		protected abstract void Run(Entity scene, Message message);
+		protected abstract void Run(Session session, Message message);
 
 		public void Register(IMessageDispather component)
 		{
@@ -17,7 +18,7 @@ namespace Base
 			where Request : ARequest
 			where Response: AResponse
 	{
-		protected abstract void Run(Entity scene, Request message, Action<Response> reply);
+		protected abstract void Run(Session scene, Request message, Action<Response> reply);
 
 		public void Register(IMessageDispather component)
 		{

+ 2 - 2
Unity/Assets/Plugins/Base/Message/AMEvent.cs.meta → Unity/Assets/Scripts/Message/AMEvent.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 4baf1ce7bcc358548b06835969112d12
-timeCreated: 1476426533
+guid: 7794c33776a80624a8d89d76647d2c2d
+timeCreated: 1477362301
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/Plugins/Base/Message/AMessage.cs → Unity/Assets/Scripts/Message/AMessage.cs

@@ -1,4 +1,4 @@
-namespace Base
+namespace Model
 {
 	public abstract class AMessage
 	{

+ 2 - 2
Unity/Assets/Plugins/Base/Message/AMessage.cs.meta → Unity/Assets/Scripts/Message/AMessage.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 5fcce1859acc04a47b65461b59de3c5f
-timeCreated: 1476426533
+guid: 7f7b01638a2ed1242a9b81b7d6f408eb
+timeCreated: 1477362301
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 5 - 3
Unity/Assets/Plugins/Base/Message/IMRegister.cs → Unity/Assets/Scripts/Message/IMRegister.cs

@@ -1,13 +1,15 @@
 using System;
+using Model;
 
-namespace Base
+namespace Model
 {
 	public interface IMessageDispather
 	{
 		ushort GetOpcode(Type type);
-		void RegisterHandler<Message>(ushort opcode, Action<Entity, Message> action) where Message : AMessage;
 
-		void RegisterRpcHandler<Request, Response>(ushort opcode, Action<Entity, Request, Action<Response>> action) 
+		void RegisterHandler<Message>(ushort opcode, Action<Session, Message> action) where Message : AMessage;
+
+		void RegisterRpcHandler<Request, Response>(ushort opcode, Action<Session, Request, Action<Response>> action) 
 			where Request : ARequest
 			where Response : AResponse;
 	}

+ 2 - 2
Unity/Assets/Plugins/Base/Message/IMRegister.cs.meta → Unity/Assets/Scripts/Message/IMRegister.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 590cb3094f089124b83a76718332e939
-timeCreated: 1476426533
+guid: a0499b792b4bc834aaabea7d37495f6e
+timeCreated: 1477361955
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/Plugins/Base/Message/MessageAttribute.cs → Unity/Assets/Scripts/Message/MessageAttribute.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Base
+namespace Model
 {
 	public class MessageAttribute : Attribute
 	{

+ 2 - 2
Unity/Assets/Plugins/Base/Message/MessageAttribute.cs.meta → Unity/Assets/Scripts/Message/MessageAttribute.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 485eb61dbc2b9664d80d40e19aa80c49
-timeCreated: 1476426533
+guid: 66c190633eef4db4485544e51062c212
+timeCreated: 1477362301
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/Plugins/Base/Message/MessageHandlerAttribute.cs → Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 
-namespace Base
+namespace Model
 {
 	/// <summary>
 	/// 搭配MessageComponent用来分发消息

+ 2 - 2
Unity/Assets/Plugins/Base/Message/MessageHandlerAttribute.cs.meta → Unity/Assets/Scripts/Message/MessageHandlerAttribute.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: fcf293ee7dda23746a98f4308723280e
-timeCreated: 1476426533
+guid: 701bb8db44288494c97fc181c32e0ace
+timeCreated: 1477362301
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/Plugins/Base/Message/RpcException.cs → Unity/Assets/Scripts/Message/RpcException.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Base
+namespace Model
 {
 	/// <summary>
 	/// RPC异常,带ErrorCode

+ 2 - 2
Unity/Assets/Plugins/Base/Message/RpcException.cs.meta → Unity/Assets/Scripts/Message/RpcException.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 4f38d6a2a2474b64281eb5052580b91d
-timeCreated: 1476427109
+guid: 27fa1e2e2513ec047acbdaa4f770eee2
+timeCreated: 1477362301
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 12 - 1
Unity/Assets/Scripts/Other/ClientConfig.cs

@@ -1,8 +1,19 @@
-namespace Model
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace Model
 {
 	public class ClientConfig
 	{
 		public string Host = "";
 		public int Port;
+
+		[BsonIgnore]
+		public string Address
+		{
+			get
+			{
+				return $"{this.Host}:{this.Port}";
+			}
+		}
 	}
 }

+ 3 - 0
Unity/Assets/Scripts/Other/EntityType.cs

@@ -3,6 +3,9 @@
 	public static class EntityType
 	{
 		public const string None = "None";
+		public const string Scene = "Scene";
 		public const string Session = "Session";
+		public const string UI = "UI";
+		public const string Config = "Config";
 	}
 }

+ 5 - 7
Unity/Assets/Scripts/Other/StartConfig.cs

@@ -3,18 +3,16 @@ using Base;
 
 namespace Model
 {
-	public class StartConfig: ICloneable
+	public class StartConfig: Entity
 	{
-		public Options Options { get; set; }
+		public int AppId { get; set; }
 
-		public string IP { get; set; }
+		public string AppType { get; set; }
 
-		public Entity Config { get; set; }
+		public string ServerIP { get; set; }
 
-		public StartConfig()
+		public StartConfig(): base(EntityType.Config)
 		{
-			this.Options = new Options();
-			this.Config = new Entity("StartConfig");
 		}
 
 		public object Clone()

+ 1 - 1
Unity/ClientConfig.txt

@@ -1 +1 @@
-{ "_t" : "ClientConfig", "Host" : "192.168.1.134", "Port" : 10003 }
+{ "_t" : "ClientConfig", "Host" : "192.168.12.188", "Port" : 10001 }

+ 4 - 4
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs

@@ -15,17 +15,17 @@ namespace Controller
 			Game.Scene.AddComponent<MessageDispatherComponent, string>("Client");
 			ClientConfig clientConfig = Game.Scene.AddComponent<ClientConfigComponent>().Config;
 			NetworkComponent networkComponent = Game.Scene.AddComponent<NetOuterComponent>();
-			Entity session = networkComponent.Get($"{clientConfig.Host}:{clientConfig.Port}");
+			Session session = networkComponent.Get(clientConfig.Address);
 
 			try
 			{
-				R2C_Login s2CLogin = await session.GetComponent<MessageComponent>().Call<C2R_Login, R2C_Login>(new C2R_Login {Account = "abcdef", Password = "111111"});
+				R2C_Login s2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login {Account = "abcdef", Password = "111111"});
 				networkComponent.Remove(session.Id);
 
 				// 连接Gate
 				Log.Debug(MongoHelper.ToJson(s2CLogin));
-				Entity gateSession = networkComponent.Get(s2CLogin.Address);
-				await gateSession.GetComponent<MessageComponent>().Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
+				Session gateSession = networkComponent.Get(s2CLogin.Address);
+				await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
 				Log.Info("连接Gate验证成功!");
 			}
 			catch (RpcException e)

+ 1 - 1
Unity/Controller/Message/R2C_ServerLogHandler.cs

@@ -6,7 +6,7 @@ namespace Controller
 	[MessageHandler(AppType.Client)]
 	public class R2C_ServerLogHandler: AMEvent<R2C_ServerLog>
 	{
-		protected override void Run(Entity scene, R2C_ServerLog message)
+		protected override void Run(Session scene, R2C_ServerLog message)
 		{
 			Log.Debug($"[{message.AppType}][{message.AppId}] [{message.Type}] {message.Log}");
 		}

+ 2 - 11
Unity/Unity.CSharp.Plugins.csproj

@@ -13,13 +13,11 @@
     <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     <TargetFrameworkProfile>Unity Full v3.5</TargetFrameworkProfile>
-    <CompilerResponseFile>
-    </CompilerResponseFile>
+    <CompilerResponseFile></CompilerResponseFile>
     <UnityProjectType>GamePlugins:3</UnityProjectType>
     <UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
     <UnityVersion>5.4.1f1</UnityVersion>
-    <RootNamespace>
-    </RootNamespace>
+    <RootNamespace></RootNamespace>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -84,7 +82,6 @@
     <Compile Include="Assets\Plugins\Base\Event\EventAttribute.cs" />
     <Compile Include="Assets\Plugins\Base\Event\EventBaseType.cs" />
     <Compile Include="Assets\Plugins\Base\Event\IEvent.cs" />
-    <Compile Include="Assets\Plugins\Base\Game.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\ArrayHelper.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\ByteHelper.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\EnumHelper.cs" />
@@ -100,12 +97,6 @@
     <Compile Include="Assets\Plugins\Base\Helper\ZipHelper.cs" />
     <Compile Include="Assets\Plugins\Base\Log.cs" />
     <Compile Include="Assets\Plugins\Base\LogType.cs" />
-    <Compile Include="Assets\Plugins\Base\Message\AMEvent.cs" />
-    <Compile Include="Assets\Plugins\Base\Message\AMessage.cs" />
-    <Compile Include="Assets\Plugins\Base\Message\IMRegister.cs" />
-    <Compile Include="Assets\Plugins\Base\Message\MessageAttribute.cs" />
-    <Compile Include="Assets\Plugins\Base\Message\MessageHandlerAttribute.cs" />
-    <Compile Include="Assets\Plugins\Base\Message\RpcException.cs" />
     <Compile Include="Assets\Plugins\Base\MultiMap.cs" />
     <Compile Include="Assets\Plugins\Base\Network\AChannel.cs" />
     <Compile Include="Assets\Plugins\Base\Network\AService.cs" />

+ 10 - 3
Unity/Unity.CSharp.csproj

@@ -85,15 +85,16 @@
     <Compile Include="Assets\Scripts\Component\GameObjectComponent.cs" />
     <Compile Include="Assets\Scripts\Component\GlobalConfigComponent.cs" />
     <Compile Include="Assets\Scripts\Component\KVComponent.cs" />
-    <Compile Include="Assets\Scripts\Component\MessageComponent.cs" />
     <Compile Include="Assets\Scripts\Component\MessageDispatherComponent.cs" />
     <Compile Include="Assets\Scripts\Component\NetInnerComponent.cs" />
     <Compile Include="Assets\Scripts\Component\NetOuterComponent.cs" />
     <Compile Include="Assets\Scripts\Component\NetworkComponent.cs" />
-    <Compile Include="Assets\Scripts\Component\Scene.cs" />
+    <Compile Include="Assets\Scripts\Entity\Game.cs" />
+    <Compile Include="Assets\Scripts\Entity\Session.cs" />
+    <Compile Include="Assets\Scripts\Entity\Scene.cs" />
     <Compile Include="Assets\Scripts\Component\TimeComponent.cs" />
     <Compile Include="Assets\Scripts\Component\TimerComponent.cs" />
-    <Compile Include="Assets\Scripts\Component\UI.cs" />
+    <Compile Include="Assets\Scripts\Entity\UI.cs" />
     <Compile Include="Assets\Scripts\Config\BuffProto.cs" />
     <Compile Include="Assets\Scripts\Config\GlobalProto.cs" />
     <Compile Include="Assets\Scripts\Event\EnvKey.cs" />
@@ -101,10 +102,16 @@
     <Compile Include="Assets\Scripts\GameObjectHelper.cs" />
     <Compile Include="Assets\Scripts\Helper\DllHelper.cs" />
     <Compile Include="Assets\Scripts\Init.cs" />
+    <Compile Include="Assets\Scripts\Message\AMessage.cs" />
+    <Compile Include="Assets\Scripts\Message\AMEvent.cs" />
     <Compile Include="Assets\Scripts\Message\AppType.cs" />
     <Compile Include="Assets\Scripts\Message\ErrorCode.cs" />
+    <Compile Include="Assets\Scripts\Message\IMRegister.cs" />
     <Compile Include="Assets\Scripts\Message\Message.cs" />
+    <Compile Include="Assets\Scripts\Message\MessageAttribute.cs" />
+    <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\Other\BsonClassMapRegister.cs" />
     <Compile Include="Assets\Scripts\Other\ClientConfig.cs" />
     <Compile Include="Assets\Scripts\Other\ServerType.cs" />