Exemplo n.º 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;
        }
Exemplo n.º 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>();


            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;
        }
Exemplo n.º 3
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>();
        }
Exemplo n.º 4
0
        // 从index找接下来3个点,广播
        public static void BroadcastPath(this UnitPathComponent self, List <Vector3> path, int index, int offset)
        {
            Unit    unit    = self.GetParent <Unit>();
            Vector3 unitPos = unit.Position;
            M2C_PathfindingResult m2CPathfindingResult = new M2C_PathfindingResult();

            m2CPathfindingResult.X  = unitPos.x;
            m2CPathfindingResult.Y  = unitPos.y;
            m2CPathfindingResult.Z  = unitPos.z;
            m2CPathfindingResult.Id = unit.Id;
            MessageHelper.Broadcast(unit, m2CPathfindingResult);
        }
Exemplo n.º 5
0
        // 从index找接下来3个点,广播
        public static void BroadcastPath(this UnitPathComponent self, List <Vector3> path, int index, int offset)
        {
            Unit    unit    = self.GetParent <Unit>();
            Vector3 unitPos = unit.Position;
            M2C_PathfindingResult m2CPathfindingResult = new M2C_PathfindingResult();

            m2CPathfindingResult.X  = unitPos.x;
            m2CPathfindingResult.Y  = unitPos.y;
            m2CPathfindingResult.Z  = unitPos.z;
            m2CPathfindingResult.Id = unit.Id;

            for (int i = 0; i < offset; ++i)
            {
                if (index + i >= self.RecastPath.Results.Count)
                {
                    break;
                }
                Vector3 v = self.RecastPath.Results[index + i];
                m2CPathfindingResult.Xs.Add(v.x);
                m2CPathfindingResult.Ys.Add(v.y);
                m2CPathfindingResult.Zs.Add(v.z);
            }
            MessageHelper.Broadcast(self.GetParent <Unit>(), m2CPathfindingResult);
        }
Exemplo n.º 6
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>();

            unit.Position = target;

            M2C_PathfindingResult m2CPathfindingResult = new M2C_PathfindingResult();

            m2CPathfindingResult.X  = unit.Position.x;
            m2CPathfindingResult.Y  = unit.Position.y;
            m2CPathfindingResult.Z  = unit.Position.z;
            m2CPathfindingResult.Id = unit.Id;
            MessageHelper.Broadcast(unit, m2CPathfindingResult);
        }
Exemplo n.º 7
0
        private static async ETTask StartMove_Internal(this UnitPathComponent self, ETCancellationToken cancellationToken)
        {
            for (int i = 0; i < self.Path.Count; ++i)
            {
                Vector3 v = self.Path[i];

                float speed = 5;

                if (i == 0)
                {
                    // 矫正移动速度
                    Vector3 clientPos = self.GetParent <Unit>().Position;
                    float   serverf   = (self.ServerPos - v).magnitude;
                    if (serverf > 0.1f)
                    {
                        float clientf = (clientPos - v).magnitude;
                        speed = clientf / serverf * speed;
                    }
                }

                self.Parent.GetComponent <TurnComponent>().Turn(v);
                await self.Parent.GetComponent <MoveComponent>().MoveToAsync(v, speed, cancellationToken);
            }
        }