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
// }
//
// [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
// {

View File

@@ -22,15 +22,56 @@ namespace NBF
#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>
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>
public float FloatLength = 0.5f;
public float FloatLength
{
get => _floatLength;
set
{
_floatLength = value;
Scene.EventComponent.Publish(new PlayerItemRodLingChangeEvent
{
Item = this
});
}
}
private float _tension;
@@ -40,13 +81,17 @@ namespace NBF
public float Tension
{
get => _tension;
private set
set
{
if (!Mathf.Approximately(_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 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>
public void OnRodThrowStart()
{
// if (Player.State is PlayerStateThrow playerStateThrow)
// {
// playerStateThrow.OnRodThrowStart();
// }
if (Player.State == PlayerState.Throw)
{
var playerStateView = Player.GetComponent<PlayerStateView>();
if (playerStateView.CurrentStateView is PlayerStageViewThrow playerStateThrow)
{
playerStateThrow.OnRodThrowStart();
}
}
}
/// <summary>
@@ -163,10 +167,14 @@ namespace NBF
/// </summary>
public void OnRodThrownEnd()
{
// if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
// {
// playerStateThrow.OnRodThrownEnd();
// }
if (Player.State == PlayerState.Throw)
{
var playerStateView = Player.GetComponent<PlayerStateView>();
if (playerStateView.CurrentStateView is PlayerStageViewThrow playerStateThrow)
{
playerStateThrow.OnRodThrownEnd();
}
}
}
#endregion

View File

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

View File

@@ -3,6 +3,36 @@ 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; }

View File

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