コード例 #1
0
        public static async ETVoid MoveTo(this UnitPathComponent self, Vector3 target)
        {
            if ((self.Target - target).magnitude < 0.1f)
            {
                return;
            }

            self.Target = target;

            Unit unit = self.GetParent <Unit>();

            RecastPathComponent recastPathComponent = self.Domain.GetComponent <RecastPathComponent>();
            RecastPath          recastPath          = EntityFactory.Create <RecastPath>((Entity)self.Domain);

            recastPath.StartPos = unit.Position;
            recastPath.EndPos   = new Vector3(target.x, target.y, target.z);
            self.RecastPath     = recastPath;
            //TODO 因为目前阶段只有一张地图,所以默认mapId为10001
            recastPathComponent.SearchPath(10001, self.RecastPath);
            //Log.Debug($"------start Pos: {self.RecastPath.StartPos}\n------end Pos: {self.RecastPath.EndPos}\n------find result: {self.RecastPath.Results.ListToString()}");

            self.CancellationToken?.Cancel();
            self.CancellationToken = new ETCancellationToken();
            await self.MoveAsync(self.RecastPath.Results);

            self.CancellationToken = null;
        }
コード例 #2
0
ファイル: RecastPathProcessor.cs プロジェクト: zhu64778065/ET
 public void CalculatePath(RecastPath recastPath)
 {
     if (RecastInterface.FindPath(this.MapId, recastPath.StartPos, recastPath.EndPos))
     {
         RecastInterface.Smooth(this.MapId, 2f, 0.5f);
         {
             int     smoothCount = 0;
             float[] smooths     = RecastInterface.GetPathSmooth(this.MapId, out smoothCount);
             for (int i = 0; i < smoothCount; ++i)
             {
                 Vector3 node = new Vector3(smooths[i * 3], smooths[i * 3 + 1], smooths[i * 3 + 2]);
                 recastPath.Results.Add(node);
             }
         }
     }
 }
コード例 #3
0
ファイル: RecastPathComponent.cs プロジェクト: zhu64778065/ET
 /// <summary>
 /// 寻路
 /// </summary>
 public void SearchPath(int mapId, RecastPath recastPath)
 {
     GetRecastPathProcessor(mapId).CalculatePath(recastPath);
 }