This commit is contained in:
Bob.Song
2026-03-11 10:16:08 +08:00
9 changed files with 145 additions and 96 deletions

View File

@@ -36,36 +36,7 @@
// Feeder = 10 // Feeder = 10
// } // }
// //
// [Serializable]
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 enum HeldItemType // public enum HeldItemType
// { // {

View File

@@ -22,15 +22,56 @@ namespace NBF
#region Rod专属 #region Rod专属
private bool _stretchRope;
public bool StretchRope
{
get => _stretchRope;
set
{
_stretchRope = value;
Scene.EventComponent.Publish(new PlayerItemRodLingChangeEvent
{
Item = this
});
}
}
private float _lineLength = 5f;
/// <summary> /// <summary>
/// 线长度 /// 线长度
/// </summary> /// </summary>
public float LineLength = 1.5f; public float LineLength
{
get => _lineLength;
set
{
_lineLength = value;
Scene.EventComponent.Publish(new PlayerItemRodLingChangeEvent
{
Item = this
});
}
}
private float _floatLength = 0.3f;
/// <summary> /// <summary>
/// 浮漂线长度 /// 浮漂线长度
/// </summary> /// </summary>
public float FloatLength = 0.5f; public float FloatLength
{
get => _floatLength;
set
{
_floatLength = value;
Scene.EventComponent.Publish(new PlayerItemRodLingChangeEvent
{
Item = this
});
}
}
private float _tension; private float _tension;
@@ -40,13 +81,17 @@ namespace NBF
public float Tension public float Tension
{ {
get => _tension; get => _tension;
private set set
{ {
if (!Mathf.Approximately(_tension, value)) if (!Mathf.Approximately(_tension, value))
{ {
_tension = value; _tension = value;
// OnTensionChanged?.Invoke(_tension);
} }
Scene.EventComponent.Publish(new PlayerItemRodLingChangeEvent
{
Item = this
});
} }
} }

View File

@@ -12,4 +12,9 @@
public PlayerItem Item; public PlayerItem Item;
public PlayerItem PrevItem; public PlayerItem PrevItem;
} }
public struct PlayerItemRodLingChangeEvent
{
public PlayerItem Item;
}
} }

View File

@@ -0,0 +1,15 @@
using Fantasy.Event;
namespace NBF
{
public class OnPlayerItemRodLingChangeEvent: EventSystem<PlayerItemRodLingChangeEvent>
{
protected override void Handler(PlayerItemRodLingChangeEvent self)
{
var itemView = self.Item.GetComponent<PlayerItemView>();
itemView.Rod.SetLineLength();
// var view = self.Player.GetOrAddComponent<PlayerView>();
// view.ChangeItem(self).Coroutine();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 308a4c63d4da4a5e83db7426790c9b6e
timeCreated: 1773155866

View File

@@ -152,10 +152,14 @@ namespace NBF
/// </summary> /// </summary>
public void OnRodThrowStart() public void OnRodThrowStart()
{ {
// if (Player.State is PlayerStateThrow playerStateThrow) if (Player.State == PlayerState.Throw)
// { {
// playerStateThrow.OnRodThrowStart(); var playerStateView = Player.GetComponent<PlayerStateView>();
// } if (playerStateView.CurrentStateView is PlayerStageViewThrow playerStateThrow)
{
playerStateThrow.OnRodThrowStart();
}
}
} }
/// <summary> /// <summary>
@@ -163,10 +167,14 @@ namespace NBF
/// </summary> /// </summary>
public void OnRodThrownEnd() public void OnRodThrownEnd()
{ {
// if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow) if (Player.State == PlayerState.Throw)
// { {
// playerStateThrow.OnRodThrownEnd(); var playerStateView = Player.GetComponent<PlayerStateView>();
// } if (playerStateView.CurrentStateView is PlayerStageViewThrow playerStateThrow)
{
playerStateThrow.OnRodThrownEnd();
}
}
} }
#endregion #endregion

View File

@@ -16,6 +16,8 @@ namespace NBF
private PlayerStageViewBase _currentStateView; private PlayerStageViewBase _currentStateView;
private Player _player; private Player _player;
public PlayerStageViewBase CurrentStateView => _currentStateView;
public void Awake() public void Awake()
{ {
_player = GetParent<Player>(); _player = GetParent<Player>();

View File

@@ -3,6 +3,36 @@ using UnityEngine;
namespace NBF 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 abstract class PlayerStageViewBase
{ {
public Player Player { get; private set; } public Player Player { get; private set; }

View File

@@ -12,17 +12,10 @@ namespace NBF
{ {
public class FRod : FHandItem public class FRod : FHandItem
{ {
private float _tension;
public PlayerItem PlayerItem; public PlayerItem PlayerItem;
public override int ConfigId => PlayerItem?.ConfigID ?? 0; public override int ConfigId => PlayerItem?.ConfigID ?? 0;
/// <summary>
/// 可用的
/// </summary>
public bool Usable { get; private set; }
public RodAsset Asset; public RodAsset Asset;
public FReel Reel; public FReel Reel;
@@ -41,29 +34,6 @@ namespace NBF
[HideInInspector] public FFish currentFish; [HideInInspector] public FFish currentFish;
public RodRingNode[] rings; public RodRingNode[] rings;
/// <summary>
/// 线长度
/// </summary>
public float lineLength = 1.5f;
/// <summary>
/// 浮漂线长度
/// </summary>
public float floatLength = 0.5f;
public float Tension
{
get => _tension;
private set
{
if (!Mathf.Approximately(_tension, value))
{
_tension = value;
// OnTensionChanged?.Invoke(_tension);
}
}
}
private void Awake() private void Awake()
{ {
@@ -72,42 +42,43 @@ namespace NBF
private void Update() private void Update()
{ {
if (Input.GetKeyDown(KeyCode.Alpha0)) // if (Input.GetKeyDown(KeyCode.Alpha0))
{ // {
SetLineLength(lineLength); // SetLineLength(lineLength);
} // }
else if (Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.Equals)) // else if (Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.Equals))
{ // {
lineLength += 0.1f; // lineLength += 0.1f;
SetLineLength(lineLength); // SetLineLength(lineLength);
} // }
else if (Input.GetKeyDown(KeyCode.Minus)) // else if (Input.GetKeyDown(KeyCode.Minus))
{ // {
lineLength -= 0.1f; // lineLength -= 0.1f;
SetLineLength(lineLength); // SetLineLength(lineLength);
} // }
// SetLineLength();
} }
public void SetLineLength(float lineLength, bool stretchRope = true) public void SetLineLength()
{ {
if (!Line) return; if (!Line) return;
if (Line.LineType == LineType.Spinning) if (Line.LineType == LineType.Spinning)
{ {
//没有浮漂类型 //没有浮漂类型
Line.Lure.SetJointDistance(lineLength); Line.Lure.SetJointDistance(PlayerItem.LineLength);
if (stretchRope) if (PlayerItem.StretchRope)
{ {
Line.SetTargetLength(Tension > 0f ? 0f : lineLength); Line.SetTargetLength(PlayerItem.Tension > 0f ? 0f : PlayerItem.LineLength);
} }
} }
else else
{ {
//有浮漂 //有浮漂
Line.Lure.SetJointDistance(floatLength); Line.Lure.SetJointDistance(PlayerItem.FloatLength);
Line.Bobber.SetJointDistance(lineLength - floatLength); Line.Bobber.SetJointDistance(PlayerItem.LineLength - PlayerItem.FloatLength);
if (stretchRope) if (PlayerItem.StretchRope)
{ {
Line.SetTargetLength(Tension > 0f ? 0f : lineLength - floatLength); Line.SetTargetLength(PlayerItem.Tension > 0f ? 0f : PlayerItem.LineLength - PlayerItem.FloatLength);
} }
} }
} }
@@ -204,6 +175,7 @@ namespace NBF
} }
await FTask.WaitFrame(playerView.Scene); //等待1帧 await FTask.WaitFrame(playerView.Scene); //等待1帧
SetLineLength();
if (Reel) if (Reel)
{ {
Reel.reelingDrag = 0.699f; Reel.reelingDrag = 0.699f;
@@ -243,8 +215,6 @@ namespace NBF
transform.SetParent(playerViewUnity.ModelAsset.RodRoot); transform.SetParent(playerViewUnity.ModelAsset.RodRoot);
transform.localPosition = Vector3.zero; transform.localPosition = Vector3.zero;
transform.rotation = playerViewUnity.ModelAsset.RodRoot.rotation; transform.rotation = playerViewUnity.ModelAsset.RodRoot.rotation;
Usable = true;
} }