From 51148ef5e21835ae16402b6ec64975efe3436301 Mon Sep 17 00:00:00 2001 From: Mark Joshwel Date: Sat, 10 Aug 2024 02:25:46 +0800 Subject: [PATCH] game(scripts): [big] standardise just format and add placeholder xml comments where not placed --- RunningLateGame/Assets/Scripts/AI.cs | 8 +- RunningLateGame/Assets/Scripts/AiCar.cs | 132 ++++++++++++++---- RunningLateGame/Assets/Scripts/AiManager.cs | 52 ++++++- .../Assets/Scripts/CarController.cs | 59 +++++++- .../Assets/Scripts/CommonInteractable.cs | 20 +++ ...ble.cs.meta => CommonInteractable.cs.meta} | 0 RunningLateGame/Assets/Scripts/Door.cs | 47 ++++++- .../Assets/Scripts/Interactable.cs | 11 -- RunningLateGame/Assets/Scripts/Player.cs | 58 ++++++-- 9 files changed, 323 insertions(+), 64 deletions(-) create mode 100644 RunningLateGame/Assets/Scripts/CommonInteractable.cs rename RunningLateGame/Assets/Scripts/{Interactable.cs.meta => CommonInteractable.cs.meta} (100%) delete mode 100644 RunningLateGame/Assets/Scripts/Interactable.cs diff --git a/RunningLateGame/Assets/Scripts/AI.cs b/RunningLateGame/Assets/Scripts/AI.cs index 57c464d..7fc0f8f 100644 --- a/RunningLateGame/Assets/Scripts/AI.cs +++ b/RunningLateGame/Assets/Scripts/AI.cs @@ -1,7 +1,7 @@ /* - * author: lin hengrui ryan + * author: ryan lin * date: 30/7/2024 - * description: AI code for the different AI in the game + * description: 'standard' npc ai behaviour */ using System.Collections; @@ -9,6 +9,9 @@ using UnityEngine.AI; using Random = System.Random; +/// +/// TODO +/// public class AI : MonoBehaviour { /// @@ -16,7 +19,6 @@ public class AI : MonoBehaviour /// private static readonly int AnimatorSpeed = Animator.StringToHash("Speed"); - /// /// set the layers the AI can be on /// diff --git a/RunningLateGame/Assets/Scripts/AiCar.cs b/RunningLateGame/Assets/Scripts/AiCar.cs index fc40a6c..332785a 100644 --- a/RunningLateGame/Assets/Scripts/AiCar.cs +++ b/RunningLateGame/Assets/Scripts/AiCar.cs @@ -1,24 +1,96 @@ -using System.Collections; +/* + * author: ryan lin + * date: 30/7/2024 + * description: vehicular ai behaviour + */ + +using System.Collections; using UnityEngine; +/// +/// TODO +/// public class AICar : MonoBehaviour { + /// + /// TODO + /// [SerializeField] private Transform carPosition; + + /// + /// TODO + /// [SerializeField] private float stoppingDistance; + + /// + /// TODO + /// [SerializeField] private float slowingSpeed; + + /// + /// TODO + /// [SerializeField] private float slowingDistance; + + /// + /// TODO + /// [SerializeField] private float reverseDist; - private string _currentState; - private string _nextState; + + /// + /// TODO + /// private float _accelerationInput; - private CarController _car; + + /// + /// TODO + /// private float _angularDirection; + + /// + /// TODO + /// + private CarController _car; + + /// + /// TODO + /// + private string _currentState; + + /// + /// TODO + /// private Vector3 _dirToMove; + + /// + /// TODO + /// private float _distanceToTarget; + + /// + /// TODO + /// private Transform _driveTarget; + + /// + /// TODO + /// + // FIXME: use an enum or something + private string _nextState; + + /// + /// TODO + /// private float _turnInput; + + /// + /// TODO + /// private float _verticalDirection; + /// + /// TODO + /// private void Awake() { var hasChild = false; @@ -44,16 +116,25 @@ private void Awake() ChangeState(); } + /// + /// TODO + /// private void Update() { _currentState = _nextState; } + /// + /// TODO + /// private void ChangeState() { StartCoroutine(_currentState); } + /// + /// TODO + /// private void Steering() { _angularDirection = Vector3.SignedAngle(carPosition.transform.forward, @@ -64,34 +145,36 @@ private void Steering() _turnInput = 1; } + /// + /// TODO + /// private IEnumerator Stopped() { - while (_currentState == "Stopped") { - _distanceToTarget=Vector3.Distance(carPosition.position, _driveTarget.position); + _distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position); _car.braking = true; _accelerationInput = 0f; _turnInput = 0f; - if (_distanceToTarget>stoppingDistance) - { - _nextState = "Slowed"; - } + if (_distanceToTarget > stoppingDistance) _nextState = "Slowed"; yield return new WaitForSeconds(1); } + ChangeState(); } + /// + /// TODO + /// private IEnumerator Slowed() { _car.braking = false; while (_currentState == "Slowed") { - _verticalDirection = Vector3.Dot(carPosition.transform.forward, (_driveTarget.position - carPosition.transform.position).normalized); _distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position); - if (_verticalDirection>0) + if (_verticalDirection > 0) { if (carPosition.GetComponent().velocity.magnitude > slowingSpeed) _accelerationInput = -1; @@ -105,15 +188,19 @@ private IEnumerator Slowed() else _accelerationInput = 1; } - + Steering(); SlowedCheck(); _car.SetInputs(_accelerationInput, _turnInput); yield return new WaitForEndOfFrame(); } + ChangeState(); } + /// + /// TODO + /// private IEnumerator Driving() { _car.braking = false; @@ -122,30 +209,25 @@ private IEnumerator Driving() _verticalDirection = Vector3.Dot(carPosition.transform.forward, (_driveTarget.position - carPosition.transform.position).normalized); _distanceToTarget = Vector3.Distance(carPosition.position, _driveTarget.position); - _accelerationInput = 1; - - + _accelerationInput = 1; + Steering(); if (_distanceToTarget < slowingDistance) _nextState = "Slowed"; _car.SetInputs(_accelerationInput, _turnInput); yield return new WaitForEndOfFrame(); } + ChangeState(); } + /// + /// TODO + /// private void SlowedCheck() { - if (_distanceToTarget < stoppingDistance) - { - _nextState = "Stopped"; - } + if (_distanceToTarget < stoppingDistance) _nextState = "Stopped"; if (_distanceToTarget > slowingDistance) _nextState = "Driving"; - - - - - } } \ No newline at end of file diff --git a/RunningLateGame/Assets/Scripts/AiManager.cs b/RunningLateGame/Assets/Scripts/AiManager.cs index ccbacde..600e5e0 100644 --- a/RunningLateGame/Assets/Scripts/AiManager.cs +++ b/RunningLateGame/Assets/Scripts/AiManager.cs @@ -1,32 +1,71 @@ +/* + * author: ryan lin + * date: TODO + * description: TODO + */ + using System.Collections; using UnityEngine; -public class AiManager : MonoBehaviour +public class AIManager : MonoBehaviour { + /// + /// TODO + /// public Transform player; + + /// + /// TODO + /// public float cullingDistance; + + /// + /// TODO + /// public GameObject aiPrefab; - private GameObject[] _ais; - private float _distance; + + /// + /// TODO + /// public int maxAI; + + /// + /// TODO + /// + private GameObject[] _ais; + + /// + /// TODO + /// + private float _distance; + + /// + /// TODO + /// private void Start() { StartCoroutine(Manager()); } + /// + /// TODO + /// private void OnDrawGizmos() { Gizmos.color = Color.yellow; Gizmos.DrawWireSphere(player.position, cullingDistance); } - // ReSharper disable Unity.PerformanceAnalysis + /// + /// TODO + /// private IEnumerator Manager() { while (true) { + // FIXME: feels weird _ais = GameObject.FindGameObjectsWithTag("AIs"); - if (_ais.Length < maxAI ) + if (_ais.Length < maxAI) { var instance = Instantiate(aiPrefab, gameObject.transform); } @@ -38,6 +77,7 @@ private IEnumerator Manager() } yield return new WaitForSeconds(1); - } + } + // TODO: iterator never returns? is this intended? } } \ No newline at end of file diff --git a/RunningLateGame/Assets/Scripts/CarController.cs b/RunningLateGame/Assets/Scripts/CarController.cs index 31a6596..d3efbff 100644 --- a/RunningLateGame/Assets/Scripts/CarController.cs +++ b/RunningLateGame/Assets/Scripts/CarController.cs @@ -1,25 +1,65 @@ +/* + * author: ryan lin + * date: TODO + * description: TODO + */ + using System; using System.Collections.Generic; using UnityEngine; +/// +/// TODO +/// public class CarController : MonoBehaviour { + /// + /// TODO + /// public enum Axel { Front, Rear } + /// + /// TODO + /// public float acceleration; + + /// + /// TODO + /// public float turnAngle; + + /// + /// TODO + /// public List wheels; + /// + /// TODO + /// public float brakeForce; + + /// + /// TODO + /// public bool braking; + + /// + /// TODO + /// private float _currentAcceleration; + + /// + /// TODO + /// private float _currentTurn; - + /// + /// TODO + /// private void FixedUpdate() { Move(); @@ -27,18 +67,26 @@ private void FixedUpdate() Brake(); } + /// + /// TODO + /// public void SetInputs(float forwardAmount, float turnAmount) { _currentAcceleration = forwardAmount * acceleration; _currentTurn = turnAmount * turnAngle; } - + /// + /// TODO + /// public void Move() { foreach (var wheel in wheels) wheel.wheelCollider.motorTorque = _currentAcceleration; } + /// + /// TODO + /// public void Brake() { if (braking) @@ -49,6 +97,9 @@ public void Brake() wheel.wheelCollider.brakeTorque = 0f; } + /// + /// TODO + /// public void Steering() { foreach (var wheel in wheels) @@ -56,6 +107,10 @@ public void Steering() wheel.wheelCollider.steerAngle = _currentTurn; } + /// + /// TODO + /// + // NOTE: once again, why is this at the bottom lol [Serializable] public struct Wheel { diff --git a/RunningLateGame/Assets/Scripts/CommonInteractable.cs b/RunningLateGame/Assets/Scripts/CommonInteractable.cs new file mode 100644 index 0000000..326db69 --- /dev/null +++ b/RunningLateGame/Assets/Scripts/CommonInteractable.cs @@ -0,0 +1,20 @@ +/* + * authors: ryan lin, mark joshwel + * date: 10/8/2024 + * description: common interactable behaviour class + */ + +using UnityEngine; + +/// +/// TODO +/// +public class CommonInteractable : MonoBehaviour +{ + /// + /// TODO + /// + public virtual void Interact() + { + } +} \ No newline at end of file diff --git a/RunningLateGame/Assets/Scripts/Interactable.cs.meta b/RunningLateGame/Assets/Scripts/CommonInteractable.cs.meta similarity index 100% rename from RunningLateGame/Assets/Scripts/Interactable.cs.meta rename to RunningLateGame/Assets/Scripts/CommonInteractable.cs.meta diff --git a/RunningLateGame/Assets/Scripts/Door.cs b/RunningLateGame/Assets/Scripts/Door.cs index 808cdce..ec00399 100644 --- a/RunningLateGame/Assets/Scripts/Door.cs +++ b/RunningLateGame/Assets/Scripts/Door.cs @@ -1,29 +1,64 @@ +/* + * author: ryan lin + * date: 8/8/2024 + * description: door interaction and animation + */ + using System; using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Door : Interactable +/// +/// TODO +/// +public class Door : CommonInteractable { + /// + /// TODO + /// public enum DoorType { Sliding, Rotating } + /// + /// TODO + /// public List doors; + /// + /// TODO + /// public float duration; + + /// + /// TODO + /// public AnimationCurve curve; + + /// + /// TODO + /// private bool _isOpen; + + /// + /// TODO + /// private bool _opening; - + /// + /// TODO + /// public override void Interact() { if (!_opening) StartCoroutine(OpenDoor()); } + /// + /// TODO + /// private IEnumerator OpenDoor() { _opening = true; @@ -62,19 +97,19 @@ private IEnumerator OpenDoor() currentDuration = 0; _opening = false; if (_isOpen) - { _isOpen = false; - } else - { _isOpen = true; - } } yield return new WaitForEndOfFrame(); } } + /// + /// TODO + /// + // NOTE: why is this at the bottom lol [Serializable] public struct DoorInput { diff --git a/RunningLateGame/Assets/Scripts/Interactable.cs b/RunningLateGame/Assets/Scripts/Interactable.cs deleted file mode 100644 index dd8cb02..0000000 --- a/RunningLateGame/Assets/Scripts/Interactable.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Interactable : MonoBehaviour -{ - public virtual void Interact() - { - - } -} diff --git a/RunningLateGame/Assets/Scripts/Player.cs b/RunningLateGame/Assets/Scripts/Player.cs index 0cb8044..a6a9220 100644 --- a/RunningLateGame/Assets/Scripts/Player.cs +++ b/RunningLateGame/Assets/Scripts/Player.cs @@ -1,17 +1,54 @@ +/* + * author: ryan lin + * date: 8/8/2024 + * description: TODO + */ + using UnityEngine; - +/// +/// TODO +/// public class Player : MonoBehaviour { - public RaycastHit Hit; + /// + /// TODO + /// [SerializeField] private Transform playerPosition; + + /// + /// TODO + /// [SerializeField] private float seeDistance; - private Interactable _currentInteractable; - private bool _active; - private bool _raycast; + + /// + /// TODO + /// public LayerMask raycastLayers; + + /// + /// TODO + /// + private bool _active; + + /// + /// TODO + /// + private CommonInteractable _currentInteractable; + + /// + /// TODO + /// + private bool _raycast; + + /// + /// TODO + /// + public RaycastHit Hit; - + /// + /// TODO + /// private void Update() { _raycast = Physics.Raycast( @@ -28,15 +65,14 @@ private void Update() ); } + /// + /// TODO + /// private void OnAction() { Debug.Log("test"); if (_raycast) - { if (Hit.transform.CompareTag("Interactable")) - { - Hit.transform.GetComponent().Interact(); - } - } + Hit.transform.GetComponent().Interact(); } } \ No newline at end of file