/// <summary> /// 服务器还需要同步Speed用于表示Entity是否移动的一个状态 /// </summary> /// <returns></returns> public override Vector3 GetServerPos() { if (positions.Count > 0) { var p1 = positions[positions.Count - 1]; var passTime = NetworkScene.Instance.GetPredictPassServerTime(p1.FrameID); var speed = NetworkUtil.FloatPos(p1.SpeedX, 0, p1.SpeedY); if (passTime > 0) { return(MobaUtil.FloatPos(p1) + speed * (passTime + Util.FrameSecTime)); } else { return(MobaUtil.FloatPos(p1) + speed * Util.FrameSecTime); } } else { return(MobaUtil.FloatPos(curInfo)); } /* * var passTime = NetworkScene.Instance.GetPredictPassServerTime(curInfo.FrameID); * //客户端跑的比服务器快 外插值 * if (passTime > 0) * { * var c = positions.Count; * if (c >= 2) * { * var p1 = positions[c - 1]; * var p0 = positions[c - 2]; * var deltaFrame = p1.FrameID - p0.FrameID; * //速度没有归0 * if (deltaFrame > 0) * { * var tm = MobaUtil.DeltaFrameToTime(deltaFrame); * var sp = MobaUtil.DeltaPos(p1, p0); * var speed = MobaUtil.Speed(sp, tm); * * //var speed = new Vector3(curInfo.SpeedX, 0, curInfo.SpeedY); * speed = Util.NetToGameVec(speed); * var extraPos = passTime * speed; * return MobaUtil.FloatPos(curInfo) + extraPos; * }else * { * return MobaUtil.FloatPos(curInfo); * } * }else * { * return MobaUtil.FloatPos(curInfo); * } * }else * { * return MobaUtil.FloatPos(curInfo); * } */ }
//迭代加权平滑 弹簧 物理运动平滑手段 private Vector3 GetInfoPredictPos(AvatarInfo p1) { var passTime = NetworkScene.Instance.GetPredictPassServerTime(p1.FrameID); var speed = NetworkUtil.FloatPos(p1.SpeedX, 0, p1.SpeedY); if (passTime > 0) { return(MobaUtil.FloatPos(p1) + speed * (passTime + Util.FrameSecTime)); } else { return(MobaUtil.FloatPos(p1) + speed * Util.FrameSecTime); } }
//预测其它玩家的控制位置 //服务器上的FrameId 都是整数 //客户端的FrameId是浮点数 //计算得到这一阵结束时候的位置 public override Vector3 GetServerPos() { if (NetworkScene.Instance != null) { if (positions.Count > 0) { return(MobaUtil.FloatPos(curInfo)); } else { return(MobaUtil.FloatPos(curInfo)); } } else { return(transform.position); } }
public override Vector3 GetCurInfoPos() { return(MobaUtil.FloatPos(curInfo)); }
public override void NetworkAttribute(GCPlayerCmd cmd) { var info = cmd.AvatarInfo; if (attr == null) { attr = GetComponent <NpcAttribute>(); } Log.Net("OtherSync: " + info); if (info == null) { Debug.LogError("NetMatchInfo is Null "); return; } NetworkMove(info); //服务器通知瞬间传送位置 if (info.ResetPos) { if (aiBase != null) { aiBase.GetAI().ChangeState(AIStateEnum.IDLE); } var netPos = MobaUtil.FloatPos(info); transform.position = netPos; positions.Clear(); } if (info.HasTeamColor) { attr.SetTeamColorNet(info.TeamColor); curInfo.TeamColor = info.TeamColor; } if (info.HasIsMaster) { attr.SetIsMasterNet(info.IsMaster); curInfo.IsMaster = info.IsMaster; } var dataChanged = false; var skillCount = curInfo.KillCount; if (info.HasKillCount) { skillCount = info.KillCount; curInfo.KillCount = info.KillCount; dataChanged = true; } var deadCount = curInfo.DeadCount; if (info.HasDeadCount) { deadCount = info.DeadCount; curInfo.DeadCount = info.DeadCount; dataChanged = true; } var secondaryAttackCount = curInfo.SecondaryAttackCount; if (info.HasSecondaryAttackCount) { secondaryAttackCount = info.SecondaryAttackCount; curInfo.SecondaryAttackCount = info.SecondaryAttackCount; dataChanged = true; } if (info.HasScore) { curInfo.Score = info.Score; dataChanged = true; } if (dataChanged) { var sid = attr.GetNetView().GetServerID(); ScoreManager.Instance.NetSyncScore(sid, curInfo.Score, sid, skillCount, deadCount, secondaryAttackCount); } if (info.HasContinueKilled) { curInfo.ContinueKilled = info.ContinueKilled; if (curInfo.ContinueKilled > 0) { } } if (info.HasPlayerModelInGame && curInfo.PlayerModelInGame != info.PlayerModelInGame) { curInfo.PlayerModelInGame = info.PlayerModelInGame; GetComponent <MobaModelLoader>().LoadModel(curInfo.PlayerModelInGame); var unitData = Util.GetUnitData(true, curInfo.PlayerModelInGame, 0); attr.SetObjUnitData(unitData); //SkillDataController.skillDataController.InitSkillShotAfterSelectSkill(curInfo.PlayerModelInGame); } if (info.HasHP) { curInfo.HP = info.HP; attr.SetHPNet(info.HP); } if (info.HasLevel) { curInfo.Level = info.Level; attr.ChangeLevel(info.Level); } if (info.HasState) { curInfo.State = info.State; } }
public override Vector3 GetCurInfoSpeed() { return(MobaUtil.FloatPos(new Vector3(curInfo.SpeedX, 0, curInfo.SpeedY))); }