Просмотр исходного кода

增加客户端配置编辑器

tanghai 9 лет назад
Родитель
Сommit
961fa53a13

+ 2 - 2
Unity/Assets/Editor/ServerCommandLineEditor/Component.meta → Unity/Assets/Editor/ClientConfigEditor.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
-guid: 24f0b40b39c2f954d9e5e63bbb17f3d6
+guid: 44f2bb6ff888c0b4c82e9e5434888b58
 folderAsset: yes
-timeCreated: 1476673759
+timeCreated: 1477315157
 licenseType: Pro
 DefaultImporter:
   userData: 

+ 60 - 0
Unity/Assets/Editor/ClientConfigEditor/ClientConfigEditor.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using Base;
+using Model;
+using UnityEditor;
+using UnityEngine;
+
+namespace MyEditor
+{
+	public class ClientConfigEditor : EditorWindow
+	{
+		private const string Path = "./ClientConfig.txt";
+
+		private ClientConfig config;
+
+		[MenuItem("Tools/客户端配置")]
+		private static void ShowWindow()
+		{
+			GetWindow(typeof(ClientConfigEditor));
+		}
+
+		private void OnEnable()
+		{
+			if (!File.Exists(Path))
+			{
+				this.config = new ClientConfig();
+				return;
+			}
+
+			string s = File.ReadAllText(Path);
+			this.config = MongoHelper.FromJson<ClientConfig>(s);
+		}
+
+		private void OnGUI()
+		{
+			this.config.Host = EditorGUILayout.TextField("地址: ", this.config.Host);
+			this.config.Port = EditorGUILayout.IntField("端口: ", this.config.Port);
+
+			GUILayout.BeginHorizontal();
+
+			if (GUILayout.Button("保存"))
+			{
+				using (StreamWriter sw = new StreamWriter(new FileStream(Path, FileMode.Create)))
+				{
+					sw.Write(MongoHelper.ToJson(this.config));
+				}
+			}
+		}
+
+		private void OnDisable()
+		{
+		}
+
+		private void OnDestroy()
+		{
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Editor/ClientConfigEditor/ClientConfigEditor.cs.meta

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

+ 25 - 0
Unity/Assets/Scripts/Component/ClientConfigComponent.cs

@@ -0,0 +1,25 @@
+using System.IO;
+using Base;
+
+namespace Model
+{
+	[ObjectEvent]
+	public class ClientConfigComponentEvent : ObjectEvent<ClientConfigComponent>, IAwake
+	{
+		public void Awake()
+		{
+			this.GetValue().Awake();
+		}
+	}
+
+	public class ClientConfigComponent : Component
+    {
+		public ClientConfig Config { get; private set; }
+
+		public void Awake()
+		{
+			string s = File.ReadAllText("./ClientConfig.txt");
+			this.Config = MongoHelper.FromJson<ClientConfig>(s);
+		}
+    }
+}

+ 12 - 0
Unity/Assets/Scripts/Component/ClientConfigComponent.cs.meta

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

+ 9 - 0
Unity/Assets/Scripts/Message/Message.cs

@@ -7,7 +7,9 @@ namespace Model
 	[BsonIgnoreExtraElements]
 	public class C2R_Login: ARequest
 	{
+		[BsonElement("a")]
 		public string Account;
+		[BsonElement("p")]
 		public string Password;
 	}
 
@@ -15,7 +17,9 @@ namespace Model
 	[BsonIgnoreExtraElements]
 	public class R2C_Login: AResponse
 	{
+		[BsonElement("a")]
 		public string Address { get; set; }
+		[BsonElement("k")]
 		public long Key { get; set; }
 	}
 
@@ -23,9 +27,13 @@ namespace Model
 	[BsonIgnoreExtraElements]
 	public class R2C_ServerLog: AMessage
 	{
+		[BsonElement("at")]
 		public string AppType { get; set; }
+		[BsonElement("a")]
 		public int AppId { get; set; }
+		[BsonElement("t")]
 		public LogType Type { get; set; }
+		[BsonElement("l")]
 		public string Log { get; set; }
 	}
 
@@ -63,6 +71,7 @@ namespace Model
 	[BsonIgnoreExtraElements]
 	public class C2G_LoginGate : ARequest
 	{
+		[BsonElement("k")]
 		public long Key;
 
 		public C2G_LoginGate(long key)

+ 8 - 0
Unity/Assets/Scripts/Other/ClientConfig.cs

@@ -0,0 +1,8 @@
+namespace Model
+{
+	public class ClientConfig
+	{
+		public string Host = "";
+		public int Port;
+	}
+}

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

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

+ 1 - 0
Unity/ClientConfig.txt

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

+ 2 - 1
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs

@@ -13,8 +13,9 @@ namespace Controller
 		public async void Run()
 		{
 			Game.Scene.AddComponent<MessageDispatherComponent, string>("Client");
+			ClientConfig clientConfig = Game.Scene.AddComponent<ClientConfigComponent>().Config;
 			NetworkComponent networkComponent = Game.Scene.AddComponent<NetOuterComponent>();
-			Entity session = networkComponent.Get("192.168.12.188:10003");
+			Entity session = networkComponent.Get($"{clientConfig.Host}:{clientConfig.Port}");
 
 			try
 			{

+ 1 - 0
Unity/Unity.CSharp.Editor.csproj

@@ -113,6 +113,7 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Assets\Editor\ClientConfigEditor\ClientConfigEditor.cs" />
     <Compile Include="Assets\Editor\EditorInit.cs" />
     <Compile Include="Assets\Editor\ObjectManagerToolsEditor\ObjectManagerToolsWindow.cs" />
     <Compile Include="Assets\Editor\ReferenceCollectorEditor\ReferenceCollectorEditor.cs" />

+ 2 - 0
Unity/Unity.CSharp.csproj

@@ -81,6 +81,7 @@
   <ItemGroup>
     <Compile Include="Assets\Scripts\Component\ChildrenComponent.cs" />
     <Compile Include="Assets\Scripts\Component\EventComponent.cs" />
+    <Compile Include="Assets\Scripts\Component\ClientConfigComponent.cs" />
     <Compile Include="Assets\Scripts\Component\GameObjectComponent.cs" />
     <Compile Include="Assets\Scripts\Component\GlobalConfigComponent.cs" />
     <Compile Include="Assets\Scripts\Component\KVComponent.cs" />
@@ -105,6 +106,7 @@
     <Compile Include="Assets\Scripts\Message\Message.cs" />
     <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\StartConfig.cs" />
     <Compile Include="Assets\Scripts\Other\EntityType.cs" />
     <Compile Include="Assets\Scripts\Other\GameException.cs" />