Пример #1
0
        public static async void 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 = new CancellationTokenSource();
            await self.MoveAsync(self.ABPath.Result);

            self.CancellationTokenSource.Dispose();
            self.CancellationTokenSource = null;
        }
Пример #2
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.ABPath.Result.Count)
                {
                    break;
                }
                Vector3 v = self.ABPath.Result[index + i];
                m2CPathfindingResult.Xs.Add(v.x);
                m2CPathfindingResult.Ys.Add(v.y);
                m2CPathfindingResult.Zs.Add(v.z);
            }
            MessageHelper.Broadcast(unit, m2CPathfindingResult);
        }