提交 7f280745 编写于 作者: T tanghai

增加服务器命令行配置工具,放在unity tool菜单下面

上级 98d57911
......@@ -17,7 +17,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;SERVER</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
......
using System;
using System.Text;
using Base;
using CommandLine;
namespace Model
{
public class Options
{
[Option("appType", Required = true, HelpText = "AppType: realm gate")]
public string AppType { get; set; }
[Option("name", Required = true, HelpText = "Name.")]
public string Name { get; set; }
[Option("protocol", Required = false, HelpText = "Protocol, tcp or udp.", DefaultValue = NetworkProtocol.UDP)]
public NetworkProtocol Protocol { get; set; }
[Option("host", Required = true, HelpText = "Host.")]
public string Host { get; set; }
[Option("port", Required = true, HelpText = "Port.")]
public int Port { get; set; }
[Option("gateHost", Required = false, HelpText = "GateHost.")]
public string GateHost { get; set; }
[Option("gatePort", Required = false, HelpText = "GatePort.")]
public int GatePort { get; set; }
[Option('v', HelpText = "Print details during execution.")]
public bool Verbose { get; set; }
[HelpOption]
public string GetUsage()
{
// this without using CommandLine.Text
StringBuilder usage = new StringBuilder();
usage.AppendLine("Quickstart Application 1.0");
usage.AppendLine("Read user manual for usage instructions...");
return usage.ToString();
}
}
[ObjectEvent]
public class OptionsComponentEvent : ObjectEvent<OptionsComponent>, IAwake<string[]>
{
......
......@@ -17,7 +17,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;SERVER</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
......@@ -71,6 +71,9 @@
<Compile Include="..\..\Unity\Assets\Scripts\Message\OpcodeHelper.cs">
<Link>Message\OpcodeHelper.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Assets\Scripts\Other\Options.cs">
<Link>Other\Options.cs</Link>
</Compile>
<Compile Include="Component\OptionsComponent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
......
fileFormatVersion: 2
guid: 7b8e880bdba621545827eea82adf63cc
folderAsset: yes
timeCreated: 1476672464
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 24f0b40b39c2f954d9e5e63bbb17f3d6
folderAsset: yes
timeCreated: 1476673759
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using Base;
using Model;
namespace MyEditor
{
public class CommandLine: ICloneable
{
public string IP = "";
public Options Options = new Options();
public object Clone()
{
return MongoHelper.FromBson<CommandLine>(MongoHelper.ToBson(this));
}
}
public class CommandLines
{
public List<CommandLine> Commands = new List<CommandLine>();
}
}
fileFormatVersion: 2
guid: 4f4981289b5c3cc4ca1604a6ba39f3a8
timeCreated: 1476674012
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 04d12359a9fbea443904bae2c7dcf115
folderAsset: yes
timeCreated: 1476673684
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Base;
using UnityEditor;
using UnityEngine;
namespace MyEditor
{
public class ServerCommandLineEditor : EditorWindow
{
private const string Path = @"..\Server\Bin\Debug\CommandLineConfig.txt";
private CommandLines commandLines;
[MenuItem("Tools/服务端命令行配置")]
static void ShowWindow()
{
GetWindow(typeof(ServerCommandLineEditor));
}
void OnEnable()
{
if (!File.Exists(Path))
{
this.commandLines = new CommandLines();
return;
}
string s = File.ReadAllText(Path);
this.commandLines = MongoHelper.FromJson<CommandLines>(s);
}
void OnGUI()
{
for (int i = 0; i < this.commandLines.Commands.Count; ++i)
{
CommandLine commandLine = this.commandLines.Commands[i];
GUILayout.BeginHorizontal();
GUILayout.Label($"IP:");
commandLine.IP = EditorGUILayout.TextField(commandLine.IP);
GUILayout.Label($"AppType:");
commandLine.Options.AppType = EditorGUILayout.TextField(commandLine.Options.AppType);
GUILayout.Label($"Name:");
commandLine.Options.Name = EditorGUILayout.TextField(commandLine.Options.Name);
GUILayout.Label($"Host:");
commandLine.Options.Host = EditorGUILayout.TextField(commandLine.Options.Host);
GUILayout.Label($"Port:");
commandLine.Options.Port = EditorGUILayout.IntField(commandLine.Options.Port);
if (GUILayout.Button("删除"))
{
this.commandLines.Commands.Remove(commandLine);
break;
}
if (GUILayout.Button("复制"))
{
CommandLine newCommandLine = (CommandLine)commandLine.Clone();
this.commandLines.Commands.Add(newCommandLine);
break;
}
GUILayout.EndHorizontal();
}
if (GUILayout.Button("添加"))
{
CommandLine commandLine = new CommandLine();
this.commandLines.Commands.Add(commandLine);
}
if (GUILayout.Button("保存"))
{
File.WriteAllText(Path, MongoHelper.ToJson(this.commandLines));
}
if (GUILayout.Button("启动"))
{
foreach (CommandLine commandLine in this.commandLines.Commands)
{
string arguments = $"--appType={commandLine.Options.AppType} --name={commandLine.Options.Name} --Host={commandLine.Options.Host} --Port={commandLine.Options.Port}";
ProcessStartInfo info = new ProcessStartInfo(@"App.exe", arguments)
{
UseShellExecute = true,
WorkingDirectory = @"..\Server\Bin\Debug"
};
Process.Start(info);
}
}
}
void OnDisable()
{
}
void OnDestroy()
{
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: f87d124589b266d41a4281a2a6ba3f63
timeCreated: 1476673528
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Text;
using Base;
#if SERVER
using CommandLine;
#endif
namespace Model
{
public class Options
{
#if SERVER
[Option("appType", Required = true, HelpText = "AppType: realm gate")]
#endif
public string AppType { get; set; }
#if SERVER
[Option("name", Required = true, HelpText = "Name.")]
#endif
public string Name { get; set; }
#if SERVER
[Option("protocol", Required = false, HelpText = "Protocol, tcp or udp.", DefaultValue = NetworkProtocol.UDP)]
#endif
public NetworkProtocol Protocol { get; set; }
#if SERVER
[Option("host", Required = true, HelpText = "Host.")]
#endif
public string Host { get; set; }
#if SERVER
[Option("port", Required = true, HelpText = "Port.")]
#endif
public int Port { get; set; }
#if SERVER
[Option("gateHost", Required = false, HelpText = "GateHost.")]
#endif
public string GateHost { get; set; }
#if SERVER
[Option("gatePort", Required = false, HelpText = "GatePort.")]
#endif
public int GatePort { get; set; }
#if SERVER
[Option('v', HelpText = "Print details during execution.")]
#endif
public bool Verbose { get; set; }
#if SERVER
[HelpOption]
#endif
public string GetUsage()
{
// this without using CommandLine.Text
StringBuilder usage = new StringBuilder();
usage.AppendLine("Quickstart Application 1.0");
usage.AppendLine("Read user manual for usage instructions...");
return usage.ToString();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 7ba4eddc4124ae740bd2d0c3208e5541
timeCreated: 1476674408
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -13,11 +13,13 @@
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Unity Full v3.5</TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<CompilerResponseFile>
</CompilerResponseFile>
<UnityProjectType>Editor:5</UnityProjectType>
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
<UnityVersion>5.4.2f1</UnityVersion>
<RootNamespace></RootNamespace>
<RootNamespace>
</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -112,10 +114,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Editor\ReferenceCollectorEditor\ReferenceCollectorEditor.cs" />
<Compile Include="Assets\Editor\ServerCommandLineEditor\Component\CommandLine.cs" />
<Compile Include="Assets\Editor\ServerCommandLineEditor\UI\ServerCommandLineEditor.cs" />
</ItemGroup>
<ItemGroup>
<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>
......@@ -103,6 +103,7 @@
<Compile Include="Assets\Scripts\Message\OpcodeHelper.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\UIType.cs" />
<Compile Include="Assets\Scripts\ReferenceCollector.cs" />
</ItemGroup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册