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,47 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
[EntitySystemOf(typeof(ClientSenderCompnent))]
|
||||
[FriendOf(typeof(ClientSenderCompnent))]
|
||||
public static partial class ClientSenderCompnentSystem
|
||||
{
|
||||
[EntitySystem]
|
||||
private static void Awake(this ClientSenderCompnent self)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[EntitySystem]
|
||||
private static void Destroy(this ClientSenderCompnent self)
|
||||
{
|
||||
if (self.fiberId != 0)
|
||||
{
|
||||
FiberManager.Instance.Remove(self.fiberId);
|
||||
}
|
||||
}
|
||||
|
||||
public static async ETTask<long> LoginAsync(this ClientSenderCompnent self, string account, string password)
|
||||
{
|
||||
self.fiberId = await FiberManager.Instance.Create(SchedulerType.ThreadPool, 0, SceneType.NetClient, "");
|
||||
self.netClientActorId = new ActorId(self.Fiber().Process, self.fiberId);
|
||||
|
||||
NetClient2Main_Login response = await self.Fiber().ActorInnerComponent.Call(self.netClientActorId, new Main2NetClient_Login() { Account = account, Password = password }) as NetClient2Main_Login;
|
||||
return response.PlayerId;
|
||||
}
|
||||
|
||||
public static void Send(this ClientSenderCompnent self, IMessage message)
|
||||
{
|
||||
A2NetClient_Message a2NetClientMessage = A2NetClient_Message.Create();
|
||||
a2NetClientMessage.MessageObject = message;
|
||||
self.Fiber().ActorInnerComponent.Send(self.netClientActorId, a2NetClientMessage);
|
||||
}
|
||||
|
||||
public static async ETTask<IResponse> Call(this ClientSenderCompnent self, IRequest request, bool needException = true)
|
||||
{
|
||||
A2NetClient_Request a2NetClientRequest = A2NetClient_Request.Create();
|
||||
a2NetClientRequest.MessageObject = request;
|
||||
A2NetClient_Response response = await self.Fiber().ActorInnerComponent.Call(self.netClientActorId, a2NetClientRequest, needException: needException) as A2NetClient_Response;
|
||||
return response.MessageObject;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a11bff036359a2143aca1de23150ce40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c38213e2fca6b8b489ffb3fee170c51f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace ET.Client
|
||||
{
|
||||
public static partial class EnterMapHelper
|
||||
{
|
||||
public static async ETTask EnterMapAsync(Scene root)
|
||||
{
|
||||
try
|
||||
{
|
||||
G2C_EnterMap g2CEnterMap = await root.GetComponent<ClientSenderCompnent>().Call(new C2G_EnterMap()) as G2C_EnterMap;
|
||||
|
||||
// 等待场景切换完成
|
||||
await root.GetComponent<ObjectWait>().Wait<Wait_SceneChangeFinish>();
|
||||
|
||||
EventSystem.Instance.Publish(root, new EventType.EnterMapFinish());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static async ETTask Match(Fiber fiber)
|
||||
{
|
||||
try
|
||||
{
|
||||
G2C_Match g2CEnterMap = await fiber.Root.GetComponent<ClientSenderCompnent>().Call(new C2G_Match()) as G2C_Match;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25a13c7e1f3127848a33352576e747c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e5f376ea66398e4f8d5fc5d700b4373
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
[ActorMessageHandler(SceneType.Demo)]
|
||||
public class M2C_PathfindingResultHandler : ActorMessageHandler<Scene, M2C_PathfindingResult>
|
||||
{
|
||||
protected override async ETTask Run(Scene root, M2C_PathfindingResult message)
|
||||
{
|
||||
Unit unit = root.CurrentScene().GetComponent<UnitComponent>().Get(message.Id);
|
||||
|
||||
float speed = unit.GetComponent<NumericComponent>().GetAsFloat(NumericType.Speed);
|
||||
|
||||
await unit.GetComponent<MoveComponent>().MoveToAsync(message.Points, speed);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46ac4bf2b7bf6ea468ccbfbf09367733
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,24 @@
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Client
|
||||
{
|
||||
[ActorMessageHandler(SceneType.Demo)]
|
||||
public class M2C_StopHandler : ActorMessageHandler<Scene, M2C_Stop>
|
||||
{
|
||||
protected override async ETTask Run(Scene root, M2C_Stop message)
|
||||
{
|
||||
Unit unit = root.CurrentScene().GetComponent<UnitComponent>().Get(message.Id);
|
||||
if (unit == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
|
||||
moveComponent.Stop(message.Error == 0);
|
||||
unit.Position = message.Position;
|
||||
unit.Rotation = message.Rotation;
|
||||
unit.GetComponent<ObjectWait>()?.Notify(new Wait_UnitStop() {Error = message.Error});
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb3ae6bd37192c648b88723824beaaa7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Client
|
||||
{
|
||||
public static partial class MoveHelper
|
||||
{
|
||||
// 可以多次调用,多次调用的话会取消上一次的协程
|
||||
public static async ETTask<int> MoveToAsync(this Unit unit, float3 targetPos, ETCancellationToken cancellationToken = null)
|
||||
{
|
||||
C2M_PathfindingResult msg = new C2M_PathfindingResult() { Position = targetPos };
|
||||
unit.Root().GetComponent<ClientSenderCompnent>().Send(msg);
|
||||
|
||||
ObjectWait objectWait = unit.GetComponent<ObjectWait>();
|
||||
|
||||
// 要取消上一次的移动协程
|
||||
objectWait.Notify(new Wait_UnitStop() { Error = WaitTypeError.Cancel });
|
||||
|
||||
// 一直等到unit发送stop
|
||||
Wait_UnitStop waitUnitStop = await objectWait.Wait<Wait_UnitStop>(cancellationToken);
|
||||
if (cancellationToken.IsCancel())
|
||||
{
|
||||
return WaitTypeError.Cancel;
|
||||
}
|
||||
return waitUnitStop.Error;
|
||||
}
|
||||
|
||||
public static async ETTask MoveToAsync(this Unit unit, List<float3> path)
|
||||
{
|
||||
float speed = unit.GetComponent<NumericComponent>().GetAsFloat(NumericType.Speed);
|
||||
MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
|
||||
await moveComponent.MoveToAsync(path, speed);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9517a733443387b49a227cfb10aa82d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,12 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
[ActorMessageHandler(SceneType.All)]
|
||||
public class NetClient2Main_SessionDisposeHandler: ActorMessageHandler<Scene, NetClient2Main_SessionDispose>
|
||||
{
|
||||
protected override async ETTask Run(Scene entity, NetClient2Main_SessionDispose message)
|
||||
{
|
||||
Log.Error($"session dispose, error: {message.Error}");
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fbd99f39ddd82042af56cdbf9ce8dc3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d507c6bfa0e3424380311d17689451c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,14 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
public static class CurrentSceneFactory
|
||||
{
|
||||
public static Scene Create(long id, string name, CurrentScenesComponent currentScenesComponent)
|
||||
{
|
||||
Scene currentScene = EntitySceneFactory.CreateScene(currentScenesComponent, id, currentScenesComponent.Fiber().IdGenerater.GenerateInstanceId(), SceneType.Current, name);
|
||||
currentScenesComponent.Scene = currentScene;
|
||||
|
||||
EventSystem.Instance.Publish(currentScene, new EventType.AfterCreateCurrentScene());
|
||||
return currentScene;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7e7628945100a44193d11f6c86856fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,11 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
[ActorMessageHandler(SceneType.Demo)]
|
||||
public class M2C_StartSceneChangeHandler : ActorMessageHandler<Scene, M2C_StartSceneChange>
|
||||
{
|
||||
protected override async ETTask Run(Scene root, M2C_StartSceneChange message)
|
||||
{
|
||||
await SceneChangeHelper.SceneChangeTo(root, message.SceneName, message.SceneInstanceId);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ba66d6939e13bc47b59fe326cac0526
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,29 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
public static partial class SceneChangeHelper
|
||||
{
|
||||
// 场景切换协程
|
||||
public static async ETTask SceneChangeTo(Scene root, string sceneName, long sceneInstanceId)
|
||||
{
|
||||
root.RemoveComponent<AIComponent>();
|
||||
|
||||
CurrentScenesComponent currentScenesComponent = root.GetComponent<CurrentScenesComponent>();
|
||||
currentScenesComponent.Scene?.Dispose(); // 删除之前的CurrentScene,创建新的
|
||||
Scene currentScene = CurrentSceneFactory.Create(sceneInstanceId, sceneName, currentScenesComponent);
|
||||
UnitComponent unitComponent = currentScene.AddComponent<UnitComponent>();
|
||||
|
||||
// 可以订阅这个事件中创建Loading界面
|
||||
EventSystem.Instance.Publish(root, new EventType.SceneChangeStart());
|
||||
// 等待CreateMyUnit的消息
|
||||
Wait_CreateMyUnit waitCreateMyUnit = await root.GetComponent<ObjectWait>().Wait<Wait_CreateMyUnit>();
|
||||
M2C_CreateMyUnit m2CCreateMyUnit = waitCreateMyUnit.Message;
|
||||
Unit unit = UnitFactory.Create(currentScene, m2CCreateMyUnit.Unit);
|
||||
unitComponent.Add(unit);
|
||||
root.RemoveComponent<AIComponent>();
|
||||
|
||||
EventSystem.Instance.Publish(currentScene, new EventType.SceneChangeFinish());
|
||||
// 通知等待场景切换的协程
|
||||
root.GetComponent<ObjectWait>().Notify(new Wait_SceneChangeFinish());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eff9697e3de79f54dbfd7996f55c6f47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b99fb42c78388f147beaf9a963a80458
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,13 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
[ActorMessageHandler(SceneType.Demo)]
|
||||
public class M2C_CreateMyUnitHandler: ActorMessageHandler<Scene, M2C_CreateMyUnit>
|
||||
{
|
||||
protected override async ETTask Run(Scene root, M2C_CreateMyUnit message)
|
||||
{
|
||||
// 通知场景切换协程继续往下走
|
||||
root.GetComponent<ObjectWait>().Notify(new Wait_CreateMyUnit() {Message = message});
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69fc464a314f79d46922ca7c44dad617
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,22 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
[ActorMessageHandler(SceneType.Demo)]
|
||||
public class M2C_CreateUnitsHandler: ActorMessageHandler<Scene, M2C_CreateUnits>
|
||||
{
|
||||
protected override async ETTask Run(Scene root, M2C_CreateUnits message)
|
||||
{
|
||||
Scene currentScene = root.CurrentScene();
|
||||
UnitComponent unitComponent = currentScene.GetComponent<UnitComponent>();
|
||||
|
||||
foreach (UnitInfo unitInfo in message.Units)
|
||||
{
|
||||
if (unitComponent.Get(unitInfo.UnitId) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Unit unit = UnitFactory.Create(currentScene, unitInfo);
|
||||
}
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b8fc07def7b312469c243c3ccad1b39
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
[ActorMessageHandler(SceneType.Demo)]
|
||||
public class M2C_RemoveUnitsHandler: ActorMessageHandler<Scene, M2C_RemoveUnits>
|
||||
{
|
||||
protected override async ETTask Run(Scene root, M2C_RemoveUnits message)
|
||||
{
|
||||
UnitComponent unitComponent = root.CurrentScene()?.GetComponent<UnitComponent>();
|
||||
if (unitComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (long unitId in message.Units)
|
||||
{
|
||||
unitComponent.Remove(unitId);
|
||||
}
|
||||
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c4d413c1206d8844b7f6ccc95dd2ce6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,41 @@
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Client
|
||||
{
|
||||
public static partial class UnitFactory
|
||||
{
|
||||
public static Unit Create(Scene currentScene, UnitInfo unitInfo)
|
||||
{
|
||||
UnitComponent unitComponent = currentScene.GetComponent<UnitComponent>();
|
||||
Unit unit = unitComponent.AddChildWithId<Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);
|
||||
unitComponent.Add(unit);
|
||||
|
||||
unit.Position = unitInfo.Position;
|
||||
unit.Forward = unitInfo.Forward;
|
||||
|
||||
NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
|
||||
|
||||
foreach (var kv in unitInfo.KV)
|
||||
{
|
||||
numericComponent.Set(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
unit.AddComponent<MoveComponent>();
|
||||
if (unitInfo.MoveInfo != null)
|
||||
{
|
||||
if (unitInfo.MoveInfo.Points.Count > 0)
|
||||
{
|
||||
unitInfo.MoveInfo.Points[0] = unit.Position;
|
||||
unit.MoveToAsync(unitInfo.MoveInfo.Points).Coroutine();
|
||||
}
|
||||
}
|
||||
|
||||
unit.AddComponent<ObjectWait>();
|
||||
|
||||
unit.AddComponent<XunLuoPathComponent>();
|
||||
|
||||
EventSystem.Instance.Publish(unit.Scene(), new EventType.AfterUnitCreate() {Unit = unit});
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f76a73cf5e806e9499c3eb92aeeb46d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,18 @@
|
||||
namespace ET.Client
|
||||
{
|
||||
public static partial class UnitHelper
|
||||
{
|
||||
public static Unit GetMyUnitFromClientScene(Scene root)
|
||||
{
|
||||
PlayerComponent playerComponent = root.GetComponent<PlayerComponent>();
|
||||
Scene currentScene = root.GetComponent<CurrentScenesComponent>().Scene;
|
||||
return currentScene.GetComponent<UnitComponent>().Get(playerComponent.MyId);
|
||||
}
|
||||
|
||||
public static Unit GetMyUnitFromCurrentScene(Scene currentScene)
|
||||
{
|
||||
PlayerComponent playerComponent = currentScene.Root().GetComponent<PlayerComponent>();
|
||||
return currentScene.GetComponent<UnitComponent>().Get(playerComponent.MyId);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90e53c0be7b8aab4c827ed76d193ca42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user