Răsfoiți Sursa

增加ServerType枚举,简化了代码

tanghai 9 ani în urmă
părinte
comite
83bd33bcc2

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

@@ -21,7 +21,7 @@ namespace Controller
 						continue;
 					}
 					InnerConfig innerConfig = startConfig.Config.GetComponent<InnerConfig>();
-					Entity serverSession = netInnerComponent.Get($"{innerConfig.Host}:{innerConfig.Port}");
+					Entity serverSession = netInnerComponent.Get(innerConfig.Address);
 					await serverSession.GetComponent<MessageComponent>().Call<M2A_Reload, A2M_Reload>(new M2A_Reload());
 				}
 			}

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

@@ -20,7 +20,7 @@ namespace Controller
 				a2MReload.Error = ErrorCode.ERR_ReloadFail;
 				StartConfig myStartConfig = Game.Scene.GetComponent<StartConfigComponent>().MyConfig;
 				InnerConfig innerConfig = myStartConfig.Config.GetComponent<InnerConfig>();
-				a2MReload.Message = $"{innerConfig.Host}:{innerConfig.Port} reload fail, {e}";
+				a2MReload.Message = $"{innerConfig.Address} reload fail, {e}";
 			}
 			reply(a2MReload);
 		}

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

@@ -86,6 +86,9 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Other\Options.cs">
       <Link>Other\Options.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Other\ServerType.cs">
+      <Link>Other\ServerType.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Other\StartConfig.cs">
       <Link>Other\StartConfig.cs</Link>
     </Compile>

+ 1 - 1
Server/Run.sh

@@ -5,5 +5,5 @@ cd Bin/Debug/
 cmake ../..
 make
 
-pkill App.exe
+ps -ef | grep App.exe | awk '{print $2}' | xargs kill -9
 mono --debug App.exe --id=1 --appType=Manager

+ 1 - 1
Server/Start.sh

@@ -1,5 +1,5 @@
 #!/bin/bash
 
 cd Bin/Debug/
-pkill App.exe
+ps -ef | grep App.exe | awk '{print $2}' | xargs kill -9
 mono --debug App.exe --id=1 --appType=Manager

+ 7 - 6
Unity/Assets/Editor/ServerManagerEditor/ServerManagerEditor.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using Base;
 using Model;
 using UnityEditor;
@@ -14,8 +13,8 @@ namespace MyEditor
 
 		private bool isAll;
 
-		private string[] appTypes = { "Manager", "Realm", "Gate" };
-		private bool[] isCheck = { false, false, false };
+		private readonly string[] serverTypes = Enum.GetNames(typeof(ServerType));
+		private bool[] isCheck;
 
 		[MenuItem("Tools/服务器管理")]
 		private static void ShowWindow()
@@ -25,6 +24,7 @@ namespace MyEditor
 
 		private void OnEnable()
 		{
+			this.isCheck = new bool[this.serverTypes.Length];
 		}
 
 		private void OnGUI()
@@ -35,6 +35,7 @@ namespace MyEditor
 				return;
 			}
 
+			
 			List<string> selected = new List<string>();
 			this.isAll = GUILayout.Toggle(this.isAll, "All");
 			if (this.isAll)
@@ -45,9 +46,9 @@ namespace MyEditor
 				}
 			}
 
-			for (int i = 0; i < this.appTypes.Length; ++i)
+			for (int i = 0; i < this.serverTypes.Length; ++i)
 			{
-				this.isCheck[i] = GUILayout.Toggle(this.isCheck[i], this.appTypes[i]);
+				this.isCheck[i] = GUILayout.Toggle(this.isCheck[i], this.serverTypes[i]);
 				if (!this.isCheck[i])
 				{
 					this.isAll = false;
@@ -62,7 +63,7 @@ namespace MyEditor
 				{
 					if (this.isCheck[i])
 					{
-						selected.Add(this.appTypes[i]);
+						selected.Add(this.serverTypes[i]);
 					}
 				}
 				NetworkComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();

+ 18 - 0
Unity/Assets/Scripts/Other/Options.cs

@@ -43,6 +43,15 @@ namespace Model
 	{
 		public string Host { get; set; }
 		public int Port { get; set; }
+
+		[BsonIgnore]
+		public string Address
+		{
+			get
+			{
+				return $"{this.Host}:{this.Port}";
+			}
+		}
 	}
 
 	[BsonIgnoreExtraElements]
@@ -50,5 +59,14 @@ namespace Model
 	{
 		public string Host { get; set; }
 		public int Port { get; set; }
+
+		[BsonIgnore]
+		public string Address
+		{
+			get
+			{
+				return $"{this.Host}:{this.Port}";
+			}
+		}
 	}
 }

+ 9 - 0
Unity/Assets/Scripts/Other/ServerType.cs

@@ -0,0 +1,9 @@
+namespace Model
+{
+	public enum ServerType
+	{
+		Manager,
+		Realm,
+		Gate,
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Other/ServerType.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: fc81138bdc09d7143ba9a3510635f70a
+timeCreated: 1477322119
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Unity.CSharp.csproj

@@ -107,6 +107,7 @@
     <Compile Include="Assets\Scripts\Message\OpcodeHelper.cs" />
     <Compile Include="Assets\Scripts\Other\BsonClassMapRegister.cs" />
     <Compile Include="Assets\Scripts\Other\ClientConfig.cs" />
+    <Compile Include="Assets\Scripts\Other\ServerType.cs" />
     <Compile Include="Assets\Scripts\Other\StartConfig.cs" />
     <Compile Include="Assets\Scripts\Other\EntityType.cs" />
     <Compile Include="Assets\Scripts\Other\GameException.cs" />