From 7b2a93d67360ad7101df32d9aa6f9e743530246f Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Sun, 18 Jan 2026 01:05:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E8=A7=86=E8=A7=92=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResRaw/Prefabs/Player/Human_Male.prefab | 19 +++++++ Assets/Scenes/StartUp.unity | 7 +-- Assets/Scripts/Common/Utils/GameUtils.cs | 49 +++++++++++++++++++ Assets/Scripts/Common/Utils/GameUtils.cs.meta | 3 ++ Assets/Scripts/Fishing/Player/FPlayer.cs | 3 ++ Assets/Scripts/Fishing/Player/FPlayerData.cs | 6 +++ Assets/Scripts/Fishing/Player/PlayerArm.cs | 18 ++++++- Assets/Scripts/Fishing/Player/PlayerChest.cs | 25 ++++++++++ .../Fishing/Player/PlayerChest.cs.meta | 3 ++ 9 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 Assets/Scripts/Common/Utils/GameUtils.cs create mode 100644 Assets/Scripts/Common/Utils/GameUtils.cs.meta create mode 100644 Assets/Scripts/Fishing/Player/PlayerChest.cs create mode 100644 Assets/Scripts/Fishing/Player/PlayerChest.cs.meta diff --git a/Assets/ResRaw/Prefabs/Player/Human_Male.prefab b/Assets/ResRaw/Prefabs/Player/Human_Male.prefab index 3a507f6c0..4351f05d9 100644 --- a/Assets/ResRaw/Prefabs/Player/Human_Male.prefab +++ b/Assets/ResRaw/Prefabs/Player/Human_Male.prefab @@ -1577,6 +1577,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 7242152361089127277, guid: 284185ec1f1e5c6409bed7bc27c6c215, type: 3} insertIndex: -1 addedObject: {fileID: 2392158382265859538} + - targetCorrespondingSourceObject: {fileID: 7242152361089127277, guid: 284185ec1f1e5c6409bed7bc27c6c215, type: 3} + insertIndex: -1 + addedObject: {fileID: 2233472743962583192} - targetCorrespondingSourceObject: {fileID: 4070688717456758137, guid: 284185ec1f1e5c6409bed7bc27c6c215, type: 3} insertIndex: -1 addedObject: {fileID: 7412159401566189008} @@ -3466,8 +3469,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 01ef40348d8b4d4da250acf0a921fc2a, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::NBF.PlayerArm + FixLowerArm: 0 IsLeft: 0 IK: {fileID: 6957666202517838931} + LowerArm: {fileID: 7537462892583471047} RodContainer: {fileID: 2827152078700489346} FingerRig: {fileID: 2621265606016813142} interactionTargetWeight: 0 @@ -5055,8 +5060,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 01ef40348d8b4d4da250acf0a921fc2a, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::NBF.PlayerArm + FixLowerArm: 0 IsLeft: 1 IK: {fileID: 482972912705027537} + LowerArm: {fileID: 2505921912821122484} RodContainer: {fileID: 5757538020472164704} FingerRig: {fileID: 5186464396902472690} interactionTargetWeight: 0 @@ -5493,6 +5500,18 @@ CharacterJoint: m_EnablePreprocessing: 0 m_MassScale: 1 m_ConnectedMassScale: 1 +--- !u!114 &2233472743962583192 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7486795965464388375} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e152a74e74b54d17ace5403a1570e12a, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::NBF.PlayerChest --- !u!4 &7497490466774393111 stripped Transform: m_CorrespondingSourceObject: {fileID: -1482997459186921107, guid: 284185ec1f1e5c6409bed7bc27c6c215, type: 3} diff --git a/Assets/Scenes/StartUp.unity b/Assets/Scenes/StartUp.unity index 0b7d26cf9..f0024a1aa 100644 --- a/Assets/Scenes/StartUp.unity +++ b/Assets/Scenes/StartUp.unity @@ -756,7 +756,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1127680710956633387, guid: 0893171cfcdca8943a3322a9a261c693, type: 3} propertyPath: m_IsActive - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2193713676330198984, guid: 0893171cfcdca8943a3322a9a261c693, type: 3} propertyPath: m_Enabled @@ -1629,8 +1629,8 @@ Camera: y: 0 width: 1 height: 1 - near clip plane: 0.1 - far clip plane: 3000 + near clip plane: 0.01 + far clip plane: 5000 field of view: 60.000004 orthographic: 0 orthographic size: 5 @@ -1824,6 +1824,7 @@ MonoBehaviour: LineTension: 0 IsLureRod: 0 MoveInput: {x: 0, y: 0} + EyeAngle: 0 NextState: 0 --- !u!1660057539 &9223372036854775807 SceneRoots: diff --git a/Assets/Scripts/Common/Utils/GameUtils.cs b/Assets/Scripts/Common/Utils/GameUtils.cs new file mode 100644 index 000000000..66de892ff --- /dev/null +++ b/Assets/Scripts/Common/Utils/GameUtils.cs @@ -0,0 +1,49 @@ +using UnityEngine; + +namespace NBF +{ + public static class GameUtils + { + public static float GetVerticalAngle(Transform character, Transform target) + { + // 计算从角色指向目标的向量 + Vector3 direction = target.position - character.position; + + // 计算水平距离(XZ平面) + float horizontalDistance = new Vector3(direction.x, 0, direction.z).magnitude; + + // 计算垂直高度差(Y轴) + float verticalDistance = direction.y; + + // 使用反正切计算垂直角度 + // Atan2(垂直距离, 水平距离) + float angle = Mathf.Atan2(verticalDistance, horizontalDistance) * Mathf.Rad2Deg; + + return angle; // 正值为上方,负值为下方 + } + + public static float GetHorizontalAngle(Transform obj1, Transform obj2) + { + // 获取两个物体在水平面上的位置向量 + Vector3 pos1 = obj1.position; + Vector3 pos2 = obj2.position; + + // 创建水平方向向量(忽略Y轴) + Vector3 direction = new Vector3( + pos2.x - pos1.x, + 0, // Y轴设为0,只在XZ平面计算 + pos2.z - pos1.z + ); + + // 计算相对于世界坐标系前向向量的角度 + float angle = Vector3.SignedAngle( + Vector3.forward, // 参考方向(世界坐标系前向) + direction.normalized, + Vector3.up // 旋转轴(Y轴) + ); + + // 返回角度范围:-180° 到 180° + return angle; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Utils/GameUtils.cs.meta b/Assets/Scripts/Common/Utils/GameUtils.cs.meta new file mode 100644 index 000000000..dc0feaa5f --- /dev/null +++ b/Assets/Scripts/Common/Utils/GameUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a1e142c7ecd747eaa6971907ecae2c44 +timeCreated: 1768661644 \ No newline at end of file diff --git a/Assets/Scripts/Fishing/Player/FPlayer.cs b/Assets/Scripts/Fishing/Player/FPlayer.cs index 13cce2115..2a4c729ac 100644 --- a/Assets/Scripts/Fishing/Player/FPlayer.cs +++ b/Assets/Scripts/Fishing/Player/FPlayer.cs @@ -40,6 +40,7 @@ namespace NBF FirstPerson = gameObject.GetComponent(); Data = FPlayerData.Instance; transform.localPosition = new Vector3(484, 1, 422); + // Data.NeedChangeRightArmAngle = true; } private void Start() @@ -53,6 +54,8 @@ namespace NBF { UpdateMove(); Fsm?.Update(); + + Data.EyeAngle = GameUtils.GetVerticalAngle(transform, FppLook); } private void OnDestroy() diff --git a/Assets/Scripts/Fishing/Player/FPlayerData.cs b/Assets/Scripts/Fishing/Player/FPlayerData.cs index 2283cbd9a..55dbf2c2d 100644 --- a/Assets/Scripts/Fishing/Player/FPlayerData.cs +++ b/Assets/Scripts/Fishing/Player/FPlayerData.cs @@ -28,6 +28,7 @@ namespace NBF public enum PlayerState : uint { None = 0, + /// /// 闲置等待中 /// @@ -74,6 +75,11 @@ namespace NBF public Vector2 MoveInput; + /// + /// + /// + public float EyeAngle; + public PlayerState PreviousState => _previousPlayerState; diff --git a/Assets/Scripts/Fishing/Player/PlayerArm.cs b/Assets/Scripts/Fishing/Player/PlayerArm.cs index 7e37c7c6b..80ab2efc3 100644 --- a/Assets/Scripts/Fishing/Player/PlayerArm.cs +++ b/Assets/Scripts/Fishing/Player/PlayerArm.cs @@ -1,15 +1,29 @@ -using RootMotion.FinalIK; +using System; +using RootMotion.FinalIK; using UnityEngine; namespace NBF { public class PlayerArm : MonoBehaviour { + public bool FixLowerArm; public bool IsLeft; public LimbIK IK; + public Transform LowerArm; public Transform RodContainer; public FingerRig FingerRig; - + + [HideInInspector] public float interactionTargetWeight; + + private const int MaxFixEyeAngle = 15; + + public void Awake() + { + } + + private void LateUpdate() + { + } } } \ No newline at end of file diff --git a/Assets/Scripts/Fishing/Player/PlayerChest.cs b/Assets/Scripts/Fishing/Player/PlayerChest.cs new file mode 100644 index 000000000..1bee577c5 --- /dev/null +++ b/Assets/Scripts/Fishing/Player/PlayerChest.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace NBF +{ + public class PlayerChest : MonoBehaviour + { + private const int MaxFixEyeAngle = 15; + private const int MinFixEyeAngle = -10; + + private void LateUpdate() + { + FixArmAngle(); + } + + private void FixArmAngle() + { + var angle = FPlayerData.Instance.EyeAngle; + + if (angle > MaxFixEyeAngle) angle = MaxFixEyeAngle; + else if (angle < MinFixEyeAngle) angle = MinFixEyeAngle; + var val = transform.localEulerAngles; + transform.localEulerAngles = new Vector3(val.x, val.y, val.z - angle); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Fishing/Player/PlayerChest.cs.meta b/Assets/Scripts/Fishing/Player/PlayerChest.cs.meta new file mode 100644 index 000000000..b4bf77904 --- /dev/null +++ b/Assets/Scripts/Fishing/Player/PlayerChest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e152a74e74b54d17ace5403a1570e12a +timeCreated: 1768668096 \ No newline at end of file