修改提交

This commit is contained in:
Bob.Song
2026-03-09 17:50:20 +08:00
parent 68beeb3417
commit 27b85fd875
228 changed files with 30829 additions and 1509 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
// // 新文件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);
// }
// }
// }
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ec2bd63eb6c143fdb528da693a8c6969
timeCreated: 1773028161

View File

@@ -0,0 +1,60 @@
// using UnityEngine;
//
// namespace NBF
// {
// /// <summary>
// /// 网络模式的数据管理器
// /// </summary>
// public class NetworkDataManager : PlayerDataManager
// {
// public override bool IsLocalMode => false;
//
// // TODO: 这里集成你的网络库Steamworks、Photon、Mirror 等)
// // public SteamNetworkClient NetworkClient;
//
// protected void Awake()
// {
// Instance = this;
// }
//
// public override void OnPlayerStateChanged(FPlayerData player, PlayerState newState)
// {
// // 如果是本地玩家,发送到服务器
// if (player.IsLocalPlayer)
// {
// SendStateSnapshot(player);
// }
// }
//
// public override void OnHeldItemChanged(FPlayerData player, HeldItemInfo newItem)
// {
// if (player.IsLocalPlayer)
// {
// // TODO: 发送物品切换消息到服务器
// Debug.Log($"发送物品切换:{newItem.ItemType}, ConfigID={newItem.ConfigID}");
// }
// }
//
// public override void SendStateSnapshot(FPlayerData player)
// {
// if (!player.IsLocalPlayer) return;
//
// // TODO: 通过 Steam 或其他网络库发送
// // NetworkClient.SendStateSnapshot(player.ToNetworkSnapshot());
// }
//
// public override void ReceiveStateSnapshot(int playerID, PlayerStateSnapshot snapshot)
// {
// // TODO: 从网络接收其他玩家的状态
// // 找到或创建对应的玩家对象
// var player = FindOrCreatePlayer(playerID);
// player.ApplyFromNetworkSnapshot(snapshot);
// }
//
// private FPlayerData FindOrCreatePlayer(int playerID)
// {
// // TODO: 实现玩家对象池或动态生成
// return FindObjectOfType<FPlayerData>();
// }
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f1a06ba516ea46f0920729b2af6484c1
timeCreated: 1773028213

View File

@@ -0,0 +1,56 @@
// using System;
// using System.Collections.Generic;
// using UnityEngine;
//
// namespace NBF
// {
// public interface IDataSource
// {
// }
//
// /// <summary>
// /// 数据管理器基类(本地和网络共享接口)
// /// </summary>
// public class PlayerDataManager : MonoBehaviour
// {
// public static PlayerDataManager Instance { get; private set; }
//
// public FPlayerData Self { get; set; }
//
// private Dictionary<int, FPlayerData> _players = new Dictionary<int, FPlayerData>();
//
// protected void Awake()
// {
// Instance = this;
// }
//
//
// /// <summary>
// /// 玩家状态变更时调用
// /// </summary>
// public void OnPlayerStateChanged(FPlayerData player, PlayerState newState)
// {
// }
//
// /// <summary>
// /// 手持物品变更时调用
// /// </summary>
// public void OnHeldItemChanged(FPlayerData player, HeldItemInfo newItem)
// {
// }
//
// /// <summary>
// /// 发送玩家状态快照
// /// </summary>
// public void SendStateSnapshot(FPlayerData player)
// {
// }
//
// /// <summary>
// /// 接收并应用网络快照
// /// </summary>
// public void ReceiveStateSnapshot(int playerID, PlayerStateSnapshot snapshot)
// {
// }
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0478bf9a256a46beb65fd0307c7b5b9b
timeCreated: 1773028149

View File

@@ -0,0 +1,234 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace NBF
{
/// <summary>
/// 状态进入参数(用于网络同步和动画/表现播放)
/// </summary>
[Serializable]
public class StateEnterParams
{
// 序列化友好的数据存储
[SerializeField] private List<string> _keys = new();
[SerializeField] private List<int> _intValues = new();
[SerializeField] private List<float> _floatValues = new();
[SerializeField] private List<Vector3> _vector3Values = new();
[SerializeField] private List<Quaternion> _quaternionValues = new();
// 快速访问缓存
private Dictionary<string, int> _intCache;
private Dictionary<string, int> _floatCache;
private Dictionary<string, int> _vector3Cache;
private Dictionary<string, int> _quaternionCache;
public StateEnterParams()
{
InitializeCaches();
}
private void InitializeCaches()
{
_intCache = new Dictionary<string, int>();
_floatCache = new Dictionary<string, int>();
_vector3Cache = new Dictionary<string, int>();
_quaternionCache = new Dictionary<string, int>();
}
/// <summary>
/// 清空所有参数
/// </summary>
public void Clear()
{
_keys.Clear();
_intValues.Clear();
_floatValues.Clear();
_vector3Values.Clear();
_quaternionValues.Clear();
_intCache.Clear();
_floatCache.Clear();
_vector3Cache.Clear();
_quaternionCache.Clear();
}
/// <summary>
/// 设置 int 参数
/// </summary>
public void SetInt(string key, int value)
{
if (_intCache.TryGetValue(key, out int index))
{
_intValues[index] = value;
}
else
{
_keys.Add(key);
_intValues.Add(value);
_intCache[key] = _intValues.Count - 1;
}
}
/// <summary>
/// 设置 float 参数
/// </summary>
public void SetFloat(string key, float value)
{
if (_floatCache.TryGetValue(key, out int index))
{
_floatValues[index] = value;
}
else
{
_keys.Add(key);
_floatValues.Add(value);
_floatCache[key] = _floatValues.Count - 1;
}
}
/// <summary>
/// 设置 Vector3 参数
/// </summary>
public void SetVector3(string key, Vector3 value)
{
if (_vector3Cache.TryGetValue(key, out int index))
{
_vector3Values[index] = value;
}
else
{
_keys.Add(key);
_vector3Values.Add(value);
_vector3Cache[key] = _vector3Values.Count - 1;
}
}
/// <summary>
/// 设置 Quaternion 参数
/// </summary>
public void SetQuaternion(string key, Quaternion value)
{
if (_quaternionCache.TryGetValue(key, out int index))
{
_quaternionValues[index] = value;
}
else
{
_keys.Add(key);
_quaternionValues.Add(value);
_quaternionCache[key] = _quaternionValues.Count - 1;
}
}
/// <summary>
/// 设置 bool 参数
/// </summary>
public void SetBool(string key, bool value)
{
if (_intCache.TryGetValue(key, out int index))
{
_intValues[index] = value ? 1 : 0;
}
else
{
_keys.Add(key);
_intValues.Add(value ? 1 : 0);
_intCache[key] = _intValues.Count - 1;
}
}
/// <summary>
/// 获取 int 参数
/// </summary>
public int GetInt(string key, int defaultValue = 0)
{
if (_intCache.TryGetValue(key, out int index) && index < _intValues.Count)
{
return _intValues[index];
}
return defaultValue;
}
/// <summary>
/// 获取 float 参数
/// </summary>
public float GetFloat(string key, float defaultValue = 0f)
{
if (_floatCache.TryGetValue(key, out int index) && index < _floatValues.Count)
{
return _floatValues[index];
}
return defaultValue;
}
/// <summary>
/// 获取 Vector3 参数
/// </summary>
public Vector3 GetVector3(string key, Vector3 defaultValue = default)
{
if (_vector3Cache.TryGetValue(key, out int index) && index < _vector3Values.Count)
{
return _vector3Values[index];
}
return defaultValue;
}
/// <summary>
/// 获取 Quaternion 参数
/// </summary>
public Quaternion GetQuaternion(string key, Quaternion defaultValue = default)
{
if (_quaternionCache.TryGetValue(key, out int index) && index < _quaternionValues.Count)
{
return _quaternionValues[index];
}
return defaultValue;
}
/// <summary>
/// 获取 bool 参数
/// </summary>
public bool GetBool(string key, bool defaultValue = false)
{
if (_intCache.TryGetValue(key, out int index) && index < _intValues.Count)
{
return _intValues[index] == 1;
}
return defaultValue;
}
/// <summary>
/// 是否包含某个参数
/// </summary>
public bool HasKey(string key)
{
return _intCache.ContainsKey(key) ||
_floatCache.ContainsKey(key) ||
_vector3Cache.ContainsKey(key) ||
_quaternionCache.ContainsKey(key);
}
/// <summary>
/// 复制当前参数
/// </summary>
public StateEnterParams Clone()
{
var copy = new StateEnterParams
{
_keys = new List<string>(_keys),
_intValues = new List<int>(_intValues),
_floatValues = new List<float>(_floatValues),
_vector3Values = new List<Vector3>(_vector3Values),
_quaternionValues = new List<Quaternion>(_quaternionValues)
};
copy.InitializeCaches();
return copy;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a0ff43bbc7dd46b387e62f574ceb2523
timeCreated: 1773029210