diff --git a/Assets/Scripts/Runtime/Core/Classes/Engineer.cs b/Assets/Scripts/Runtime/Core/Classes/Engineer.cs index 85f11cc..bf09870 100644 --- a/Assets/Scripts/Runtime/Core/Classes/Engineer.cs +++ b/Assets/Scripts/Runtime/Core/Classes/Engineer.cs @@ -2,15 +2,5 @@ using UnityEngine; public class Engineer : RobotController { - // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } + // Engineer Class } diff --git a/Assets/Scripts/Runtime/Core/Classes/PlayerEssence.cs b/Assets/Scripts/Runtime/Core/Classes/PlayerEssence.cs index be9d1c1..8a895fd 100644 --- a/Assets/Scripts/Runtime/Core/Classes/PlayerEssence.cs +++ b/Assets/Scripts/Runtime/Core/Classes/PlayerEssence.cs @@ -1,12 +1,13 @@ using UnityEngine; [RequireComponent( typeof(Camera) )] -public class PlayerEssence : MonoBehaviour { - public float acceleration = 50; // how fast you accelerate - public float accSprintMultiplier = 4; // how much faster you go when "sprinting" - public float lookSensitivity = 1; // mouse look sensitivity - public float dampingCoefficient = 5; // how quickly you break to a halt after you stop your input - public bool focusOnEnable = true; // whether or not to focus and lock cursor immediately on enable +public class PlayerEssence : MonoBehaviour +{ + public float _acceleration = 50; // how fast you accelerate + public float _accSprintMultiplier = 4; // how much faster you go when "sprinting" + public float _lookSensitivity = 1; // mouse look sensitivity + public float _dampingCoefficient = 5; // how quickly you break to a halt after you stop your input + public bool _focusOnEnable = true; // whether or not to focus and lock cursor immediately on enable Vector3 velocity; // current velocity @@ -19,7 +20,7 @@ public class PlayerEssence : MonoBehaviour { } void OnEnable() { - if( focusOnEnable ) Focused = true; + if( _focusOnEnable ) Focused = true; } void OnDisable() => Focused = false; @@ -32,7 +33,7 @@ public class PlayerEssence : MonoBehaviour { Focused = true; // Physics - velocity = Vector3.Lerp( velocity, Vector3.zero, dampingCoefficient * Time.deltaTime ); + velocity = Vector3.Lerp( velocity, Vector3.zero, _dampingCoefficient * Time.deltaTime ); transform.position += velocity * Time.deltaTime; } @@ -41,7 +42,7 @@ public class PlayerEssence : MonoBehaviour { velocity += GetAccelerationVector() * Time.deltaTime; // Rotation - Vector2 mouseDelta = lookSensitivity * new Vector2( Input.GetAxis( "Mouse X" ), -Input.GetAxis( "Mouse Y" ) ); + Vector2 mouseDelta = _lookSensitivity * new Vector2( Input.GetAxis( "Mouse X" ), -Input.GetAxis( "Mouse Y" ) ); Quaternion rotation = transform.rotation; Quaternion horiz = Quaternion.AngleAxis( mouseDelta.x, Vector3.up ); Quaternion vert = Quaternion.AngleAxis( mouseDelta.y, Vector3.right ); @@ -69,8 +70,8 @@ public class PlayerEssence : MonoBehaviour { Vector3 direction = transform.TransformVector( moveInput.normalized ); if( Input.GetKey( KeyCode.LeftShift ) ) - return direction * ( acceleration * accSprintMultiplier ); // "sprinting" - return direction * acceleration; // "walking" + return direction * ( _acceleration * _accSprintMultiplier ); // "sprinting" + return direction * _acceleration; // "walking" } // Fog for Camera - Later diff --git a/Assets/Scripts/Runtime/Core/Classes/PlayerSettings.cs b/Assets/Scripts/Runtime/Core/Classes/PlayerSettings.cs index 5247a51..a8fb792 100644 --- a/Assets/Scripts/Runtime/Core/Classes/PlayerSettings.cs +++ b/Assets/Scripts/Runtime/Core/Classes/PlayerSettings.cs @@ -4,5 +4,5 @@ using UnityEngine; public class PlayerSettings : NetworkBehaviour { - public NetworkVariable playerNickname; + public NetworkVariable PlayerNickname; } diff --git a/Assets/Scripts/Runtime/Core/Classes/RobotController.cs b/Assets/Scripts/Runtime/Core/Classes/RobotController.cs index 08a6ef3..2987b4e 100644 --- a/Assets/Scripts/Runtime/Core/Classes/RobotController.cs +++ b/Assets/Scripts/Runtime/Core/Classes/RobotController.cs @@ -4,38 +4,38 @@ using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.InputSystem; -public class RobotController : NetworkBehaviour +public class RobotController : NetworkBehaviour { [Header("Objects")] - [SerializeField] protected CharacterController characterController; - [SerializeField] protected Camera mainCam; - [SerializeField] protected AudioListener audioListener; - [SerializeField] protected Weapon weapon; + [SerializeField] protected CharacterController _characterController; + [SerializeField] protected Camera _mainCam; + [SerializeField] protected AudioListener _audioListener; + [SerializeField] protected Weapon _weapon; - [SerializeField] protected float upDownRange = 90f; - protected float verticalRotation; + [SerializeField] protected float _upDownRange = 90f; + protected float _verticalRotation; [Header("Movement")] - [SerializeField] protected float walkSpeed = 5.0f; - [SerializeField] protected float sprintMultiplier = 5.0f; - protected float speedMultiplier = 1f; + [SerializeField] protected float _walkSpeed = 5.0f; + [SerializeField] protected float _sprintMultiplier = 5.0f; + protected float _speedMultiplier = 1f; [Header("Gravity / JumpForce")] - [SerializeField] protected float gravity = 9.81f; - [SerializeField] protected float jumpForce = 5f; + [SerializeField] protected float _gravity = 9.81f; + [SerializeField] protected float _jumpForce = 5f; [Header("Look Sensitivity")] - [SerializeField] protected float lookSensitivity = 3.0f; - protected bool cursorIsLocked = true; + [SerializeField] protected float _lookSensitivity = 3.0f; + protected bool _cursorIsLocked = true; [Header("Input Actions")] - [SerializeField] protected PlayerInput playerInput; + [SerializeField] protected PlayerInput _playerInput; - protected Vector2 moveInput; - protected Vector2 lookInput; + protected Vector2 _moveInput; + protected Vector2 _lookInput; - protected bool isMoving; - protected Vector3 currentMovement = Vector3.zero; + protected bool _isMoving; + protected Vector3 _currentMovement = Vector3.zero; [Header("Developer Console")] [SerializeField] protected DeveloperConsoleUI devConsole; @@ -43,9 +43,9 @@ public class RobotController : NetworkBehaviour private void Awake() { - characterController = GetComponent(); - playerInput = GetComponent(); - audioListener = GetComponentInChildren(); + _characterController = GetComponent(); + _playerInput = GetComponent(); + _audioListener = GetComponentInChildren(); } // PlayerInput Events @@ -65,26 +65,30 @@ public class RobotController : NetworkBehaviour } } } + public void OnMove(InputAction.CallbackContext context) { - moveInput = context.ReadValue(); + _moveInput = context.ReadValue(); } + public void OnLook(InputAction.CallbackContext context) { - lookInput = context.ReadValue(); + _lookInput = context.ReadValue(); } + public void OnSprint(InputAction.CallbackContext context) { if (context.performed) { Debug.Log("Running"); - speedMultiplier = sprintMultiplier; + _speedMultiplier = _sprintMultiplier; } else { - speedMultiplier = 1f; + _speedMultiplier = 1f; } } + public void OnJump(InputAction.CallbackContext context) { if (context.performed) @@ -92,6 +96,7 @@ public class RobotController : NetworkBehaviour JumpServerRPC(); } } + public void OnAttack(InputAction.CallbackContext context) { if (context.performed) @@ -99,6 +104,7 @@ public class RobotController : NetworkBehaviour ShootServerRPC(); } } + public void OnAim(InputAction.CallbackContext context) { if (context.performed) @@ -106,6 +112,7 @@ public class RobotController : NetworkBehaviour AimServerRPC(); } } + public void OnCrouch(InputAction.CallbackContext context) { if (context.performed) @@ -113,6 +120,7 @@ public class RobotController : NetworkBehaviour CrouchServerRPC(); } } + public void OnInteract(InputAction.CallbackContext context) { if (context.performed) @@ -126,10 +134,10 @@ public class RobotController : NetworkBehaviour { base.OnNetworkSpawn(); - playerInput.enabled = IsOwner; - characterController.enabled = IsOwner; - mainCam.enabled = IsOwner; - audioListener.enabled = IsOwner; + _playerInput.enabled = IsOwner; + _characterController.enabled = IsOwner; + _mainCam.enabled = IsOwner; + _audioListener.enabled = IsOwner; Debug.Log($"NetworkObject ID: {NetworkObjectId} spawned with OwnerClientId: {OwnerClientId}"); } @@ -138,10 +146,10 @@ public class RobotController : NetworkBehaviour { base.OnNetworkDespawn(); - playerInput.enabled = false; - characterController.enabled = false; - mainCam.enabled = false; - audioListener.enabled = false; + _playerInput.enabled = false; + _characterController.enabled = false; + _mainCam.enabled = false; + _audioListener.enabled = false; Debug.Log($"NetworkObject ID: {NetworkObjectId} despawned"); } @@ -160,42 +168,42 @@ public class RobotController : NetworkBehaviour protected void HandleMovement() { - float verticalSpeed = moveInput.y * walkSpeed * speedMultiplier; - float horizontalSpeed = moveInput.x * walkSpeed * speedMultiplier; + float verticalSpeed = _moveInput.y * _walkSpeed * _speedMultiplier; + float horizontalSpeed = _moveInput.x * _walkSpeed * _speedMultiplier; - Vector3 horizontalMovement = new Vector3 (horizontalSpeed, 0, verticalSpeed); + Vector3 horizontalMovement = new(horizontalSpeed, 0, verticalSpeed); horizontalMovement = transform.rotation * horizontalMovement; handleGravityAndJumping(); - currentMovement.x = horizontalMovement.x; - currentMovement.z = horizontalMovement.z; + _currentMovement.x = horizontalMovement.x; + _currentMovement.z = horizontalMovement.z; - characterController.Move(currentMovement * Time.deltaTime); + _characterController.Move(_currentMovement * Time.deltaTime); - isMoving = moveInput.y != 0 || moveInput.x != 0; + _isMoving = _moveInput.y != 0 || _moveInput.x != 0; } protected void handleGravityAndJumping() { - if (characterController.isGrounded) + if (_characterController.isGrounded) { - currentMovement.y = -0.5f; + _currentMovement.y = -0.5f; } else { - currentMovement.y -= gravity * Time.deltaTime; + _currentMovement.y -= _gravity * Time.deltaTime; } } protected void HandleRotation() { - float mouseXRotation = lookInput.x * lookSensitivity; + float mouseXRotation = _lookInput.x * _lookSensitivity; transform.Rotate(0, mouseXRotation, 0); - verticalRotation -= lookInput.y * lookSensitivity; - verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange); - mainCam.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0); + _verticalRotation -= _lookInput.y * _lookSensitivity; + _verticalRotation = Mathf.Clamp(_verticalRotation, -_upDownRange, _upDownRange); + _mainCam.transform.localRotation = Quaternion.Euler(_verticalRotation, 0, 0); } //controls the locking and unlocking of the mouse @@ -203,27 +211,29 @@ public class RobotController : NetworkBehaviour { if (Input.GetKeyUp(KeyCode.Escape)) { - cursorIsLocked = false; + _cursorIsLocked = false; } else if (Input.GetMouseButtonUp(0)) { - cursorIsLocked = true; + _cursorIsLocked = true; } - if (cursorIsLocked) + if (_cursorIsLocked) { UnlockCursor(); } - else if (!cursorIsLocked) + else if (!_cursorIsLocked) { LockCursor(); } } + private void UnlockCursor() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } + private void LockCursor() { Cursor.lockState = CursorLockMode.None; @@ -231,11 +241,10 @@ public class RobotController : NetworkBehaviour } // Networking Staff - [ServerRpc] protected void JumpServerRPC() { - if (characterController.isGrounded) + if (_characterController.isGrounded) { Debug.Log($"Jump triggered. Owner: {OwnerClientId}"); } @@ -245,7 +254,7 @@ public class RobotController : NetworkBehaviour protected void ShootServerRPC() { Debug.Log($"Shooting triggered. Owner: {OwnerClientId}"); - weapon.Shooting(); + _weapon.Shooting(); } [ServerRpc] diff --git a/Assets/Scripts/Runtime/Core/Classes/Trooper.cs b/Assets/Scripts/Runtime/Core/Classes/Trooper.cs index 2db805b..a4a023a 100644 --- a/Assets/Scripts/Runtime/Core/Classes/Trooper.cs +++ b/Assets/Scripts/Runtime/Core/Classes/Trooper.cs @@ -6,29 +6,30 @@ using UnityEngine.InputSystem; public class Trooper : RobotController { // Dev Debug Staff - [SerializeField] Canvas screenSpaceCanvas; + [SerializeField] private Canvas _screenSpaceCanvas; [Header("Gameplay Variables")] - private NetworkVariable healthPoints = new NetworkVariable(); - public int HealthPoints { get { return healthPoints.Value; } set { healthPoints.Value = value; } } + public NetworkVariable HealthPoints { get => _healthPoints; set => _healthPoints = value; } + private NetworkVariable _healthPoints = new NetworkVariable(); - private NetworkVariable armorPoints = new NetworkVariable(); - public int ArmorPoints { get { return armorPoints.Value; } set { armorPoints.Value = value; } } + public NetworkVariable ArmorPoints { get => _armorPoints; set => _armorPoints = value; } + private NetworkVariable _armorPoints = new NetworkVariable(); - private NetworkVariable ammoPoints = new NetworkVariable(); - public int AmmoPoints { get { return ammoPoints.Value; } set { ammoPoints.Value = value; } } + public NetworkVariable AmmoPoints { get => _ammoPoints; set => _ammoPoints = value; } + private NetworkVariable _ammoPoints = new NetworkVariable(); - [SerializeField] private int initialHP = 100; - public int InitialHP { get => initialHP; set => initialHP = value; } + public int InitialHP { get => _initialHP; set => _initialHP = value; } + [SerializeField] private int _initialHP = 100; - [SerializeField] private int initialArmor = 100; - public int InitialArmor { get => initialArmor; set => initialArmor = value; } + public int InitialArmor { get => _initialArmor; set => _initialArmor = value; } + [SerializeField] private int _initialArmor = 100; + // Gameplay - Scene Awake & Start private void Awake() { - characterController = GetComponent(); - playerInput = GetComponent(); - audioListener = GetComponentInChildren(); + _characterController = GetComponent(); + _playerInput = GetComponent(); + _audioListener = GetComponentInChildren(); } // PlayerInput Events @@ -48,7 +49,7 @@ public class Trooper : RobotController } // Networking Staff - Spawn & Despawn - void OnServerSpawnPlayer() + private void OnServerSpawnPlayer() { // this is done server side, so we have a single source of truth for our spawn point list var spawnPoint = ServerPlayerSpawnPoints.Instance.ConsumeNextSpawnPoint(); @@ -61,28 +62,28 @@ public class Trooper : RobotController OnServerSpawnPlayer(); base.OnNetworkSpawn(); - playerInput.enabled = IsOwner; - characterController.enabled = IsOwner; - mainCam.enabled = IsOwner; - audioListener.enabled = IsOwner; - screenSpaceCanvas.enabled = IsOwner; + _playerInput.enabled = IsOwner; + _characterController.enabled = IsOwner; + _mainCam.enabled = IsOwner; + _audioListener.enabled = IsOwner; + _screenSpaceCanvas.enabled = IsOwner; // Game Variables - healthPoints.Value = InitialHP; + HealthPoints.Value = InitialHP; Debug.Log($"NetworkObject ID: {NetworkObjectId} spawned with OwnerClientId: {OwnerClientId}"); - Debug.Log($"HP of OwnerClientID: {OwnerClientId} is {healthPoints.Value} when spawned."); + Debug.Log($"HP of OwnerClientID: {OwnerClientId} is {HealthPoints.Value} when spawned."); } public override void OnNetworkDespawn() { base.OnNetworkDespawn(); - playerInput.enabled = false; - characterController.enabled = false; - mainCam.enabled = false; - audioListener.enabled = false; - screenSpaceCanvas.enabled = false; + _playerInput.enabled = false; + _characterController.enabled = false; + _mainCam.enabled = false; + _audioListener.enabled = false; + _screenSpaceCanvas.enabled = false; Debug.Log($"NetworkObject ID: {NetworkObjectId} despawned"); } @@ -93,33 +94,33 @@ public class Trooper : RobotController [ServerRpc] private new void JumpServerRPC() { - if (characterController.isGrounded) + if (_characterController.isGrounded) { - Debug.Log("Jumping as Trooper triggered."); + Debug.Log($"Jumping as Trooper triggered. Owner: {OwnerClientId}"); } } [ServerRpc] private new void ShootServerRPC() { - weapon.Shooting(); + _weapon.Shooting(); } [ServerRpc] private new void AimServerRPC() { - Debug.Log("Aim as Trooper triggered."); + Debug.Log($"Aim as Trooper triggered. Owner: {OwnerClientId}"); } [ServerRpc] private new void CrouchServerRPC() { - Debug.Log("Crouch as Trooper triggered."); + Debug.Log($"Crouch as Trooper triggered. Owner: {OwnerClientId}"); } [ServerRpc] private new void InteractServerRPC() { - Debug.Log("Interact as Trooper triggered."); + Debug.Log($"Interact as Trooper triggered. Owner: {OwnerClientId}"); } } diff --git a/Assets/Scripts/Runtime/Core/Classes/Weapon.cs b/Assets/Scripts/Runtime/Core/Classes/Weapon.cs index 05065aa..9098904 100644 --- a/Assets/Scripts/Runtime/Core/Classes/Weapon.cs +++ b/Assets/Scripts/Runtime/Core/Classes/Weapon.cs @@ -3,27 +3,24 @@ using Unity.Netcode; public class Weapon : MonoBehaviour { - // [SerializeField] private float damage = 10f; - [SerializeField] private float range = 100f; - [SerializeField] protected Camera mainCam; - [SerializeField] protected float debugRayDistance = 5f; - [SerializeField] protected float debugRayDuration = 2f; + [SerializeField] protected Camera _mainCam; + [SerializeField] protected float _debugRayDistance = 5f; + [SerializeField] protected float _debugRayDuration = 2f; + [SerializeField] private float _range = 100f; [Header("Gameplay Variables")] - private NetworkVariable m_Damage = new NetworkVariable(); - [SerializeField] protected int damage = 10; - - + public NetworkVariable Damage { get => _damage; set => _damage = value; } + private NetworkVariable _damage = new NetworkVariable(); public void Shooting() { RaycastHit hit; - if (Physics.Raycast(mainCam.transform.position, mainCam.transform.forward, out hit, range)) + if (Physics.Raycast(_mainCam.transform.position, _mainCam.transform.forward, out hit, _range)) { Debug.Log(hit.transform.name); - Vector3 rayDir = mainCam.transform.forward * debugRayDistance; - Debug.DrawRay(mainCam.transform.position, rayDir, Color.yellow, debugRayDuration, false); + Vector3 rayDir = _mainCam.transform.forward * _debugRayDistance; + Debug.DrawRay(_mainCam.transform.position, rayDir, Color.yellow, _debugRayDuration, false); } } diff --git a/Assets/Scripts/Runtime/UI/Armorbar.cs b/Assets/Scripts/Runtime/UI/Armorbar.cs index e014bcb..4f4f57b 100644 --- a/Assets/Scripts/Runtime/UI/Armorbar.cs +++ b/Assets/Scripts/Runtime/UI/Armorbar.cs @@ -3,26 +3,26 @@ using UnityEngine; public class Armorbar : MonoBehaviour { - [SerializeField] private TextMeshProUGUI staticInfo; - [SerializeField] private TextMeshProUGUI dynamicInfo; - [SerializeField] private Trooper trooper; + [SerializeField] private TextMeshProUGUI _staticInfo; + [SerializeField] private TextMeshProUGUI _dynamicInfo; + [SerializeField] private Trooper _trooper; - private int bufferHP; - private int initialInfo; + private int _bufferHP; + private int _initialInfo; - public TextMeshProUGUI DynamicInfo { get => dynamicInfo; set => dynamicInfo = value; } - public TextMeshProUGUI StaticInfo { get => staticInfo; set => staticInfo = value; } - public int BufferHP { get => bufferHP; set => bufferHP = value; } + public TextMeshProUGUI DynamicInfo { get => _dynamicInfo; set => _dynamicInfo = value; } + public TextMeshProUGUI StaticInfo { get => _staticInfo; set => _staticInfo = value; } + public int BufferHP { get => _bufferHP; set => _bufferHP = value; } void Start() { - initialInfo = trooper.InitialArmor; - StaticInfo.text = initialInfo.ToString(); - DynamicInfo.text = initialInfo.ToString(); + _initialInfo = _trooper.InitialArmor; + StaticInfo.text = _initialInfo.ToString(); + DynamicInfo.text = _initialInfo.ToString(); } void DynamicInfoChange(int newValue) { - DynamicInfo.text = bufferHP.ToString(); + DynamicInfo.text = _bufferHP.ToString(); } } diff --git a/Assets/Scripts/Runtime/UI/Healthbar.cs b/Assets/Scripts/Runtime/UI/Healthbar.cs index ee5008d..905c06b 100644 --- a/Assets/Scripts/Runtime/UI/Healthbar.cs +++ b/Assets/Scripts/Runtime/UI/Healthbar.cs @@ -3,26 +3,26 @@ using UnityEngine; public class Healthbar : MonoBehaviour { - [SerializeField] private TextMeshProUGUI staticInfo; - [SerializeField] private TextMeshProUGUI dynamicInfo; - [SerializeField] private Trooper trooper; + [SerializeField] private TextMeshProUGUI _staticInfo; + [SerializeField] private TextMeshProUGUI _dynamicInfo; + [SerializeField] private Trooper _trooper; - private int bufferHP; - private int initialInfo; + private int _bufferHP; + private int _initialInfo; - public TextMeshProUGUI DynamicInfo { get => dynamicInfo; set => dynamicInfo = value; } - public TextMeshProUGUI StaticInfo { get => staticInfo; set => staticInfo = value; } - public int BufferHP { get => bufferHP; set => bufferHP = value; } + public TextMeshProUGUI DynamicInfo { get => _dynamicInfo; set => _dynamicInfo = value; } + public TextMeshProUGUI StaticInfo { get => _staticInfo; set => _staticInfo = value; } + public int BufferHP { get => _bufferHP; set => _bufferHP = value; } void Start() { - initialInfo = trooper.InitialHP; - StaticInfo.text = initialInfo.ToString(); - DynamicInfo.text = initialInfo.ToString(); + _initialInfo = _trooper.InitialHP; + StaticInfo.text = _initialInfo.ToString(); + DynamicInfo.text = _initialInfo.ToString(); } void DynamicInfoChange(int newValue) { - DynamicInfo.text = bufferHP.ToString(); + DynamicInfo.text = _bufferHP.ToString(); } -} \ No newline at end of file +} \ No newline at end of file