Files
Fishing2/Assets/Scripts/Fishing/Data/LocalDataManager.cs
2026-03-09 17:50:20 +08:00

95 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// // 新文件D:\myself\Fishing2\Assets\Scripts\Fishing\Data\LocalDataManager.cs
//
// using System.Collections.Generic;
// using UnityEngine;
//
// namespace NBF
// {
// /// <summary>
// /// 本地单机模式的数据管理器(模拟服务器转发)
// /// </summary>
// public class LocalDataManager : PlayerDataManager
// {
// public override bool IsLocalMode => true;
//
// private Dictionary<int, FPlayerData> _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);
// }
// }
// }
// }
// }