1
This commit is contained in:
@@ -170,6 +170,9 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
float clickTime = 0;
|
||||
private Dictionary<int, float> botFireTimer = new Dictionary<int, float>();
|
||||
private Dictionary<string, float> botLastAngle = new Dictionary<string, float>();
|
||||
// bot 旋转广播节流:记录上次广播的角度/时间
|
||||
private Dictionary<int, float> botLastSyncAngle = new Dictionary<int, float>();
|
||||
private Dictionary<int, float> botLastSyncTime = new Dictionary<int, float>();
|
||||
// bot 技能运行时
|
||||
private Dictionary<int, BotSkillRuntime> botSkills = new Dictionary<int, BotSkillRuntime>();
|
||||
// bot 目标记忆
|
||||
@@ -213,7 +216,7 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
int l = GameManager.Instance.gameData.currRoomData.roomLevel;
|
||||
foreach (var item in GameManager.Instance.gameConfig.roomConfigs)
|
||||
{
|
||||
if (item.gameType == t && l == GameManager.Instance.gameData.currRoomData.roomLevel)
|
||||
if (item.gameType == t && l == item.roomLevel)
|
||||
{
|
||||
paoBeiList = item.cannonMultipleList;
|
||||
}
|
||||
@@ -368,7 +371,6 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
{
|
||||
base.OnHide();
|
||||
|
||||
|
||||
UnLoadResources();
|
||||
// 场景可能未加载或已卸载,做保护避免重复卸载报错
|
||||
var scene = SceneManager.GetSceneByName(sceneName);
|
||||
@@ -623,6 +625,7 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
|
||||
}
|
||||
int ina = 0;
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
||||
@@ -1030,38 +1033,15 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
float angle = currSitData.IsFlipped ? (autoRotateAngle + 180f) % 360f : autoRotateAngle;
|
||||
currSitData.SetRotation(angle);
|
||||
}
|
||||
private Coroutine rotateCoroutine;
|
||||
|
||||
/// <summary>
|
||||
/// 远程玩家/bot 旋转:直接把目标角度赋给炮台,不做任何过渡。
|
||||
/// 旋转和开炮都改成实时同步,收到广播立即应用。
|
||||
/// </summary>
|
||||
private void SmoothRotate(SitPosData sit, float angle)
|
||||
{
|
||||
sit.SetRotation(angle); // 先立即更新角度(逻辑角度)
|
||||
if (rotateCoroutine != null)
|
||||
StopCoroutine(rotateCoroutine);
|
||||
|
||||
rotateCoroutine = StartCoroutine(RotateIE_Angle(sit, Quaternion.Euler(0, 0, angle)));
|
||||
}
|
||||
|
||||
private IEnumerator RotateIE_Angle(SitPosData sit, Quaternion target)
|
||||
{
|
||||
float angleThreshold = 0.1f;
|
||||
|
||||
while (true)
|
||||
{
|
||||
float angleDiff = Quaternion.Angle(sit.tra_CurrTurret.rotation, target);
|
||||
if (angleDiff <= angleThreshold)
|
||||
{
|
||||
sit.tra_CurrTurret.rotation = target;
|
||||
yield break;
|
||||
}
|
||||
|
||||
sit.tra_CurrTurret.rotation = Quaternion.Lerp(
|
||||
sit.tra_CurrTurret.rotation,
|
||||
target,
|
||||
0.6f
|
||||
);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
if (sit == null || sit.tra_CurrTurret == null) return;
|
||||
sit.SetRotation(angle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1897,8 +1877,13 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
{
|
||||
if (sync.sitPos == currSitData.posID) return;
|
||||
|
||||
var sit = list_Sits[sync.sitPos];
|
||||
// ⭐ 房主不处理机器人旋转广播:房主在 RotateBotToTarget 里已直接旋转本地炮台,
|
||||
// 再走 SmoothRotate 会和本地直接旋转冲突
|
||||
if (sit != null && sit.isBot && currSitData == SitPosData.roomOwnerSit) return;
|
||||
|
||||
var data = FrameDataParser.Parse<FrameData_Rotate>(sync.frameData);
|
||||
SmoothRotate(list_Sits[sync.sitPos], data.angle);
|
||||
SmoothRotate(sit, data.angle);
|
||||
}
|
||||
|
||||
public void SyncGameData_FireBullit(FireCannonSendData sync)
|
||||
@@ -1981,11 +1966,15 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
{
|
||||
var data = JsonConvert.DeserializeObject<FrameData_RandomDieFish>(sync.frameData.ToString());
|
||||
|
||||
// 用 sync.sitPos 判断是否本地玩家发的(服务器不会丢这个字段)
|
||||
bool isLocalSender = sync.sitPos == currSitData.posID;
|
||||
|
||||
CreateFishManager.Instance.Id_DieListFish_FX(
|
||||
data.guids,
|
||||
data.coinNum,
|
||||
new Vector3(data.x, data.y, data.z),
|
||||
data.count
|
||||
data.count,
|
||||
isLocalSender
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2750,7 +2739,7 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
s.doubleEndTime = Time.time + Random.Range(skillCfg.doubleMinTime, skillCfg.doubleMaxTime);
|
||||
}
|
||||
|
||||
/// <summary>人机炮台旋转</summary>
|
||||
/// <summary>人机炮台旋转(房主端执行)</summary>
|
||||
private void RotateBotToTarget(SitPosData sit, Vector3 fishWorldPos, float rotateSpeed = -1f)
|
||||
{
|
||||
Vector2 screenPos = Camera.main.WorldToScreenPoint(fishWorldPos);
|
||||
@@ -2775,6 +2764,30 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
float t = Mathf.Min(speed * 0.15f * Time.deltaTime, 1f);
|
||||
float smoothed = Mathf.LerpAngle(current, angle, t);
|
||||
sit.SetRotation(smoothed);
|
||||
|
||||
// ⭐ 机器人旋转帧同步:和开炮一样实时广播
|
||||
// 只保留极小节流(角度>2° 或 0.05s)避免每帧都广播造成网络洪流
|
||||
float lastAngle = botLastSyncAngle.TryGetValue(sit.posID, out float la) ? la : -999f;
|
||||
float lastTime = botLastSyncTime.TryGetValue(sit.posID, out float lt) ? lt : 0f;
|
||||
if (Mathf.Abs(Mathf.DeltaAngle(lastAngle, smoothed)) > 2f || (Time.time - lastTime) > 0.05f)
|
||||
{
|
||||
SyncBotRotate(sit, smoothed);
|
||||
botLastSyncAngle[sit.posID] = smoothed;
|
||||
botLastSyncTime[sit.posID] = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>机器人旋转广播(房主代发,复用 rotateTurrect 帧类型)</summary>
|
||||
private void SyncBotRotate(SitPosData botSit, float angle)
|
||||
{
|
||||
SyncGameData sgd = new SyncGameData
|
||||
{
|
||||
sitPos = botSit.posID,
|
||||
frameType = FrameDataType.rotateTurrect,
|
||||
time = BeijingTimeManager.Instance.CurrentTimestampMs,
|
||||
frameData = new FrameData_Rotate { angle = angle }
|
||||
};
|
||||
WebSocketSendList.SyncGameData(sgd);
|
||||
}
|
||||
|
||||
/// <summary>人机开火同步(房主代发)</summary>
|
||||
|
||||
Reference in New Issue
Block a user