50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
[ActorMessageHandler]
|
|
public class Frame_ClickMapHandler: AMActorLocationHandler<Unit, Frame_ClickMap>
|
|
{
|
|
protected override async ETTask Run(Unit unit, Frame_ClickMap message)
|
|
{
|
|
if (!unit.IsTeamLeader) return;
|
|
if (unit.teamState != TeamState.None) return;
|
|
if (unit.isAI) return;
|
|
Vector2 target = new(message.UnitInfo.X, message.UnitInfo.Y);
|
|
MoveToTarget(unit, target, message.UnitInfo.YAngle).Coroutine();
|
|
await ETTask.CompletedTask;
|
|
}
|
|
|
|
private async ETVoid MoveToTarget(Unit unit, Vector2 target, int yAngle)
|
|
{
|
|
try
|
|
{
|
|
MoveHelper.MoveTo(unit, target, yAngle).Coroutine();
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
|
|
var list=team.GetUnits();
|
|
for (var curr = list.First; curr!=null;curr=curr.Next)
|
|
{
|
|
var item = curr.Value;
|
|
if (item.IsTeamLeader)
|
|
continue;
|
|
long unitInstanceId = item.InstanceId;
|
|
await TimerComponent.Instance.WaitAsync(300);
|
|
if (!item)
|
|
continue;
|
|
if (unitInstanceId != item.InstanceId) continue;
|
|
UnitScene unitScene = item.GetComponent<UnitScene>();
|
|
Vector2 delta = MoveHelper.CalucateDistanceXandY(unitScene.Position, target);
|
|
int index = team.GetIndex(item.Id);
|
|
Vector2 targetPos = new(target.x - delta.x * index, target.y - delta.y * index);
|
|
MoveHelper.MoveTo(item, targetPos).Coroutine(); // 移动到目标点, 返回false表示协程取消
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
}
|
|
} |