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,13 @@
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ActorMessageLocationHandler(SceneType.Map)]
|
||||
public class C2M_PathfindingResultHandler : ActorMessageLocationHandler<Unit, C2M_PathfindingResult>
|
||||
{
|
||||
protected override async ETTask Run(Unit unit, C2M_PathfindingResult message)
|
||||
{
|
||||
unit.FindPathMoveToAsync(message.Position).Coroutine();
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bedd38d8adf8fb147925d5091bdc6ec7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,12 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
[ActorMessageLocationHandler(SceneType.Map)]
|
||||
public class C2M_StopHandler: ActorMessageLocationHandler<Unit, C2M_Stop>
|
||||
{
|
||||
protected override async ETTask Run(Unit unit, C2M_Stop message)
|
||||
{
|
||||
unit.Stop(1);
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82030ce8c55952d4281c067ab368ef72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
public static partial class MoveHelper
|
||||
{
|
||||
// 可以多次调用,多次调用的话会取消上一次的协程
|
||||
public static async ETTask FindPathMoveToAsync(this Unit unit, float3 target)
|
||||
{
|
||||
float speed = unit.GetComponent<NumericComponent>().GetAsFloat(NumericType.Speed);
|
||||
if (speed < 0.01)
|
||||
{
|
||||
unit.SendStop(2);
|
||||
return;
|
||||
}
|
||||
|
||||
M2C_PathfindingResult m2CPathfindingResult = new();
|
||||
unit.GetComponent<PathfindingComponent>().Find(unit.Position, target, m2CPathfindingResult.Points);
|
||||
|
||||
if (m2CPathfindingResult.Points.Count < 2)
|
||||
{
|
||||
unit.SendStop(3);
|
||||
return;
|
||||
}
|
||||
|
||||
// 广播寻路路径
|
||||
m2CPathfindingResult.Id = unit.Id;
|
||||
MessageHelper.Broadcast(unit, m2CPathfindingResult);
|
||||
|
||||
MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
|
||||
|
||||
bool ret = await moveComponent.MoveToAsync(m2CPathfindingResult.Points, speed);
|
||||
if (ret) // 如果返回false,说明被其它移动取消了,这时候不需要通知客户端stop
|
||||
{
|
||||
unit.SendStop(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Stop(this Unit unit, int error)
|
||||
{
|
||||
unit.GetComponent<MoveComponent>().Stop(error == 0);
|
||||
unit.SendStop(error);
|
||||
}
|
||||
|
||||
// error: 0表示协程走完正常停止
|
||||
public static void SendStop(this Unit unit, int error)
|
||||
{
|
||||
MessageHelper.Broadcast(unit, new M2C_Stop()
|
||||
{
|
||||
Error = error,
|
||||
Id = unit.Id,
|
||||
Position = unit.Position,
|
||||
Rotation = unit.Rotation,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1126c2d3180a6f1419a44335fc0f0f12
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user