コード例 #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>();


            PathfindingComponent pathfindingComponent = self.Domain.GetComponent <PathfindingComponent>();

            self.ABPath = EntityFactory.Create <ABPathWrap, Vector3, Vector3>(self.Domain, unit.Position, new Vector3(target.x, target.y, target.z));
            pathfindingComponent.Search(self.ABPath);
            Log.Debug($"find result: {self.ABPath.Result.ListToString()}");

            self.CancellationTokenSource?.Cancel();
            self.CancellationTokenSource = EntityFactory.Create <ETCancellationTokenSource>(self.Domain);
            await self.MoveAsync(self.ABPath.Result);

            self.CancellationTokenSource.Dispose();
            self.CancellationTokenSource = null;
        }
コード例 #2
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;
        }