[+] 接入ET8服务端

[+] 接入ET8服务端
This commit is contained in:
ALEXTANG
2023-07-13 12:23:48 +08:00
parent e0be062006
commit 336d4b2eb9
1316 changed files with 130657 additions and 626 deletions

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46ac4bf2b7bf6ea468ccbfbf09367733
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb3ae6bd37192c648b88723824beaaa7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9517a733443387b49a227cfb10aa82d6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: