Esempio n. 1
0
        private static void StartMove(this MoveComponent self)
        {
            self.BeginTime = TimeHelper.ClientNow();
            self.StartTime = self.BeginTime;
            self.SetNextTarget();

            self.MoveTimer = TimerComponent.Instance.NewFrameTimer(CallbackType.MoveTimer, self);
        }
Esempio n. 2
0
        private static void StartMove(this MoveComponent self)
        {
            Unit unit = self.GetParent <Unit>();

            self.BeginTime = TimeHelper.ClientNow();
            self.StartTime = self.BeginTime;
            self.SetNextTarget();

            self.MoveTimer = TimerComponent.Instance.NewFrameTimer(TimerType.MoveTimer, self);
        }
Esempio n. 3
0
        private static void StartMove(this MoveComponent self)
        {
            Unit unit = self.GetParent <Unit>();

            self.BeginTime = TimeHelper.ClientNow();
            self.StartTime = self.BeginTime;
            self.SetNextTarget();

            self.MoveTimer = TimerComponent.Instance.NewFrameTimer(() =>
            {
                try
                {
                    self.MoveForward(false);
                }
                catch (Exception e)
                {
                    Log.Error($"move timer error: {unit.Id}\n{e}");
                }
            }
                                                                   );
        }
Esempio n. 4
0
        public static void MoveForward(this MoveComponent self, bool needCancel)
        {
            Unit unit = self.GetParent <Unit>();

            long timeNow  = TimeHelper.ClientNow();
            long moveTime = timeNow - self.StartTime;

            while (true)
            {
                if (moveTime <= 0)
                {
                    return;
                }

                // 计算位置插值
                if (moveTime >= self.NeedTime)
                {
                    unit.Position = self.NextTarget;
                    if (self.TurnTime > 0)
                    {
                        unit.Rotation = self.To;
                    }
                }
                else
                {
                    // 计算位置插值
                    float amount = moveTime * 1f / self.NeedTime;
                    if (amount > 0)
                    {
                        Vector3 newPos = Vector3.Lerp(self.StartPos, self.NextTarget, amount);
                        unit.Position = newPos;
                    }

                    // 计算方向插值
                    if (self.TurnTime > 0)
                    {
                        amount = moveTime * 1f / self.TurnTime;
                        Quaternion q = Quaternion.Slerp(self.From, self.To, amount);
                        unit.Rotation = q;
                    }
                }

                moveTime -= self.NeedTime;

                // 表示这个点还没走完,等下一帧再来
                if (moveTime < 0)
                {
                    return;
                }

                // 到这里说明这个点已经走完

                // 如果是最后一个点
                if (self.N >= self.Targets.Count - 1)
                {
                    unit.Position = self.NextTarget;
                    unit.Rotation = self.To;

                    Action <bool> callback = self.Callback;
                    self.Callback = null;

                    self.Clear();
                    callback?.Invoke(!needCancel);
                    return;
                }

                self.SetNextTarget();
            }
        }