Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
 public static bool IsArrived(this MoveComponent self)
 {
     return(self.Targets.Count == 0);
 }
Exemplo n.º 3
0
        public static UnitInfo CreateUnitInfo(Unit unit)
        {
            UnitInfo unitInfo = new UnitInfo();

            unitInfo.UnitId   = unit.Id;
            unitInfo.ConfigId = unit.ConfigId;
            unitInfo.Type     = (int)unit.Type;
            Vector3 position = unit.Position;

            unitInfo.X = position.x;
            unitInfo.Y = position.y;
            unitInfo.Z = position.z;
            Vector3 forward = unit.Forward;

            unitInfo.ForwardX = forward.x;
            unitInfo.ForwardY = forward.y;
            unitInfo.ForwardZ = forward.z;

            #region 移动信息
            MoveComponent moveComponent = unit.GetComponent <MoveComponent>();
            if (moveComponent != null)
            {
                if (!moveComponent.IsArrived())
                {
                    unitInfo.MoveInfo = new MoveInfo();
                    for (int i = moveComponent.N; i < moveComponent.Targets.Count; ++i)
                    {
                        Vector3 pos = moveComponent.Targets[i];
                        unitInfo.MoveInfo.X.Add(pos.x);
                        unitInfo.MoveInfo.Y.Add(pos.y);
                        unitInfo.MoveInfo.Z.Add(pos.z);
                    }
                }
            }


            #endregion

            #region 数值信息

            NumericComponent nc = unit.GetComponent <NumericComponent>();
            if (nc != null)
            {
                foreach ((int key, long value) in nc.NumericDic)
                {
                    if (key > NumericType.Max) //不需要同步最终值
                    {
                        unitInfo.Ks.Add(key);
                        unitInfo.Vs.Add(value);
                    }
                }
            }
            #endregion

            #region 战斗数据

            var cuc = unit.GetComponent <CombatUnitComponent>();
            if (cuc != null)
            {
                //技能
                unitInfo.SkillIds.AddRange(cuc.IdSkillMap.Keys);
                var buffC = cuc.GetComponent <BuffComponent>();
                if (buffC != null)
                {
                    foreach (var item in buffC.Groups)
                    {
                        var buff = item.Value;
                        unitInfo.BuffIds.Add(buff.ConfigId);
                        unitInfo.BuffTimestamp.Add(buff.Timestamp);
                    }
                }
            }

            #endregion


            return(unitInfo);
        }
Exemplo n.º 4
0
 private static Vector3 GetFaceV(this MoveComponent self)
 {
     return(self.NextTarget - self.PreTarget);
 }