From 926aded95d0a74d0d492f3bff336c2e00fa89681 Mon Sep 17 00:00:00 2001 From: Stedd Date: Fri, 14 Oct 2022 20:17:59 +0200 Subject: [PATCH] Cleanup --- Assets/Animation/AttackAnimation.anim | 14 -- Assets/Enemies/EnemyAttack.cs | 2 +- .../Prefabs/PlayerCapsule.prefab | 41 +----- .../Scripts/FirstPersonController.cs | 22 +-- .../InputSystem/MainPlayerInputs.inputactions | 90 ++++++++++++- Assets/InputSystem/StarterAssetsInputs.cs | 127 ++++++++++-------- Assets/Weapons/Revolver.prefab | 5 +- ProjectSettings/EditorBuildSettings.asset | 5 +- 8 files changed, 183 insertions(+), 123 deletions(-) diff --git a/Assets/Animation/AttackAnimation.anim b/Assets/Animation/AttackAnimation.anim index 9cd6445..523bd28 100644 --- a/Assets/Animation/AttackAnimation.anim +++ b/Assets/Animation/AttackAnimation.anim @@ -814,13 +814,6 @@ AnimationClip: floatParameter: 0 intParameter: 0 messageOptions: 0 - - time: 0.25 - functionName: AttackHitEvent - data: - objectReferenceParameter: {fileID: 0} - floatParameter: 0 - intParameter: 0 - messageOptions: 0 - time: 0.41666666 functionName: AttackHitEvent data: @@ -828,10 +821,3 @@ AnimationClip: floatParameter: 0 intParameter: 0 messageOptions: 0 - - time: 0.5833333 - functionName: AttackHitEvent - data: - objectReferenceParameter: {fileID: 0} - floatParameter: 0 - intParameter: 0 - messageOptions: 0 diff --git a/Assets/Enemies/EnemyAttack.cs b/Assets/Enemies/EnemyAttack.cs index 1ce9429..b9851e5 100644 --- a/Assets/Enemies/EnemyAttack.cs +++ b/Assets/Enemies/EnemyAttack.cs @@ -18,4 +18,4 @@ public class EnemyAttack : MonoBehaviour Debug.Log($"{transform.name} Hits {_target.transform.name}"); _target.GetComponent().ModifyHealth(-_damage); } - +} \ No newline at end of file diff --git a/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab b/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab index 19df176..4ca03dd 100644 --- a/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab +++ b/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab @@ -48,40 +48,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 01ef216392c8f33409f2efcd91f4e510, type: 3} m_Name: m_EditorClassIdentifier: - fireAction: - m_Name: Fire - m_Type: 0 - m_ExpectedControlType: - m_Id: 1ed57d50-dc55-4571-aecd-b32a46cca345 - m_Processors: - m_Interactions: - m_SingletonActionBindings: - - m_Name: - m_Id: 9820ce96-b93a-4117-a273-5fff0a8424d5 - m_Path: /leftButton - m_Interactions: - m_Processors: - m_Groups: - m_Action: Fire - m_Flags: 0 - m_Flags: 0 - reloadAction: - m_Name: Reload - m_Type: 0 - m_ExpectedControlType: - m_Id: b2fa540f-5a3f-4fb7-b40b-672ea6bc4308 - m_Processors: - m_Interactions: - m_SingletonActionBindings: - - m_Name: - m_Id: 58f8c3e7-8210-4dc2-8eae-d4494d6fdbcc - m_Path: /#(R) - m_Interactions: - m_Processors: - m_Groups: - m_Action: Reload - m_Flags: 0 - m_Flags: 0 + _fpCamera: {fileID: 0} + _muzzleFlash: {fileID: 0} + _bulletImpact: {fileID: 0} + _range: 100 + _weaponDamage: 25 --- !u!1 &4135013735270702863 GameObject: m_ObjectHideFlags: 0 @@ -331,7 +302,7 @@ MonoBehaviour: jump: 0 sprint: 0 analogMovement: 0 - cursorLocked: 1 + cursorLocked: 0 cursorInputForLook: 1 --- !u!114 &8616685848737228376 MonoBehaviour: diff --git a/Assets/ImportedAssets/StarterAssets/FirstPersonController/Scripts/FirstPersonController.cs b/Assets/ImportedAssets/StarterAssets/FirstPersonController/Scripts/FirstPersonController.cs index 2091d6c..7010b18 100644 --- a/Assets/ImportedAssets/StarterAssets/FirstPersonController/Scripts/FirstPersonController.cs +++ b/Assets/ImportedAssets/StarterAssets/FirstPersonController/Scripts/FirstPersonController.cs @@ -132,13 +132,13 @@ namespace StarterAssets private void CameraRotation() { // if there is an input - if (_input.look.sqrMagnitude >= _threshold) + if (_input._look.sqrMagnitude >= _threshold) { //Don't multiply mouse input by Time.deltaTime float deltaTimeMultiplier = IsCurrentDeviceMouse ? 1.0f : Time.deltaTime; - _cinemachineTargetPitch += _input.look.y * RotationSpeed * deltaTimeMultiplier; - _rotationVelocity = _input.look.x * RotationSpeed * deltaTimeMultiplier; + _cinemachineTargetPitch += _input._look.y * RotationSpeed * deltaTimeMultiplier; + _rotationVelocity = _input._look.x * RotationSpeed * deltaTimeMultiplier; // clamp our pitch rotation _cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, BottomClamp, TopClamp); @@ -154,19 +154,19 @@ namespace StarterAssets private void Move() { // set target speed based on move speed, sprint speed and if sprint is pressed - float targetSpeed = _input.sprint ? SprintSpeed : MoveSpeed; + float targetSpeed = _input._sprint ? SprintSpeed : MoveSpeed; // a simplistic acceleration and deceleration designed to be easy to remove, replace, or iterate upon // note: Vector2's == operator uses approximation so is not floating point error prone, and is cheaper than magnitude // if there is no input, set the target speed to 0 - if (_input.move == Vector2.zero) targetSpeed = 0.0f; + if (_input._move == Vector2.zero) targetSpeed = 0.0f; // a reference to the players current horizontal velocity float currentHorizontalSpeed = new Vector3(_controller.velocity.x, 0.0f, _controller.velocity.z).magnitude; float speedOffset = 0.1f; - float inputMagnitude = _input.analogMovement ? _input.move.magnitude : 1f; + float inputMagnitude = _input._analogMovement ? _input._move.magnitude : 1f; // accelerate or decelerate to target speed if (currentHorizontalSpeed < targetSpeed - speedOffset || currentHorizontalSpeed > targetSpeed + speedOffset) @@ -184,14 +184,14 @@ namespace StarterAssets } // normalise input direction - Vector3 inputDirection = new Vector3(_input.move.x, 0.0f, _input.move.y).normalized; + Vector3 inputDirection = new Vector3(_input._move.x, 0.0f, _input._move.y).normalized; // note: Vector2's != operator uses approximation so is not floating point error prone, and is cheaper than magnitude // if there is a move input rotate player when the player is moving - if (_input.move != Vector2.zero) + if (_input._move != Vector2.zero) { // move - inputDirection = transform.right * _input.move.x + transform.forward * _input.move.y; + inputDirection = transform.right * _input._move.x + transform.forward * _input._move.y; } // move the player @@ -212,7 +212,7 @@ namespace StarterAssets } // Jump - if (_input.jump && _jumpTimeoutDelta <= 0.0f) + if (_input._jump && _jumpTimeoutDelta <= 0.0f) { // the square root of H * -2 * G = how much velocity needed to reach desired height _verticalVelocity = Mathf.Sqrt(JumpHeight * -2f * Gravity); @@ -236,7 +236,7 @@ namespace StarterAssets } // if we are not grounded, do not jump - _input.jump = false; + _input._jump = false; } // apply gravity over time if under terminal (multiply by delta time twice to linearly speed up over time) diff --git a/Assets/InputSystem/MainPlayerInputs.inputactions b/Assets/InputSystem/MainPlayerInputs.inputactions index 7b02e98..7b8f952 100644 --- a/Assets/InputSystem/MainPlayerInputs.inputactions +++ b/Assets/InputSystem/MainPlayerInputs.inputactions @@ -1,5 +1,5 @@ { - "name": "StarterAssets", + "name": "MainPlayerInputs", "maps": [ { "name": "Player", @@ -58,6 +58,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Menu", + "type": "Button", + "id": "4a5c59b4-fdfb-4dfb-bfc1-1bd6c4a121c5", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -302,6 +311,85 @@ "action": "Reload", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "2d98121e-31da-4f67-8ba8-29af21310b0e", + "path": "/escape", + "interactions": "", + "processors": "", + "groups": "", + "action": "Menu", + "isComposite": false, + "isPartOfComposite": false + } + ] + }, + { + "name": "UI", + "id": "baa56f6d-d4c0-4362-9dfd-8c705d923a27", + "actions": [ + { + "name": "Point", + "type": "Value", + "id": "d69fb5b5-7d08-4dbc-aeff-8ddc6d53b1e6", + "expectedControlType": "Vector2", + "processors": "", + "interactions": "", + "initialStateCheck": true + }, + { + "name": "LeftClick", + "type": "Button", + "id": "4abf5888-18af-42f1-8413-e41292e4263a", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "RightClick", + "type": "Button", + "id": "f3efb458-0934-4a2e-9b28-ca1f96bfb964", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + } + ], + "bindings": [ + { + "name": "", + "id": "07dfed60-4a97-4d73-8f98-6824430eacd7", + "path": "/position", + "interactions": "", + "processors": "", + "groups": "", + "action": "Point", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "242e9c4e-9e5b-4e10-8b8d-f54a91c731d8", + "path": "/leftButton", + "interactions": "", + "processors": "", + "groups": "", + "action": "LeftClick", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "1d18148c-458c-4452-a4bf-f81fec56bcfb", + "path": "/rightButton", + "interactions": "", + "processors": "", + "groups": "", + "action": "RightClick", + "isComposite": false, + "isPartOfComposite": false } ] } diff --git a/Assets/InputSystem/StarterAssetsInputs.cs b/Assets/InputSystem/StarterAssetsInputs.cs index a76dc77..e6a18e9 100644 --- a/Assets/InputSystem/StarterAssetsInputs.cs +++ b/Assets/InputSystem/StarterAssetsInputs.cs @@ -5,76 +5,87 @@ using UnityEngine.InputSystem; namespace StarterAssets { - public class StarterAssetsInputs : MonoBehaviour - { - [Header("Character Input Values")] - public Vector2 move; - public Vector2 look; - public bool jump; - public bool sprint; + public class StarterAssetsInputs : MonoBehaviour + { + [Header("Character Input Values")] + public Vector2 _move; + public Vector2 _look; + public bool _jump; + public bool _sprint; - [Header("Movement Settings")] - public bool analogMovement; + [Header("Movement Settings")] + public bool _analogMovement; - [Header("Mouse Cursor Settings")] - public bool cursorLocked = true; - public bool cursorInputForLook = true; + [Header("Mouse Cursor Settings")] + public bool _cursorLocked = true; + public bool _cursorInputForLook = true; #if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED - public void OnMove(InputValue value) - { - MoveInput(value.Get()); - } + public void OnMove(InputValue value) + { + MoveInput(value.Get()); + } - public void OnLook(InputValue value) - { - if(cursorInputForLook) - { - LookInput(value.Get()); - } - } + public void OnLook(InputValue value) + { + if (_cursorInputForLook) + { + LookInput(value.Get()); + } + } - public void OnJump(InputValue value) - { - JumpInput(value.isPressed); - } + public void OnJump(InputValue value) + { + JumpInput(value.isPressed); + } - public void OnSprint(InputValue value) - { - SprintInput(value.isPressed); - } + public void OnSprint(InputValue value) + { + SprintInput(value.isPressed); + } + + public void OnMenu() + { + _cursorLocked = false; + SetCursorState(); + } #endif + private void OnEnable() + { + _cursorLocked = true; + SetCursorState(); + } - public void MoveInput(Vector2 newMoveDirection) - { - move = newMoveDirection; - } + public void MoveInput(Vector2 newMoveDirection) + { + _move = newMoveDirection; + } - public void LookInput(Vector2 newLookDirection) - { - look = newLookDirection; - } + public void LookInput(Vector2 newLookDirection) + { + _look = newLookDirection; + } - public void JumpInput(bool newJumpState) - { - jump = newJumpState; - } + public void JumpInput(bool newJumpState) + { + _jump = newJumpState; + } - public void SprintInput(bool newSprintState) - { - sprint = newSprintState; - } - - private void OnApplicationFocus(bool hasFocus) - { - SetCursorState(cursorLocked); - } + public void SprintInput(bool newSprintState) + { + _sprint = newSprintState; + } - private void SetCursorState(bool newState) - { - Cursor.lockState = newState ? CursorLockMode.Locked : CursorLockMode.None; - } - } - + private void OnApplicationFocus(bool hasFocus) + { + _cursorLocked = true; + SetCursorState(); + } + + private void SetCursorState() + { + Cursor.lockState = _cursorLocked ? CursorLockMode.Locked : CursorLockMode.None; + } + } } \ No newline at end of file diff --git a/Assets/Weapons/Revolver.prefab b/Assets/Weapons/Revolver.prefab index ed7f8a5..ac073df 100644 --- a/Assets/Weapons/Revolver.prefab +++ b/Assets/Weapons/Revolver.prefab @@ -48,8 +48,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 01ef216392c8f33409f2efcd91f4e510, type: 3} m_Name: m_EditorClassIdentifier: - _FpCamera: {fileID: 0} - _MuzzleFlash: {fileID: 0} + _fpCamera: {fileID: 0} + _muzzleFlash: {fileID: 6070271853189258210} + _bulletImpact: {fileID: 252487699782519274, guid: 82851982cb47c134a8403ffcb052b9d2, type: 3} _range: 100 _weaponDamage: 25 --- !u!1 &160878 diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 3b61681..5b89037 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -4,6 +4,9 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 - m_Scenes: [] + m_Scenes: + - enabled: 1 + path: Assets/Scenes/Sandbox.unity + guid: 9fc0d4010bbf28b4594072e72b8655ab m_configObjects: com.unity.input.settings: {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7, type: 2}