From cdcb007d6dca4795c8fbb248d1e56a2c7873b585 Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Wed, 28 May 2025 23:45:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9FPS=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Honeti/MorpheusGUI/Scenes/DemoScene.unity | 51 +-- Assets/Resources/Prefabs/Player/male.prefab | 219 +++++++++++- Assets/Scripts/FirstPersonController.meta | 3 + .../FirstPersonController.cs | 324 ++++++++++++++++++ .../FirstPersonController.cs.meta | 3 + .../FirstPersonController/MouseLook.cs | 132 +++++++ .../FirstPersonController/MouseLook.cs.meta | 3 + .../FirstPersonController/Utility.meta | 3 + .../Utility/CurveControlledBob.cs | 54 +++ .../Utility/CurveControlledBob.cs.meta | 3 + .../FirstPersonController/Utility/FOVKick.cs | 72 ++++ .../Utility/FOVKick.cs.meta | 3 + .../Utility/LerpControlledBob.cs | 40 +++ .../Utility/LerpControlledBob.cs.meta | 3 + Assets/Scripts/Fishing/Player/FPlayer.cs | 3 +- .../Player/PlayerCharacter/FPlayerMainSync.cs | 143 ++++++++ .../PlayerCharacter/FPlayerMainSync.cs.meta | 3 + UserSettings/EditorUserSettings.asset | 4 +- 18 files changed, 1012 insertions(+), 54 deletions(-) create mode 100644 Assets/Scripts/FirstPersonController.meta create mode 100644 Assets/Scripts/FirstPersonController/FirstPersonController.cs create mode 100644 Assets/Scripts/FirstPersonController/FirstPersonController.cs.meta create mode 100644 Assets/Scripts/FirstPersonController/MouseLook.cs create mode 100644 Assets/Scripts/FirstPersonController/MouseLook.cs.meta create mode 100644 Assets/Scripts/FirstPersonController/Utility.meta create mode 100644 Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs create mode 100644 Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs.meta create mode 100644 Assets/Scripts/FirstPersonController/Utility/FOVKick.cs create mode 100644 Assets/Scripts/FirstPersonController/Utility/FOVKick.cs.meta create mode 100644 Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs create mode 100644 Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs.meta create mode 100644 Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs create mode 100644 Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs.meta diff --git a/Assets/Honeti/MorpheusGUI/Scenes/DemoScene.unity b/Assets/Honeti/MorpheusGUI/Scenes/DemoScene.unity index 55bcc91ce..e2dfc2d5f 100644 --- a/Assets/Honeti/MorpheusGUI/Scenes/DemoScene.unity +++ b/Assets/Honeti/MorpheusGUI/Scenes/DemoScene.unity @@ -7490,7 +7490,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -60} + m_AnchoredPosition: {x: 0, y: -60.000122} m_SizeDelta: {x: 70, y: -120} m_Pivot: {x: 1, y: 1} --- !u!114 &56942380 @@ -84095,7 +84095,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -60.000244} + m_AnchoredPosition: {x: 0, y: -60} m_SizeDelta: {x: 20, y: -120} m_Pivot: {x: 1, y: 1} --- !u!114 &744733221 @@ -134448,7 +134448,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -60.000244} + m_AnchoredPosition: {x: 0, y: -60} m_SizeDelta: {x: 20, y: -120} m_Pivot: {x: 1, y: 1} --- !u!114 &1162464619 @@ -227071,50 +227071,6 @@ MonoBehaviour: m_ChildScaleWidth: 0 m_ChildScaleHeight: 0 m_ReverseArrangement: 0 ---- !u!1 &1950491582 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1950491584} - - component: {fileID: 1950491583} - m_Layer: 0 - m_Name: ScreenshotCapturer - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1950491583 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1950491582} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0c9b2dc114877d3479675dbe81e42739, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!4 &1950491584 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1950491582} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 555.19385, y: 829.94635, z: -225.59857} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1951076298 GameObject: m_ObjectHideFlags: 0 @@ -257655,4 +257611,3 @@ SceneRoots: - {fileID: 519420032} - {fileID: 2059699478} - {fileID: 1278188414} - - {fileID: 1950491584} diff --git a/Assets/Resources/Prefabs/Player/male.prefab b/Assets/Resources/Prefabs/Player/male.prefab index 573193880..2012b05a5 100644 --- a/Assets/Resources/Prefabs/Player/male.prefab +++ b/Assets/Resources/Prefabs/Player/male.prefab @@ -4133,6 +4133,8 @@ GameObject: - component: {fileID: 7406758408172975810} - component: {fileID: 1556947158619780183} - component: {fileID: 6041496193769315420} + - component: {fileID: 5826410683169617913} + - component: {fileID: 762483851572320120} m_Layer: 9 m_Name: male m_TagString: Untagged @@ -4523,7 +4525,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5559475303044247694} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 8a5e05c5b0509214d911dd005a610d9a, type: 3} m_Name: @@ -4562,7 +4564,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5559475303044247694} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: dcefd1090dc44a539b4fcd30f2adf503, type: 3} m_Name: @@ -4633,7 +4635,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5559475303044247694} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 776adaaacdc5c4e8ab0395120a6e972b, type: 3} m_Name: @@ -4700,6 +4702,217 @@ MonoBehaviour: m_PostInfinity: 2 m_RotationOrder: 4 spineTargetOffset: {x: 0, y: 0, z: 0} +--- !u!143 &5826410683169617913 +CharacterController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5559475303044247694} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Height: 1.8 + m_Radius: 0.3 + m_SlopeLimit: 45 + m_StepOffset: 0.3 + m_SkinWidth: 0.08 + m_MinMoveDistance: 0.001 + m_Center: {x: 0, y: 0.82, z: 0} +--- !u!114 &762483851572320120 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5559475303044247694} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2f1324aa5e564035ab9a361499a66c27, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IsWalking: 0 + m_WalkSpeed: 2 + m_RunSpeed: 5 + m_RunstepLenghten: 0.5 + m_JumpSpeed: 5 + m_StickToGroundForce: 10 + m_GravityMultiplier: 2 + m_MouseLook: + XSensitivity: 1 + YSensitivity: 1 + clampVerticalRotation: 1 + MinimumX: -45 + MaximumX: 75 + smooth: 1 + smoothTime: 7 + lockCursor: 1 + RotYvalue: 0 + invertMouseY: 0 + invertMouseX: 0 + ControllerHandMode: 0 + m_UseFovKick: 0 + m_FovKick: + Camera: {fileID: 0} + originalFov: 0 + FOVIncrease: 3 + TimeToIncrease: 1 + TimeToDecrease: 1 + IncreaseCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + m_UseHeadBob: 0 + m_HeadBob: + HorizontalBobRange: 0.05 + VerticalBobRange: 0.05 + Bobcurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.5 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1.5 + value: -1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 2 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + VerticaltoHorizontalRatio: 2 + m_JumpBob: + BobDuration: 0.2 + BobAmount: 0.1 + m_StepInterval: 3 + m_FootstepSounds: + - {fileID: 8300000, guid: 912ed2fe716debb4eab367c27b70f7a0, type: 3} + - {fileID: 8300000, guid: 06ab58800db672f419b0149dbd7d1db5, type: 3} + - {fileID: 8300000, guid: 1a647781ecb3c6b4db6e9dc943f85160, type: 3} + - {fileID: 8300000, guid: 9edadee383ff9704288d2b958e45f31a, type: 3} + - {fileID: 8300000, guid: 7a7faf44f2d75c34db2771b4e1c5b84a, type: 3} + - {fileID: 8300000, guid: c11d0047c50c9874e9f5db3a8d2a5e7c, type: 3} + - {fileID: 8300000, guid: 9fb2b242a24b83141820d187c1ad4dfb, type: 3} + - {fileID: 8300000, guid: 8796f1a26bb1663438d614e0748d3a76, type: 3} + - {fileID: 8300000, guid: f030710473725e041bffea7ae8058942, type: 3} + - {fileID: 8300000, guid: a29e18d1e53414f42866dd998a0fafc6, type: 3} + m_FootstepSoundsBridge: + - {fileID: 8300000, guid: bd0a87842a553c3428e9a991240e5b6d, type: 3} + - {fileID: 8300000, guid: 659ced4e98e82144d95e317d4ca3ff8d, type: 3} + - {fileID: 8300000, guid: d0f2717818c424349baac5713763a7bc, type: 3} + - {fileID: 8300000, guid: eef8e14bf3d25434595afb6f4e5408f5, type: 3} + - {fileID: 8300000, guid: 3fce4a1b6054f1948afac9845d7e7130, type: 3} + - {fileID: 8300000, guid: efc8500e12553de4eb29668ca9ebedaf, type: 3} + - {fileID: 8300000, guid: 703968afd8f32594e905301bf63e962e, type: 3} + - {fileID: 8300000, guid: 8301b2892b7374f4387cf0fca37e15da, type: 3} + - {fileID: 8300000, guid: 97965cc4498053e4c9119084a384260c, type: 3} + - {fileID: 8300000, guid: 2b746b45ba59fc94293394fee46681c2, type: 3} + - {fileID: 8300000, guid: 8a4e93c8fecd2c747bf61c82b0559110, type: 3} + - {fileID: 8300000, guid: 5b637ae65772be64d808e83f26247acd, type: 3} + - {fileID: 8300000, guid: 584c514b3ca067443a4ddee923d866c4, type: 3} + - {fileID: 8300000, guid: 1a5b66c9098c2e54e96af3d64cd8f3a0, type: 3} + - {fileID: 8300000, guid: c909dab26a4b9fb4b92081dba0858522, type: 3} + - {fileID: 8300000, guid: 0b2fe3ac8a255a249ae86e3e12df849a, type: 3} + - {fileID: 8300000, guid: 32c9d0d6136f26047aaf2dc55d4107c2, type: 3} + - {fileID: 8300000, guid: 54ed3af519a482544b379c6a0ccebcd9, type: 3} + - {fileID: 8300000, guid: b24e90347e5ba934184564234768a95b, type: 3} + - {fileID: 8300000, guid: b1d207273bbb1cf4abb3d988425fb325, type: 3} + - {fileID: 8300000, guid: 5cb197f90b9e26644b25b61beb1106a7, type: 3} + - {fileID: 8300000, guid: 165a3214d0daa6d4aac09479a07ba7f0, type: 3} + - {fileID: 8300000, guid: 21c7835e8db44e04db219cb8961eb564, type: 3} + - {fileID: 8300000, guid: 7c8f9d517cd090845a5078716966d5b9, type: 3} + - {fileID: 8300000, guid: 462fa001b2b45a041ac3efc2b76e9351, type: 3} + - {fileID: 8300000, guid: 9de152505c5fd8f42a532aa16b6172ca, type: 3} + - {fileID: 8300000, guid: 4ae8eb6661beb0541bf8b9f6db46a227, type: 3} + - {fileID: 8300000, guid: b7136bb651f70ff459a93a5a5668c191, type: 3} + - {fileID: 8300000, guid: 12b1240febfb7bb4bb9330bea6e9bf2c, type: 3} + - {fileID: 8300000, guid: 2060723f0d3343946b5766ccce9183c4, type: 3} + m_FootstepSoundsStone: + - {fileID: 8300000, guid: 8e72d0aa866b57c45820eba64fd0f108, type: 3} + - {fileID: 8300000, guid: 93d2a4fdc51c57549a27998c40db069f, type: 3} + - {fileID: 8300000, guid: a4c13d07d4097ad4aae38fae8be2cbf3, type: 3} + - {fileID: 8300000, guid: 4665be96d319fed47a131e4570aa5d02, type: 3} + - {fileID: 8300000, guid: f13515bee2f8d254d87e4c0032423169, type: 3} + - {fileID: 8300000, guid: 7a63c182d9c7db141afd2f7b13ec0772, type: 3} + m_JumpSound: {fileID: 8300000, guid: 89f36de37219b6e4ebe1bdac9d24677c, type: 3} + m_LandSound: {fileID: 8300000, guid: 7f0942ac0ccaae649a1685e0890b7c64, type: 3} + frezzeRotation: 0 + frezzePosition: 0 + rotateMouseInFixedUpdate: 1 + m_Input: {x: 0, y: 0} + m_MoveDir: {x: 0, y: 0, z: 0} + m_CharacterController: {fileID: 5826410683169617913} + horizontal: 0 + vertical: 0 + isJumping: 0 + isRuning: 0 + notMove: 0 + isWater: 0 --- !u!1 &5735120231836046354 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/FirstPersonController.meta b/Assets/Scripts/FirstPersonController.meta new file mode 100644 index 000000000..6fbe39330 --- /dev/null +++ b/Assets/Scripts/FirstPersonController.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 19ffa462a8ae4066a12d946a8b80cab0 +timeCreated: 1748446110 \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/FirstPersonController.cs b/Assets/Scripts/FirstPersonController/FirstPersonController.cs new file mode 100644 index 000000000..5d21c278e --- /dev/null +++ b/Assets/Scripts/FirstPersonController/FirstPersonController.cs @@ -0,0 +1,324 @@ +using UnityEngine; + +namespace NBF +{ + [RequireComponent(typeof(CharacterController))] + [RequireComponent(typeof(AudioSource))] + public class FirstPersonController : MonoBehaviour + { + [SerializeField] private bool m_IsWalking; + + [SerializeField] public float m_WalkSpeed; + + [SerializeField] public float m_RunSpeed; + + [SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten; + + [SerializeField] private float m_JumpSpeed; + + [SerializeField] private float m_StickToGroundForce; + + [SerializeField] private float m_GravityMultiplier; + + [SerializeField] public MouseLook m_MouseLook; + + [SerializeField] private bool m_UseFovKick; + + [SerializeField] private FOVKick m_FovKick = new FOVKick(); + + [SerializeField] private bool m_UseHeadBob; + + [SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob(); + + [SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob(); + + [SerializeField] private float m_StepInterval; + + [SerializeField] private AudioClip[] m_FootstepSounds; + + [SerializeField] private AudioClip[] m_FootstepSoundsBridge; + + [SerializeField] private AudioClip[] m_FootstepSoundsStone; + + [SerializeField] private AudioClip m_JumpSound; + + [SerializeField] private AudioClip m_LandSound; + + private Camera m_Camera; + + private bool m_Jump; + + public bool frezzeRotation; + + public bool frezzePosition; + + public bool rotateMouseInFixedUpdate = true; + + public Vector2 m_Input; + + public Vector3 m_MoveDir = Vector3.zero; + + public CharacterController m_CharacterController; + + private CollisionFlags m_CollisionFlags; + + private bool m_PreviouslyGrounded; + + private Vector3 m_OriginalCameraPosition; + + private float m_StepCycle; + + private float m_NextStep; + + private bool m_Jumping; + + private AudioSource m_AudioSource; + + private string groundTypeTag = ""; + + public float horizontal; + + public float vertical; + + public bool isJumping; + + public bool isRuning; + + public bool notMove; + + public bool isWater; + + private void Start() + { + m_CharacterController = GetComponent(); + m_Camera = Camera.main; + m_OriginalCameraPosition = m_Camera.transform.localPosition; + m_FovKick.Setup(m_Camera); + m_HeadBob.Setup(m_Camera, m_StepInterval); + m_StepCycle = 0f; + m_NextStep = m_StepCycle / 2f; + m_Jumping = false; + m_AudioSource = GetComponent(); + m_MouseLook.Init(transform, m_Camera.transform); + } + + private void Update() + { + if (!frezzeRotation && !rotateMouseInFixedUpdate) + { + RotateView(); + } + + if (!m_Jump) + { + m_Jump = isJumping; + } + + if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) + { + StartCoroutine(m_JumpBob.DoBobCycle()); + PlayLandingSound(); + m_MoveDir.y = 0f; + m_Jumping = false; + } + + if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) + { + m_MoveDir.y = 0f; + } + + m_PreviouslyGrounded = m_CharacterController.isGrounded; + } + + private void PlayLandingSound() + { + m_AudioSource.clip = m_LandSound; + m_AudioSource.Play(); + m_NextStep = m_StepCycle + 0.5f; + } + + private void FixedUpdate() + { + if (!frezzeRotation && rotateMouseInFixedUpdate) + { + RotateView(); + } + + if (frezzePosition) + { + return; + } + + GetInput(out var speed); + Vector3 vector = transform.forward * m_Input.y + transform.right * m_Input.x; + Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out var hitInfo, + m_CharacterController.height / 2f, -1, QueryTriggerInteraction.Ignore); + vector = Vector3.ProjectOnPlane(vector, hitInfo.normal).normalized; + m_MoveDir.x = vector.x * speed; + m_MoveDir.z = vector.z * speed; + if (m_CharacterController.isGrounded) + { + m_MoveDir.y = 0f - m_StickToGroundForce; + if (m_Jump && !isWater) + { + if ((bool)transform.parent && transform.parent.gameObject.layer == LayerMask.NameToLayer("Boat")) + { + return; + } + + m_MoveDir.y = m_JumpSpeed; + PlayJumpSound(); + m_Jump = false; + m_Jumping = true; + } + } + else + { + m_MoveDir += Physics.gravity * m_GravityMultiplier * Time.fixedDeltaTime; + } + + if (!notMove) + { + m_CollisionFlags = m_CharacterController.Move(m_MoveDir * Time.fixedDeltaTime); + } + + ProgressStepCycle(speed); + UpdateCameraPosition(speed); + m_MouseLook.UpdateCursorLock(); + } + + private void PlayJumpSound() + { + m_AudioSource.clip = m_JumpSound; + m_AudioSource.Play(); + } + + private void ProgressStepCycle(float speed) + { + if (m_CharacterController.velocity.sqrMagnitude > 0f && (m_Input.x != 0f || m_Input.y != 0f)) + { + m_StepCycle += + (m_CharacterController.velocity.magnitude + speed * (m_IsWalking ? 1f : m_RunstepLenghten)) * + Time.fixedDeltaTime; + } + + if (m_StepCycle > m_NextStep) + { + m_NextStep = m_StepCycle + m_StepInterval; + PlayFootStepAudio(); + } + } + + private void PlayFootStepAudio() + { + if (!m_CharacterController.isGrounded) + { + return; + } + + if (groundTypeTag == "Bridge" || groundTypeTag == "Boat") + { + if (m_FootstepSoundsBridge.Length != 0) + { + int num = Random.Range(1, m_FootstepSoundsBridge.Length); + m_AudioSource.clip = m_FootstepSoundsBridge[num]; + m_AudioSource.PlayOneShot(m_AudioSource.clip, 0.3f); + m_FootstepSoundsBridge[num] = m_FootstepSoundsBridge[0]; + m_FootstepSoundsBridge[0] = m_AudioSource.clip; + } + } + else if (groundTypeTag == "Stone") + { + if (m_FootstepSoundsStone.Length != 0) + { + int num2 = Random.Range(1, m_FootstepSoundsStone.Length); + m_AudioSource.clip = m_FootstepSoundsStone[num2]; + m_AudioSource.PlayOneShot(m_AudioSource.clip, 0.3f); + m_FootstepSoundsStone[num2] = m_FootstepSoundsStone[0]; + m_FootstepSoundsStone[0] = m_AudioSource.clip; + } + } + else if (m_FootstepSounds.Length != 0) + { + int num3 = Random.Range(1, m_FootstepSounds.Length); + m_AudioSource.clip = m_FootstepSounds[num3]; + m_AudioSource.PlayOneShot(m_AudioSource.clip, 0.3f); + m_FootstepSounds[num3] = m_FootstepSounds[0]; + m_FootstepSounds[0] = m_AudioSource.clip; + } + } + + private void UpdateCameraPosition(float speed) + { + if (m_UseHeadBob) + { + Vector3 localPosition; + if (m_CharacterController.velocity.magnitude > 0f && m_CharacterController.isGrounded) + { + m_Camera.transform.localPosition = m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude + + speed * + (m_IsWalking ? 1f : m_RunstepLenghten)); + localPosition = m_Camera.transform.localPosition; + localPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset(); + } + else + { + localPosition = m_Camera.transform.localPosition; + localPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset(); + } + + m_Camera.transform.localPosition = localPosition; + } + } + + private void GetInput(out float speed) + { + bool isWalking = m_IsWalking; + m_IsWalking = !isRuning; + speed = (m_IsWalking ? m_WalkSpeed : m_RunSpeed); + m_Input = new Vector2(horizontal, vertical); + if (m_Input.sqrMagnitude > 1f) + { + m_Input.Normalize(); + } + + if (m_IsWalking != isWalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0f) + { + StopAllCoroutines(); + StartCoroutine((!m_IsWalking) ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown()); + } + } + + public void RotateView() + { + m_MouseLook.LookRotation(transform, m_Camera.transform); + } + + private void OnControllerColliderHit(ControllerColliderHit hit) + { + Rigidbody attachedRigidbody = hit.collider.attachedRigidbody; + groundTypeTag = hit.collider.tag; + + if (m_CollisionFlags != CollisionFlags.Below && !(attachedRigidbody == null)) + { + _ = attachedRigidbody.isKinematic; + } + } + + private void OnTriggerStay(Collider other) + { + if (other.CompareTag("Water")) + { + isWater = true; + } + } + + private void OnTriggerExit(Collider other) + { + if (other.CompareTag("Water")) + { + isWater = false; + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/FirstPersonController.cs.meta b/Assets/Scripts/FirstPersonController/FirstPersonController.cs.meta new file mode 100644 index 000000000..d9b0baf5d --- /dev/null +++ b/Assets/Scripts/FirstPersonController/FirstPersonController.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2f1324aa5e564035ab9a361499a66c27 +timeCreated: 1748446121 \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/MouseLook.cs b/Assets/Scripts/FirstPersonController/MouseLook.cs new file mode 100644 index 000000000..637e5d314 --- /dev/null +++ b/Assets/Scripts/FirstPersonController/MouseLook.cs @@ -0,0 +1,132 @@ +using System; +using UnityEngine; + +namespace NBF +{ + [Serializable] + public class MouseLook + { + public float XSensitivity = 2f; + + public float YSensitivity = 2f; + + public bool clampVerticalRotation = true; + + public float MinimumX = -90f; + + public float MaximumX = 90f; + + public bool smooth; + + public float smoothTime = 5f; + + public bool lockCursor = true; + + public float RotYvalue; + + public bool invertMouseY; + + public bool invertMouseX; + + public int ControllerHandMode; + + private Quaternion m_CharacterTargetRot; + + private Quaternion m_CameraTargetRot; + + private bool m_cursorIsLocked = true; + + // private Player player; + + public void Init(Transform character, Transform camera) + { + m_CharacterTargetRot = character.localRotation; + m_CameraTargetRot = camera.localRotation; + // player = ReInput.players.GetPlayer(0); + } + + public void LookRotation(Transform character, Transform camera) + { + // if (!SRDebug.Instance.IsDebugPanelVisible && !SRDebug.Instance.IsDebugPanelVisible) + { + var lookInput = InputManager.GetLookInput(); + + float num = Mathf.Clamp(lookInput.y * YSensitivity * 5f * Time.deltaTime, -10f, 10f); + float num2 = + Mathf.Clamp(lookInput.x * XSensitivity * 5f * Time.deltaTime, -10f, 10f); + + if (invertMouseY) + { + num *= -1f; + } + + if (invertMouseX) + { + num2 *= -1f; + } + + RotYvalue = num2; + m_CharacterTargetRot *= Quaternion.Euler(0f, num2, 0f); + m_CameraTargetRot *= Quaternion.Euler(0f - num, 0f, 0f); + if (clampVerticalRotation) + { + m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot); + } + + if (smooth) + { + character.localRotation = Quaternion.Slerp(character.localRotation, m_CharacterTargetRot, + smoothTime * Time.deltaTime); + camera.localRotation = Quaternion.Slerp(camera.localRotation, m_CameraTargetRot, + smoothTime * Time.deltaTime); + } + else + { + character.localRotation = m_CharacterTargetRot; + camera.localRotation = m_CameraTargetRot; + } + + UpdateCursorLock(); + } + } + + public void SetCursorLock(bool value) + { + lockCursor = value; + if (!lockCursor) + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + else + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + } + + public void UpdateCursorLock() + { + if (lockCursor) + { + InternalLockUpdate(); + } + } + + private void InternalLockUpdate() + { + } + + private Quaternion ClampRotationAroundXAxis(Quaternion q) + { + q.x /= q.w; + q.y /= q.w; + q.z /= q.w; + q.w = 1f; + float value = 114.59156f * Mathf.Atan(q.x); + value = Mathf.Clamp(value, MinimumX, MaximumX); + q.x = Mathf.Tan((float)Math.PI / 360f * value); + return q; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/MouseLook.cs.meta b/Assets/Scripts/FirstPersonController/MouseLook.cs.meta new file mode 100644 index 000000000..de0be2096 --- /dev/null +++ b/Assets/Scripts/FirstPersonController/MouseLook.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8d0cbae98ed8408e90ca0cb0e05b6d1d +timeCreated: 1748446245 \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/Utility.meta b/Assets/Scripts/FirstPersonController/Utility.meta new file mode 100644 index 000000000..8109f77cd --- /dev/null +++ b/Assets/Scripts/FirstPersonController/Utility.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8d919912beb546df866a283a379c7e96 +timeCreated: 1748446174 \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs b/Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs new file mode 100644 index 000000000..4426bc8ef --- /dev/null +++ b/Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs @@ -0,0 +1,54 @@ +using System; +using UnityEngine; + +namespace NBF +{ + [Serializable] + public class CurveControlledBob + { + public float HorizontalBobRange = 0.33f; + + public float VerticalBobRange = 0.33f; + + public AnimationCurve Bobcurve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.5f, 1f), + new Keyframe(1f, 0f), new Keyframe(1.5f, -1f), new Keyframe(2f, 0f)); + + public float VerticaltoHorizontalRatio = 1f; + + private float m_CyclePositionX; + + private float m_CyclePositionY; + + private float m_BobBaseInterval; + + private Vector3 m_OriginalCameraPosition; + + private float m_Time; + + public void Setup(Camera camera, float bobBaseInterval) + { + m_BobBaseInterval = bobBaseInterval; + m_OriginalCameraPosition = camera.transform.localPosition; + m_Time = Bobcurve[Bobcurve.length - 1].time; + } + + public Vector3 DoHeadBob(float speed) + { + float x = m_OriginalCameraPosition.x + Bobcurve.Evaluate(m_CyclePositionX) * HorizontalBobRange; + float y = m_OriginalCameraPosition.y + Bobcurve.Evaluate(m_CyclePositionY) * VerticalBobRange; + m_CyclePositionX += speed * Time.deltaTime / m_BobBaseInterval; + m_CyclePositionY += speed * Time.deltaTime / m_BobBaseInterval * VerticaltoHorizontalRatio; + if (m_CyclePositionX > m_Time) + { + m_CyclePositionX -= m_Time; + } + + if (m_CyclePositionY > m_Time) + { + m_CyclePositionY -= m_Time; + } + + return new Vector3(x, y, 0f); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs.meta b/Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs.meta new file mode 100644 index 000000000..7d22c04dc --- /dev/null +++ b/Assets/Scripts/FirstPersonController/Utility/CurveControlledBob.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 491f525f09d84899a13bf70f08f7a713 +timeCreated: 1748446274 \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/Utility/FOVKick.cs b/Assets/Scripts/FirstPersonController/Utility/FOVKick.cs new file mode 100644 index 000000000..4a3d647af --- /dev/null +++ b/Assets/Scripts/FirstPersonController/Utility/FOVKick.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections; +using UnityEngine; + +namespace NBF +{ + [Serializable] + public class FOVKick + { + public Camera Camera; + + [HideInInspector] public float originalFov; + + public float FOVIncrease = 3f; + + public float TimeToIncrease = 1f; + + public float TimeToDecrease = 1f; + + public AnimationCurve IncreaseCurve; + + public void Setup(Camera camera) + { + CheckStatus(camera); + Camera = camera; + originalFov = camera.fieldOfView; + } + + private void CheckStatus(Camera camera) + { + if (camera == null) + { + throw new Exception("FOVKick camera is null, please supply the camera to the constructor"); + } + + if (IncreaseCurve == null) + { + throw new Exception( + "FOVKick Increase curve is null, please define the curve for the field of view kicks"); + } + } + + public void ChangeCamera(Camera camera) + { + Camera = camera; + } + + public IEnumerator FOVKickUp() + { + float t = Mathf.Abs((Camera.fieldOfView - originalFov) / FOVIncrease); + while (t < TimeToIncrease) + { + Camera.fieldOfView = originalFov + IncreaseCurve.Evaluate(t / TimeToIncrease) * FOVIncrease; + t += Time.deltaTime; + yield return new WaitForEndOfFrame(); + } + } + + public IEnumerator FOVKickDown() + { + float t = Mathf.Abs((Camera.fieldOfView - originalFov) / FOVIncrease); + while (t > 0f) + { + Camera.fieldOfView = originalFov + IncreaseCurve.Evaluate(t / TimeToDecrease) * FOVIncrease; + t -= Time.deltaTime; + yield return new WaitForEndOfFrame(); + } + + Camera.fieldOfView = originalFov; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/Utility/FOVKick.cs.meta b/Assets/Scripts/FirstPersonController/Utility/FOVKick.cs.meta new file mode 100644 index 000000000..db4328cc3 --- /dev/null +++ b/Assets/Scripts/FirstPersonController/Utility/FOVKick.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cb6289c553a943a98adf26c14b1eaf2b +timeCreated: 1748446181 \ No newline at end of file diff --git a/Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs b/Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs new file mode 100644 index 000000000..75b78eb8c --- /dev/null +++ b/Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections; +using UnityEngine; + +namespace NBF +{ + [Serializable] + public class LerpControlledBob + { + public float BobDuration; + + public float BobAmount; + + private float m_Offset; + + public float Offset() + { + return m_Offset; + } + + public IEnumerator DoBobCycle() + { + float t2 = 0f; + while (t2 < BobDuration) + { + m_Offset = Mathf.Lerp(0f, BobAmount, t2 / BobDuration); + t2 += Time.deltaTime; + yield return new WaitForFixedUpdate(); + } + t2 = 0f; + while (t2 < BobDuration) + { + m_Offset = Mathf.Lerp(BobAmount, 0f, t2 / BobDuration); + t2 += Time.deltaTime; + yield return new WaitForFixedUpdate(); + } + m_Offset = 0f; + } + } +} diff --git a/Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs.meta b/Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs.meta new file mode 100644 index 000000000..3dd6d9ef9 --- /dev/null +++ b/Assets/Scripts/FirstPersonController/Utility/LerpControlledBob.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1ff17b813690432a9da59c9ab3ceccbb +timeCreated: 1748446293 \ No newline at end of file diff --git a/Assets/Scripts/Fishing/Player/FPlayer.cs b/Assets/Scripts/Fishing/Player/FPlayer.cs index 596efad5d..f7d12ca89 100644 --- a/Assets/Scripts/Fishing/Player/FPlayer.cs +++ b/Assets/Scripts/Fishing/Player/FPlayer.cs @@ -37,7 +37,7 @@ public partial class FPlayer : MonoBehaviour public CapsuleCollider Collider; public Rigidbody Rigidbody; - + private void Awake() { PlayerAnimatorCtrl = gameObject.GetComponent(); @@ -77,6 +77,7 @@ public partial class FPlayer : MonoBehaviour if (data.PlayerID == GameModel.RoleID) { Fishing.Inst.Player.SelfPlayer = this; + var mainSync = gameObject.AddComponent(); BaseCamera.Main.transform.SetParent(CameraRoot); BaseCamera.Main.transform.localPosition = Vector3.zero; } diff --git a/Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs b/Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs new file mode 100644 index 000000000..5f50338e3 --- /dev/null +++ b/Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs @@ -0,0 +1,143 @@ +using NBC; +using UnityEngine; + +namespace NBF +{ + public class FPlayerMainSync : MonoBehaviour + { + public FirstPersonController firstPersonController; + + [HideInInspector] public int nextShowSlotIndex = -1; + + + private float walkingSpeed = 1f; + + private float runningSpeed = 2f; + + private FPlayer _player; + + + private bool _isRun; + + private void Start() + { + firstPersonController = GetComponent(); + walkingSpeed = firstPersonController.m_WalkSpeed; + runningSpeed = firstPersonController.m_RunSpeed; + _player = GetComponent(); + + + transform.position = _player.Data.position; + transform.rotation = _player.Data.rotation; + + + Timer.Once(1f, this, EnableFirstPersonController); + + // App.Inst.SetMouseCurrsor(false); + + // InputManager.OnQuickIndexAction += OnQuickIndexAction; + // InputManager.OnUseTorchAction += OnUseTorchAction; + // InputManager.OnUseTelescopeAction += OnUseTelescopeAction; + + InputManager.OnPlayerCanceled += OnPlayerCanceled; + InputManager.OnPlayerPerformed += OnPlayerPerformed; + } + + private void OnDestroy() + { + InputManager.OnPlayerCanceled -= OnPlayerCanceled; + InputManager.OnPlayerPerformed -= OnPlayerPerformed; + // InputManager.OnQuickIndexAction -= OnQuickIndexAction; + // InputManager.OnUseTorchAction -= OnUseTorchAction; + // InputManager.OnUseTelescopeAction -= OnUseTelescopeAction; + } + + private void OnPlayerPerformed(string action) + { + if (action == "Run") + { + // Sprint(); + _isRun = true; + } + } + + private void OnPlayerCanceled(string action) + { + if (action == "Run") + { + _isRun = false; + // StopSprinting(); + } + else if (action.StartsWith("Quick")) + { + nextShowSlotIndex = int.Parse(action.Substring("Quick".Length)); + } + else if (action == "UseTorch") + { + _player.Data.openLight = !_player.Data.openLight; + } + else if (action == "UseTelescope") + { + _player.Data.openTelescope = !_player.Data.openTelescope; + _player.ToggleTelescope(); + } + } + + private void EnableFirstPersonController() + { + firstPersonController.enabled = true; + } + + private void Update() + { + var movementAxis = InputManager.GetMovementInput(); + if (movementAxis != Vector2.zero) + { + // Debug + } + + firstPersonController.horizontal = movementAxis.x; + firstPersonController.vertical = movementAxis.y; + + // firstPersonController.isJumping = InputManager.IsJumping; + firstPersonController.isRuning = _isRun; + + // firstPersonController.m_MouseLook.ControllerHandMode = GameManager.Instance._playerData + // .Player[GameManager.Instance._playerData.currentPlayerProfileIndex].controllerSetup; + + + if (firstPersonController.isWater) + { + firstPersonController.m_WalkSpeed = walkingSpeed - Mathf.Abs(transform.position.y - 1f); + firstPersonController.m_RunSpeed = firstPersonController.m_WalkSpeed; + firstPersonController.m_WalkSpeed = Mathf.Clamp(firstPersonController.m_WalkSpeed, 0.7f, 2f); + firstPersonController.m_RunSpeed = Mathf.Clamp(firstPersonController.m_RunSpeed, 0.8f, 2f); + } + else + { + firstPersonController.m_WalkSpeed = walkingSpeed; + firstPersonController.m_RunSpeed = runningSpeed; + } + + + if (_player.CanChangeGear()) + { + if (nextShowSlotIndex > 0) + { + Debug.LogError("切换钓组========="); + var data = Fishing.Inst.Datasource; + data.SetSelfTestGear(nextShowSlotIndex); + nextShowSlotIndex = -1; + } + } + } + + private void FixedUpdate() + { + if (_player.MainArm) + { + // _player.MainArm.Shoulder.SetCameraEulerAngleX(BaseCamera.Main.transform.localEulerAngles.x); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs.meta b/Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs.meta new file mode 100644 index 000000000..e76a602b5 --- /dev/null +++ b/Assets/Scripts/Fishing/Player/PlayerCharacter/FPlayerMainSync.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5cf18b87277f477ab6a9b59759ee17cb +timeCreated: 1748446764 \ No newline at end of file diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index d8590474b..853d42fec 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -33,10 +33,10 @@ EditorUserSettings: value: 500606050702510d0e570876137a09441516197b782925632e2a4d64b3b16169 flags: 0 RecentlyUsedSceneGuid-8: - value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e + value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661 flags: 0 RecentlyUsedSceneGuid-9: - value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661 + value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e flags: 0 vcSharedLogLevel: value: 0d5e400f0650