From 40b142235e0b55723c41a36e11b1f23ad9e7dc22 Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Wed, 11 Mar 2026 09:06:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8A=A8=E7=94=BB=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Fishing/Data/FPlayerData.cs | 29 ------- .../Fishing/New/Data/Item/PlayerItem.cs | 53 ++++++++++++- .../Scripts/Fishing/New/Event/PlayerEvent.cs | 5 ++ .../Handle/OnPlayerItemRodLingChangeEvent.cs | 15 ++++ .../OnPlayerItemRodLingChangeEvent.cs.meta | 3 + .../New/View/Player/Mono/PlayerAnimator.cs | 26 ++++--- .../New/View/Player/PlayerStateView.cs | 2 + .../View/Player/States/PlayerStageViewBase.cs | 30 +++++++ .../Fishing/New/View/Player/Tackle/FRod.cs | 78 ++++++------------- 9 files changed, 145 insertions(+), 96 deletions(-) create mode 100644 Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs create mode 100644 Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs.meta diff --git a/Assets/Scripts/Fishing/Data/FPlayerData.cs b/Assets/Scripts/Fishing/Data/FPlayerData.cs index b667dd1b1..094454e57 100644 --- a/Assets/Scripts/Fishing/Data/FPlayerData.cs +++ b/Assets/Scripts/Fishing/Data/FPlayerData.cs @@ -36,36 +36,7 @@ // Feeder = 10 // } // - // [Serializable] - public enum PlayerState : uint - { - None = 0, - /// - /// 闲置等待中 - /// - Idle = 1, - - /// - /// 准备抛竿 - /// - Prepare = 2, - - /// - /// 抛竿中 - /// - Throw = 3, - - /// - /// 钓鱼中 - /// - Fishing = 4, - - /// - /// 溜鱼中 - /// - Fight = 5 - } // // public enum HeldItemType // { diff --git a/Assets/Scripts/Fishing/New/Data/Item/PlayerItem.cs b/Assets/Scripts/Fishing/New/Data/Item/PlayerItem.cs index 14e2ad757..2a6178ff8 100644 --- a/Assets/Scripts/Fishing/New/Data/Item/PlayerItem.cs +++ b/Assets/Scripts/Fishing/New/Data/Item/PlayerItem.cs @@ -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; + /// /// 线长度 /// - 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; /// /// 浮漂线长度 /// - 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 + }); } } diff --git a/Assets/Scripts/Fishing/New/Event/PlayerEvent.cs b/Assets/Scripts/Fishing/New/Event/PlayerEvent.cs index aebdfa281..1c1058f09 100644 --- a/Assets/Scripts/Fishing/New/Event/PlayerEvent.cs +++ b/Assets/Scripts/Fishing/New/Event/PlayerEvent.cs @@ -12,4 +12,9 @@ public PlayerItem Item; public PlayerItem PrevItem; } + + public struct PlayerItemRodLingChangeEvent + { + public PlayerItem Item; + } } \ No newline at end of file diff --git a/Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs b/Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs new file mode 100644 index 000000000..bcea54989 --- /dev/null +++ b/Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs @@ -0,0 +1,15 @@ +using Fantasy.Event; + +namespace NBF +{ + public class OnPlayerItemRodLingChangeEvent: EventSystem + { + protected override void Handler(PlayerItemRodLingChangeEvent self) + { + var itemView = self.Item.GetComponent(); + itemView.Rod.SetLineLength(); + // var view = self.Player.GetOrAddComponent(); + // view.ChangeItem(self).Coroutine(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs.meta b/Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs.meta new file mode 100644 index 000000000..1445a5667 --- /dev/null +++ b/Assets/Scripts/Fishing/New/View/Player/Handle/OnPlayerItemRodLingChangeEvent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 308a4c63d4da4a5e83db7426790c9b6e +timeCreated: 1773155866 \ No newline at end of file diff --git a/Assets/Scripts/Fishing/New/View/Player/Mono/PlayerAnimator.cs b/Assets/Scripts/Fishing/New/View/Player/Mono/PlayerAnimator.cs index 9ce8bd254..2487bf5e3 100644 --- a/Assets/Scripts/Fishing/New/View/Player/Mono/PlayerAnimator.cs +++ b/Assets/Scripts/Fishing/New/View/Player/Mono/PlayerAnimator.cs @@ -85,7 +85,7 @@ namespace NBF _IK = GetComponent(); _isInit = true; } - + public void OnUnUseItem() { @@ -152,10 +152,14 @@ namespace NBF /// public void OnRodThrowStart() { - // if (Player.State is PlayerStateThrow playerStateThrow) - // { - // playerStateThrow.OnRodThrowStart(); - // } + if (Player.State == PlayerState.Throw) + { + var playerStateView = Player.GetComponent(); + if (playerStateView.CurrentStateView is PlayerStageViewThrow playerStateThrow) + { + playerStateThrow.OnRodThrowStart(); + } + } } /// @@ -163,10 +167,14 @@ namespace NBF /// public void OnRodThrownEnd() { - // if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow) - // { - // playerStateThrow.OnRodThrownEnd(); - // } + if (Player.State == PlayerState.Throw) + { + var playerStateView = Player.GetComponent(); + if (playerStateView.CurrentStateView is PlayerStageViewThrow playerStateThrow) + { + playerStateThrow.OnRodThrownEnd(); + } + } } #endregion diff --git a/Assets/Scripts/Fishing/New/View/Player/PlayerStateView.cs b/Assets/Scripts/Fishing/New/View/Player/PlayerStateView.cs index eb0bd363c..4e854ec99 100644 --- a/Assets/Scripts/Fishing/New/View/Player/PlayerStateView.cs +++ b/Assets/Scripts/Fishing/New/View/Player/PlayerStateView.cs @@ -16,6 +16,8 @@ namespace NBF private PlayerStageViewBase _currentStateView; private Player _player; + public PlayerStageViewBase CurrentStateView => _currentStateView; + public void Awake() { _player = GetParent(); diff --git a/Assets/Scripts/Fishing/New/View/Player/States/PlayerStageViewBase.cs b/Assets/Scripts/Fishing/New/View/Player/States/PlayerStageViewBase.cs index 03b0b0f22..36c3d94c4 100644 --- a/Assets/Scripts/Fishing/New/View/Player/States/PlayerStageViewBase.cs +++ b/Assets/Scripts/Fishing/New/View/Player/States/PlayerStageViewBase.cs @@ -3,6 +3,36 @@ using UnityEngine; namespace NBF { + public enum PlayerState : uint + { + None = 0, + + /// + /// 闲置等待中 + /// + Idle = 1, + + /// + /// 准备抛竿 + /// + Prepare = 2, + + /// + /// 抛竿中 + /// + Throw = 3, + + /// + /// 钓鱼中 + /// + Fishing = 4, + + /// + /// 溜鱼中 + /// + Fight = 5 + } + public abstract class PlayerStageViewBase { public Player Player { get; private set; } diff --git a/Assets/Scripts/Fishing/New/View/Player/Tackle/FRod.cs b/Assets/Scripts/Fishing/New/View/Player/Tackle/FRod.cs index 2295455dd..3f97726d5 100644 --- a/Assets/Scripts/Fishing/New/View/Player/Tackle/FRod.cs +++ b/Assets/Scripts/Fishing/New/View/Player/Tackle/FRod.cs @@ -12,17 +12,10 @@ namespace NBF { public class FRod : FHandItem { - private float _tension; - public PlayerItem PlayerItem; public override int ConfigId => PlayerItem?.ConfigID ?? 0; - /// - /// 可用的 - /// - 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; - /// - /// 线长度 - /// - public float lineLength = 1.5f; - - /// - /// 浮漂线长度 - /// - 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; }