提交修改

This commit is contained in:
Bob.Song
2026-04-29 17:33:49 +08:00
parent a8f3569787
commit 70769f7e39
33 changed files with 237 additions and 96 deletions

View File

@@ -0,0 +1,80 @@
using System.Collections.Generic;
namespace NBF
{
public partial class Player
{
#region
/// <summary>
/// 上一个状态
/// </summary>
public PlayerState PreviousState;
/// <summary>
/// 当前状态
/// </summary>
public PlayerState State;
/// <summary>
/// 状态参数
/// </summary>
public StateEnterParams StateParams;
private readonly Dictionary<PlayerState, PlayerStageViewBase> _stageViews =
new Dictionary<PlayerState, PlayerStageViewBase>();
private PlayerStageViewBase _currentStateView;
private void InitState()
{
_stageViews.Add(PlayerState.Idle, new PlayerStageViewIdle());
_stageViews.Add(PlayerState.Prepare, new PlayerStageViewPrepare());
_stageViews.Add(PlayerState.Throw, new PlayerStageViewThrow());
_stageViews.Add(PlayerState.Fishing, new PlayerStageViewFishing());
_stageViews.Add(PlayerState.Fight, new PlayerStageViewFight());
foreach (var playerStageView in _stageViews.Values)
{
playerStageView.Init(this);
}
}
public void UpdateState()
{
_currentStateView?.Update();
}
/// <summary>
/// 切换状态
/// </summary>
/// <param name="state"></param>
/// <param name="stateParams"></param>
public void ChangeState(PlayerState state, StateEnterParams stateParams = null)
{
if (state == State)
{
return;
}
PreviousState = State;
State = state;
StateParams = stateParams;
OnStageChange();
}
public void OnStageChange()
{
if (_currentStateView != null)
{
_currentStateView.Exit();
}
_currentStateView = _stageViews.GetValueOrDefault(State);
_currentStateView?.Enter(StateParams, PreviousState);
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4eda3ea2fee445de99d96eefc3acdb85
timeCreated: 1777453996

View File

@@ -7,7 +7,7 @@ using UnityEngine;
namespace NBF
{
public class Player : MonoBehaviour
public partial class Player : MonoBehaviour
{
[Header("角色参数")] public float EyeAngle;
public bool IsGrounded;
@@ -37,6 +37,11 @@ namespace NBF
public bool IsSelf;
/// <summary>
/// 抛物线轨迹
/// </summary>
public List<Vector3> TrajectoryPoints = new List<Vector3>();
#region
private void Awake()
@@ -50,10 +55,13 @@ namespace NBF
{
gameObject.AddComponent<PlayerInput>();
}
InitState();
}
private void Update()
{
UpdateState();
}
private void FixedUpdate()
@@ -61,10 +69,11 @@ namespace NBF
}
#endregion
#region
private FHandItem HandItem;
public FHandItem HandItem { get; private set; }
private bool IsChangeItemIng;
public async FTask UseItem(int configId, List<int> bindItems)

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
namespace NBF
{
public class PlayerFSM : PlayerMonoBehaviour
{
private readonly Dictionary<PlayerState, PlayerStageViewBase> _stageViews =
new Dictionary<PlayerState, PlayerStageViewBase>();
private PlayerState _currentState;
private PlayerStageViewBase _currentStateView;
protected override void OnAwake()
{
_stageViews.Add(PlayerState.Idle, new PlayerStageViewIdle());
_stageViews.Add(PlayerState.Prepare, new PlayerStageViewPrepare());
_stageViews.Add(PlayerState.Throw, new PlayerStageViewThrow());
_stageViews.Add(PlayerState.Fishing, new PlayerStageViewFishing());
_stageViews.Add(PlayerState.Fight, new PlayerStageViewFight());
foreach (var playerStageView in _stageViews.Values)
{
playerStageView.Init(Player);
}
}
private void Update()
{
_currentStateView?.Update();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df8de819db7747ddad97ff39505814a4
timeCreated: 1777454838

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 98b05ca000114232a657f19095fdb49a
timeCreated: 1773063071

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace NBF
{
public interface IPlayerThrowAnimation
{
Player Player { get; set; }
bool IsPlaying { get; }
void Play(ThrowAnimationRequest request);
void Tick(float deltaTime);
void Stop(bool snapToTarget);
}
public struct ThrowAnimationRequest
{
public FLineLogicNode EndNode;
public Vector3 ThrowOriginPosition;
public Vector3 StartPosition;
public Vector3 Forward;
public float ChargedProgress;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 51e9c4e20e460b34ca8ec4de6b7cab4b

View File

@@ -0,0 +1,153 @@
using UnityEngine;
namespace NBF
{
public class ParabolaPlayerThrowAnimation : IPlayerThrowAnimation
{
public Player Player { get; set; }
private const int TrajectorySampleCount = 24;
//
// private readonly float _minThrowDistance;
// private readonly float _maxThrowDistance;
private readonly float _throwDuration;
private readonly float _throwArcHeight;
private readonly float _targetHeightOffset;
private readonly AnimationCurve _throwHeightCurve;
private readonly Vector3[] _lastTrajectoryPoints = new Vector3[TrajectorySampleCount + 1];
private bool _hasLastTrajectory;
private float _chargedProgress;
private float _castElapsedTime;
private Vector3 _castStartPos;
private Vector3 _castTargetPos;
private FLineLogicNode _castingLure;
public bool IsPlaying => _castingLure != null;
public ParabolaPlayerThrowAnimation(
float throwDuration = 0.45f,
float throwArcHeight = 4f,
float targetHeightOffset = 0f,
AnimationCurve throwHeightCurve = null)
{
_throwDuration = throwDuration;
_throwArcHeight = throwArcHeight;
_targetHeightOffset = targetHeightOffset;
_throwHeightCurve = throwHeightCurve ?? AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
}
public void Play(ThrowAnimationRequest request)
{
if (request.EndNode == null)
{
return;
}
Stop(snapToTarget: false);
_castingLure = request.EndNode;
_chargedProgress = Mathf.Clamp01(request.ChargedProgress);
_castElapsedTime = 0f;
var lureBody = request.EndNode.Rigidbody;
_castStartPos = request.StartPosition;
Vector3 forward = GetHorizontalForward(request.Forward);
float distance = Mathf.Lerp(1, 8, _chargedProgress);
_castTargetPos = request.ThrowOriginPosition + forward * distance;
_castTargetPos.y = _castStartPos.y + _targetHeightOffset;
CacheTrajectoryPoints();
lureBody.isKinematic = true;
lureBody.useGravity = false;
lureBody.linearVelocity = Vector3.zero;
lureBody.angularVelocity = Vector3.zero;
lureBody.position = _castStartPos;
}
public void Tick(float deltaTime)
{
UpdateCastAnimation(deltaTime);
}
public void Stop(bool snapToTarget)
{
if (_castingLure == null)
{
return;
}
var lureBody = _castingLure.Rigidbody;
if (snapToTarget)
{
_castingLure.transform.position = _castTargetPos;
lureBody.position = _castTargetPos;
}
lureBody.linearVelocity = Vector3.zero;
lureBody.angularVelocity = Vector3.zero;
lureBody.useGravity = true;
lureBody.isKinematic = false;
_castingLure = null;
}
private void UpdateCastAnimation(float deltaTime)
{
if (_castingLure == null)
{
return;
}
float duration = Mathf.Max(_throwDuration, 0.01f);
_castElapsedTime += deltaTime;
float progress = Mathf.Clamp01(_castElapsedTime / duration);
_castingLure.transform.position = EvaluateTrajectoryPosition(progress);
if (progress >= 1f)
{
Stop(snapToTarget: true);
}
}
private void CacheTrajectoryPoints()
{
for (int i = 0; i <= TrajectorySampleCount; i++)
{
float progress = i / (float)TrajectorySampleCount;
_lastTrajectoryPoints[i] = EvaluateTrajectoryPosition(progress);
}
_hasLastTrajectory = true;
if (Player != null && Player.TrajectoryPoints != null)
{
Player.TrajectoryPoints.Clear();
Player.TrajectoryPoints.AddRange(_lastTrajectoryPoints);
}
}
private Vector3 GetHorizontalForward(Vector3 forward)
{
forward.y = 0f;
if (forward.sqrMagnitude < 0.001f)
{
return Vector3.forward;
}
return forward.normalized;
}
private Vector3 EvaluateTrajectoryPosition(float progress)
{
Vector3 position = Vector3.Lerp(_castStartPos, _castTargetPos, progress);
float arc = _throwHeightCurve.Evaluate(progress) * _throwArcHeight * _chargedProgress;
position.y += arc;
return position;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 86121f3f07035144fadd467716b4b3a9

View File

@@ -0,0 +1,205 @@
using NBC;
using UnityEngine;
namespace NBF
{
public enum PlayerState : uint
{
None = 0,
/// <summary>
/// 闲置等待中
/// </summary>
Idle = 1,
/// <summary>
/// 准备抛竿
/// </summary>
Prepare = 2,
/// <summary>
/// 抛竿中
/// </summary>
Throw = 3,
/// <summary>
/// 钓鱼中
/// </summary>
Fishing = 4,
/// <summary>
/// 溜鱼中
/// </summary>
Fight = 5
}
public abstract class PlayerStageViewBase
{
public Player Player { get; private set; }
protected float EnterTime { get; set; }
protected PlayerState PreviousState { get; private set; }
protected StateEnterParams Params;
public void Init(Player player)
{
Player = player;
}
/// <summary>
/// 检查状态超时
/// </summary>
public void CheckStateTimeout(float time)
{
if (Time.time - EnterTime >= time)
{
Player.ChangeState(PlayerState.Idle);
}
}
public void Enter(StateEnterParams par = null, PlayerState prevState = PlayerState.None)
{
Log.Info($"进入状态={GetType()}");
Params = par;
PreviousState = prevState;
EnterTime = Time.time;
OnEnter();
}
protected virtual void OnEnter()
{
}
public void Exit()
{
OnExit();
}
protected virtual void OnExit()
{
}
public void Update()
{
OnUpdate();
}
protected virtual void OnUpdate()
{
}
#region 线
public void TakeLine()
{
if (Player == null) return;
if (Player.HandItem is FRod rod)
{
var endNode = rod.Line.EndNode;
var pinch = endNode.GetComponent<JointPinchController>();
if (pinch != null)
{
pinch.StartPinch(Player.ModelAsset.Pinch);
}
}
}
public void UnTakeLine()
{
if (Player == null) return;
if (Player.HandItem is FRod rod)
{
var endNode = rod.Line.EndNode;
var pinch = endNode.GetComponent<JointPinchController>();
if (pinch != null)
{
pinch.ReleasePinch();
}
}
}
#endregion
#region 竿
protected void RodUpDown()
{
PlayerState ret = PlayerState.None;
var isUpRod = false;
var isSubLine = false;
if (InputManager.IsOp1)
{
if (!Player.IsLureRod)
{
//抬杆
isUpRod = true;
}
else
{
//收线
isSubLine = true;
}
}
if (InputManager.IsOp2)
{
if (Player.IsLureRod)
{
//抬杆
isUpRod = true;
}
}
if (isUpRod || Player.ModelAsset.PlayerAnimator.FishingUp > 0)
{
var upForce = 1;
var addNum = upForce * Time.deltaTime;
if (!isUpRod)
{
addNum *= -1;
}
else
{
addNum *= 0.5f;
}
Player.ModelAsset.PlayerAnimator.FishingUp += addNum;
Debug.Log($"addNum={addNum} ishingFinal={Player.ModelAsset.PlayerAnimator.FishingUp}");
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 1)
{
Player.ModelAsset.PlayerAnimator.FishingUp = 1;
}
else if (Player.ModelAsset.PlayerAnimator.FishingUp < 0)
{
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
}
}
else
{
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
}
}
#endregion
public FRod GetRod()
{
// var view = Player.GetComponent<PlayerView>();
// if (view != null)
// {
// var handItemView = Player.HandItem.GetComponent<PlayerItemView>();
// if (handItemView != null && handItemView.Rod != null)
// {
// return handItemView.Rod;
// }
// }
if (Player != null)
{
return Player.HandItem as FRod;
}
return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cce89f03f80b4fb8a0e36e66e9ffb3a9
timeCreated: 1773063081

View File

@@ -0,0 +1,29 @@
namespace NBF
{
public class PlayerStageViewFight : PlayerStageViewBase
{
protected override void OnEnter()
{
}
protected override void OnExit()
{
}
protected override void OnUpdate()
{
PlayerState ret = PlayerState.None;
RodUpDown();
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
{
// ret = CheckTackFish();
}
if (ret != PlayerState.None)
{
Player.ChangeState(ret);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a9445a6593604dc19dea2bb8bb0819bc
timeCreated: 1773064542

View File

@@ -0,0 +1,109 @@
using UnityEngine;
namespace NBF
{
public class PlayerStageViewFishing : PlayerStageViewBase
{
protected override void OnEnter()
{
Debug.LogError("enter PlayerStateFishing");
Player.ModelAsset.PlayerAnimator.BaitThrown = true;
}
protected override void OnExit()
{
}
protected override void OnUpdate()
{
PlayerState ret = PlayerState.None;
RodUpDown();
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
{
ret = CheckTackFish();
}
if (ret != PlayerState.None)
{
Player.ChangeState(ret);
}
// var isUpRod = false;
// var isSubLine = false;
//
// if (InputManager.IsOp1)
// {
// if (!Player.IsLureRod)
// {
// //抬杆
// isUpRod = true;
// }
// else
// {
// //收线
// isSubLine = true;
// }
// }
//
// if (InputManager.IsOp2)
// {
// if (Player.IsLureRod)
// {
// //抬杆
// isUpRod = true;
// }
// }
//
// if (isUpRod || PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp > 0)
// {
// var upForce = 1;
// var addNum = upForce * Time.deltaTime;
// if (!isUpRod)
// {
// addNum *= -1;
// }
// else
// {
// addNum *= 0.5f;
// }
//
// PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp += addNum;
// Debug.Log($"addNum={addNum} ishingFinal={PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp}");
// if (PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp >= 1)
// {
// PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp = 1;
// }
// else if (PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp < 0)
// {
// PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp = 0;
// }
//
// if (PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
// {
// ret = CheckTackFish();
// }
// }
// else
// {
// PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp = 0;
// }
//
// if (ret != PlayerState.None)
// {
// Player.ChangeState(ret);
// }
}
#region
private PlayerState CheckTackFish()
{
// return PlayerState.Idle;
return PlayerState.Fight;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 84665b6bc7c84642b365db024c7759fd
timeCreated: 1773064529

View File

@@ -0,0 +1,28 @@
namespace NBF
{
public class PlayerStageViewIdle : PlayerStageViewBase
{
protected override void OnEnter()
{
Player.ModelAsset.PlayerAnimator.BaitThrown = false;
InputManager.OnOp1Action += OnOp1Action;
TakeLine();
}
private void OnOp1Action(bool performed)
{
if (Player.HandItem == null) return;
if (performed)
{
Player.ChangeState(PlayerState.Prepare);
// _nextState = true;
}
}
protected override void OnExit()
{
InputManager.OnOp1Action -= OnOp1Action;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1fca81636d7246e7a5f84684a8563ca3
timeCreated: 1773063824

View File

@@ -0,0 +1,75 @@
using NBC;
using UnityEngine;
namespace NBF
{
public class PlayerStageViewPrepare : PlayerStageViewBase
{
public enum Phase
{
None,
/// <summary>
/// 蓄力
/// </summary>
Charged,
/// <summary>
/// 确认蓄力结果
/// </summary>
Confirm,
}
public Phase Stage = Phase.Charged;
public float ChargedProgress;
protected override void OnEnter()
{
Log.Info("enter PlayerStatePrepare");
ChargedProgress = 0;
Stage = Phase.Charged;
Player.ModelAsset.PlayerAnimator.PrepareThrow = true;
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
}
protected override void OnUpdate()
{
if (Stage == Phase.Charged)
{
ThrowPowerCharged();
}
else if (Stage == Phase.Confirm)
{
//确认蓄力结果,
Debug.Log($"确认蓄力结果,ChargedProgress={ChargedProgress}");
var par = new StateEnterParams();
par.SetFloat(StateParamsConst.ChargedProgress, ChargedProgress);
Player.ChangeState(PlayerState.Throw, par);
Stage = Phase.None;
}
}
#region
private void ThrowPowerCharged()
{
if (ChargedProgress < 1)
{
ChargedProgress += Time.deltaTime * 0.5f;
Debug.Log($"ChargedProgress={ChargedProgress}");
}
else if (ChargedProgress > 1)
{
ChargedProgress = 1;
}
if (!InputManager.IsOp1)
{
Stage = Phase.Confirm;
}
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77cce716a7f94e0083789eb2953d5f79
timeCreated: 1773064499

View File

@@ -0,0 +1,111 @@
using NBC;
using UnityEngine;
namespace NBF
{
public class PlayerStageViewThrow : PlayerStageViewBase
{
private bool _nextState = false;
private bool _throwAnimEnded = false;
private IPlayerThrowAnimation _throwAnimation;
public float ChargedProgress;
protected override void OnEnter()
{
Log.Info("enter PlayerStateThrow");
Player.ModelAsset.PlayerAnimator.StartThrow = true;
ChargedProgress = 0;
if (Params != null)
{
ChargedProgress = Params.GetFloat(StateParamsConst.ChargedProgress);
}
Debug.Log($"PlayerThrow ChargedProgress={ChargedProgress}");
_nextState = false;
_throwAnimEnded = false;
_throwAnimation = null;
}
protected override void OnUpdate()
{
CheckStateTimeout(10);
_throwAnimation?.Tick(Time.deltaTime);
if (_throwAnimEnded && (_throwAnimation == null || !_throwAnimation.IsPlaying))
{
_nextState = true;
}
if (_nextState)
{
_nextState = false;
Player.ChangeState(PlayerState.Fishing);
}
}
protected override void OnExit()
{
_throwAnimation?.Stop(snapToTarget: false);
_throwAnimation = null;
}
#region
public void OnRodThrowStart()
{
Debug.LogError("OnRodThrowStart");
UnTakeLine();
Player.ModelAsset.PlayerAnimator.PrepareThrow = false;
Player.ModelAsset.PlayerAnimator.StartThrow = false;
var rod = GetRod();
if (rod == null || rod.Line == null)
{
return;
}
_throwAnimation = CreateThrowAnimation(rod);
_throwAnimation.Player = Player;
_throwAnimation?.Play(new ThrowAnimationRequest
{
EndNode = rod.Line.EndNode,
ThrowOriginPosition = Player.transform.position,
StartPosition = rod.Line.EndNode.Rigidbody.position,
Forward = Player.transform.forward,
ChargedProgress = ChargedProgress
});
}
public void OnRodThrownEnd()
{
Debug.LogError("OnRodThrownEnd");
_throwAnimEnded = true;
if (_throwAnimation == null || !_throwAnimation.IsPlaying)
{
_nextState = true;
}
}
#endregion
private IPlayerThrowAnimation CreateThrowAnimation(FRod rod)
{
if (rod == null || rod.Line == null)
{
return null;
}
switch (rod.Line.LineType)
{
case LineType.Spinning:
case LineType.SpinningFloat:
case LineType.Hand:
case LineType.HandDouble:
default:
return new ParabolaPlayerThrowAnimation();
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 240bbc6c969a4d2e9759ac1df5e6ccf2

View File

@@ -0,0 +1,239 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace NBF
{
public class StateParamsConst
{
public const string ChargedProgress = "ChargedProgress";
}
/// <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