style: change all name variables to code style convention

This commit is contained in:
Константин Адер 2024-12-10 03:28:50 +03:00
parent b0eccf53b5
commit ebf5ef05e5
8 changed files with 146 additions and 148 deletions

View File

@ -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
}

View File

@ -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

View File

@ -4,5 +4,5 @@ using UnityEngine;
public class PlayerSettings : NetworkBehaviour
{
public NetworkVariable<FixedString64Bytes> playerNickname;
public NetworkVariable<FixedString64Bytes> PlayerNickname;
}

View File

@ -7,35 +7,35 @@ using UnityEngine.InputSystem;
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<CharacterController>();
playerInput = GetComponent<PlayerInput>();
audioListener = GetComponentInChildren<AudioListener>();
_characterController = GetComponent<CharacterController>();
_playerInput = GetComponent<PlayerInput>();
_audioListener = GetComponentInChildren<AudioListener>();
}
// PlayerInput Events
@ -65,26 +65,30 @@ public class RobotController : NetworkBehaviour
}
}
}
public void OnMove(InputAction.CallbackContext context)
{
moveInput = context.ReadValue<Vector2>();
_moveInput = context.ReadValue<Vector2>();
}
public void OnLook(InputAction.CallbackContext context)
{
lookInput = context.ReadValue<Vector2>();
_lookInput = context.ReadValue<Vector2>();
}
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]

View File

@ -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<int> healthPoints = new NetworkVariable<int>();
public int HealthPoints { get { return healthPoints.Value; } set { healthPoints.Value = value; } }
public NetworkVariable<int> HealthPoints { get => _healthPoints; set => _healthPoints = value; }
private NetworkVariable<int> _healthPoints = new NetworkVariable<int>();
private NetworkVariable<int> armorPoints = new NetworkVariable<int>();
public int ArmorPoints { get { return armorPoints.Value; } set { armorPoints.Value = value; } }
public NetworkVariable<int> ArmorPoints { get => _armorPoints; set => _armorPoints = value; }
private NetworkVariable<int> _armorPoints = new NetworkVariable<int>();
private NetworkVariable<int> ammoPoints = new NetworkVariable<int>();
public int AmmoPoints { get { return ammoPoints.Value; } set { ammoPoints.Value = value; } }
public NetworkVariable<int> AmmoPoints { get => _ammoPoints; set => _ammoPoints = value; }
private NetworkVariable<int> _ammoPoints = new NetworkVariable<int>();
[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;
public int InitialArmor { get => _initialArmor; set => _initialArmor = value; }
[SerializeField] private int _initialArmor = 100;
[SerializeField] private int initialArmor = 100;
public int InitialArmor { get => initialArmor; set => initialArmor = value; }
// Gameplay - Scene Awake & Start
private void Awake()
{
characterController = GetComponent<CharacterController>();
playerInput = GetComponent<PlayerInput>();
audioListener = GetComponentInChildren<AudioListener>();
_characterController = GetComponent<CharacterController>();
_playerInput = GetComponent<PlayerInput>();
_audioListener = GetComponentInChildren<AudioListener>();
}
// 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}");
}
}

View File

@ -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<int> m_Damage = new NetworkVariable<int>();
[SerializeField] protected int damage = 10;
public NetworkVariable<float> Damage { get => _damage; set => _damage = value; }
private NetworkVariable<float> _damage = new NetworkVariable<float>();
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);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}