mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
[EntitySystemOf(typeof(ConsoleComponent))]
|
||||
[FriendOf(typeof(ConsoleComponent))]
|
||||
[FriendOf(typeof(ModeContex))]
|
||||
public static partial class ConsoleComponentSystem
|
||||
{
|
||||
[EntitySystem]
|
||||
private static void Awake(this ConsoleComponent self)
|
||||
{
|
||||
self.Start().Coroutine();
|
||||
}
|
||||
|
||||
|
||||
private static async ETTask Start(this ConsoleComponent self)
|
||||
{
|
||||
self.CancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
ModeContex modeContex = self.GetComponent<ModeContex>();
|
||||
string line = await Task.Factory.StartNew(() =>
|
||||
{
|
||||
Console.Write($"{modeContex?.Mode ?? ""}> ");
|
||||
return Console.In.ReadLine();
|
||||
}, self.CancellationTokenSource.Token);
|
||||
|
||||
line = line.Trim();
|
||||
|
||||
switch (line)
|
||||
{
|
||||
case "":
|
||||
break;
|
||||
case "exit":
|
||||
self.RemoveComponent<ModeContex>();
|
||||
break;
|
||||
default:
|
||||
{
|
||||
string[] lines = line.Split(" ");
|
||||
string mode = modeContex == null? lines[0] : modeContex.Mode;
|
||||
|
||||
IConsoleHandler iConsoleHandler = ConsoleDispatcher.Instance.Get(mode);
|
||||
if (modeContex == null)
|
||||
{
|
||||
modeContex = self.AddComponent<ModeContex>();
|
||||
modeContex.Mode = mode;
|
||||
}
|
||||
await iConsoleHandler.Run(self.Fiber(), modeContex, line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Console(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bdd9b39878d7e04685a85d38bc88950
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
[ConsoleHandler(ConsoleMode.ReloadConfig)]
|
||||
public class ReloadConfigConsoleHandler: IConsoleHandler
|
||||
{
|
||||
public async ETTask Run(Fiber fiber, ModeContex contex, string content)
|
||||
{
|
||||
switch (content)
|
||||
{
|
||||
case ConsoleMode.ReloadConfig:
|
||||
contex.Parent.RemoveComponent<ModeContex>();
|
||||
Log.Console("C must have config name, like: C UnitConfig");
|
||||
break;
|
||||
default:
|
||||
string[] ss = content.Split(" ");
|
||||
string configName = ss[1];
|
||||
string category = $"{configName}Category";
|
||||
Type type = EventSystem.Instance.GetType($"ET.{category}");
|
||||
if (type == null)
|
||||
{
|
||||
Log.Console($"reload config but not find {category}");
|
||||
return;
|
||||
}
|
||||
ConfigComponent.Instance.Reload(type);
|
||||
Log.Console($"reload config {configName} finish!");
|
||||
break;
|
||||
}
|
||||
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bf64d72d2f1cc445ad8fb13eeef331b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,12 @@
|
||||
namespace ET
|
||||
{
|
||||
[ConsoleHandler(ConsoleMode.ReloadDll)]
|
||||
public class ReloadDllConsoleHandler: IConsoleHandler
|
||||
{
|
||||
public async ETTask Run(Fiber fiber, ModeContex contex, string content)
|
||||
{
|
||||
await ETTask.CompletedTask;
|
||||
CodeLoader.Instance.LoadHotfix();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffe8f82cde98483438673415feab109a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user