// // 新文件:D:\myself\Fishing2\Assets\Scripts\Fishing\Data\LocalDataManager.cs
//
// using System.Collections.Generic;
// using UnityEngine;
//
// namespace NBF
// {
// ///
// /// 本地单机模式的数据管理器(模拟服务器转发)
// ///
// public class LocalDataManager : PlayerDataManager
// {
// public override bool IsLocalMode => true;
//
// private Dictionary _localPlayers = new();
// private uint _sequenceCounter;
//
// protected void Awake()
// {
// Instance = this;
// }
//
// public void RegisterPlayer(FPlayerData player)
// {
// if (!_localPlayers.ContainsKey(player.PlayerID))
// {
// _localPlayers.Add(player.PlayerID, player);
// player.IsLocalPlayer = true;
// }
// }
//
// public override void OnPlayerStateChanged(FPlayerData player, PlayerState newState)
// {
// // 本地模式下,广播给其他本地玩家(分屏)
// foreach (var kvp in _localPlayers)
// {
// if (kvp.Value != player)
// {
// // 直接应用状态(或者加入简单的延迟模拟)
// kvp.Value.State = newState;
// }
// }
// }
//
// public override void OnHeldItemChanged(FPlayerData player, HeldItemInfo newItem)
// {
// foreach (var kvp in _localPlayers)
// {
// if (kvp.Value != player)
// {
// kvp.Value.CurrentHeldItem = newItem;
// }
// }
// }
//
// public override void SendStateSnapshot(FPlayerData player)
// {
// _sequenceCounter++;
// var snapshot = player.ToNetworkSnapshot(_sequenceCounter);
//
// // 本地广播
// foreach (var kvp in _localPlayers)
// {
// if (kvp.Value != player)
// {
// ReceiveStateSnapshot(kvp.Key, snapshot);
// }
// }
// }
//
// public override void ReceiveStateSnapshot(int playerID, PlayerStateSnapshot snapshot)
// {
// if (_localPlayers.TryGetValue(playerID, out var player))
// {
// player.ApplyFromNetworkSnapshot(snapshot);
// }
// }
//
// // 定时同步(例如每秒 10 次)
// private float _syncTimer;
// private void Update()
// {
// _syncTimer += Time.deltaTime;
// if (_syncTimer >= 0.1f) // 10Hz
// {
// _syncTimer = 0;
// foreach (var player in _localPlayers.Values)
// {
// SendStateSnapshot(player);
// }
// }
// }
// }
// }