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,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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user