diff --git a/RunningLateGame/Assets/Scenes/Playgrounds/Playground.unity b/RunningLateGame/Assets/Scenes/Playgrounds/Playground.unity index 771d599..ad855be 100644 --- a/RunningLateGame/Assets/Scenes/Playgrounds/Playground.unity +++ b/RunningLateGame/Assets/Scenes/Playgrounds/Playground.unity @@ -264,7 +264,11 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 974238578668270704, guid: c708a3b79cd542b42bbfedb17e213bc1, + type: 3} + insertIndex: -1 + addedObject: {fileID: 491771526} m_SourcePrefab: {fileID: 100100000, guid: c708a3b79cd542b42bbfedb17e213bc1, type: 3} --- !u!1 &13596640 GameObject: @@ -7346,6 +7350,29 @@ Mesh: offset: 0 size: 0 path: +--- !u!1 &491771518 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 974238578668270704, guid: c708a3b79cd542b42bbfedb17e213bc1, + type: 3} + m_PrefabInstance: {fileID: 1120089} + m_PrefabAsset: {fileID: 0} +--- !u!114 &491771526 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 491771518} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4995ad0b66292c144ab3819605824571, type: 3} + m_Name: + m_EditorClassIdentifier: + playerPosition: {fileID: 1013448445} + interactableDistance: 2 + raycastLayers: + serializedVersion: 2 + m_Bits: 439 --- !u!43 &554144876 Mesh: m_ObjectHideFlags: 0 @@ -8474,7 +8501,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: associatedState: 2 - mixer: {fileID: 24100000, guid: 7cbb70bac0ada294e87675a4a804cde7, type: 2} + mixer: {fileID: 0} --- !u!43 &852189891 Mesh: m_ObjectHideFlags: 0 @@ -9137,6 +9164,12 @@ Mesh: offset: 0 size: 0 path: +--- !u!4 &1013448445 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 5542111180780342647, guid: c708a3b79cd542b42bbfedb17e213bc1, + type: 3} + m_PrefabInstance: {fileID: 1120089} + m_PrefabAsset: {fileID: 0} --- !u!1 &1060921175 GameObject: m_ObjectHideFlags: 0 @@ -12925,135 +12958,6 @@ MonoBehaviour: m_SelectedFaces: m_SelectedEdges: [] m_SelectedVertices: ---- !u!1 &1332885280 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1332885282} - - component: {fileID: 1332885281} - m_Layer: 0 - m_Name: music - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!82 &1332885281 -AudioSource: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1332885280} - m_Enabled: 1 - serializedVersion: 4 - OutputAudioMixerGroup: {fileID: 164311610216181747, guid: 7cbb70bac0ada294e87675a4a804cde7, - type: 2} - m_audioClip: {fileID: 8300000, guid: 5e07e339ddf1eea44b3c4db9a02dd75c, type: 3} - m_PlayOnAwake: 1 - m_Volume: 1 - m_Pitch: 1 - Loop: 1 - Mute: 0 - Spatialize: 0 - SpatializePostEffects: 0 - Priority: 128 - DopplerLevel: 1 - MinDistance: 1 - MaxDistance: 500 - Pan2D: 0 - rolloffMode: 0 - BypassEffects: 0 - BypassListenerEffects: 0 - BypassReverbZones: 0 - rolloffCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - panLevelCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - spreadCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - reverbZoneMixCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 ---- !u!4 &1332885282 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1332885280} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 483.05478, y: 0.9047287, z: 496.26224} - 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!43 &1466442468 Mesh: m_ObjectHideFlags: 0 @@ -26462,13 +26366,13 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 1226619923} + - {fileID: 618797800} - {fileID: 1794617895} - {fileID: 785883831} - {fileID: 1625449502} - {fileID: 395649655} - {fileID: 1826378110} - - {fileID: 618797800} - - {fileID: 1226619923} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1805235905 @@ -27246,4 +27150,3 @@ SceneRoots: - {fileID: 1060921176} - {fileID: 596429548} - {fileID: 897146492} - - {fileID: 1332885282} diff --git a/RunningLateGame/Assets/Scripts/AerialFaithDeathTrigger.cs b/RunningLateGame/Assets/Scripts/AerialFaithDeathTrigger.cs index 8e7a605..b93cd33 100644 --- a/RunningLateGame/Assets/Scripts/AerialFaithDeathTrigger.cs +++ b/RunningLateGame/Assets/Scripts/AerialFaithDeathTrigger.cs @@ -58,6 +58,7 @@ private void OnTriggerEnter(Collider other) linkedLeapTrigger1.isPlayerInAir = false; if (linkedLeapTrigger2 != null) linkedLeapTrigger2.isPlayerInAir = false; if (linkedLeapTrigger3 != null) linkedLeapTrigger3.isPlayerInAir = false; - // TODO: kill player + + GameManager.Instance.SetDisplayState(GameManager.DisplayState.OverlayFailedOverTimeMenu); } } \ No newline at end of file diff --git a/RunningLateGame/Assets/Scripts/GameManager.cs b/RunningLateGame/Assets/Scripts/GameManager.cs index 570c635..a1d89ae 100644 --- a/RunningLateGame/Assets/Scripts/GameManager.cs +++ b/RunningLateGame/Assets/Scripts/GameManager.cs @@ -7,6 +7,7 @@ using System; using UnityEngine; using UnityEngine.InputSystem; +using UnityEngine.SceneManagement; using UnityEngine.UIElements; using Cursor = UnityEngine.Cursor; @@ -44,6 +45,16 @@ public enum DisplayState /// [SerializeField] private GameObject guiHudObject; + /// + /// float to keep track of the elapsed play/run/speeder time + /// + private float _elapsedRunTime; + + /// + /// checked when the scene is loaded to restart the game and skip the main menu + /// + private bool _restarting; + /// /// the current state of the game /// @@ -98,12 +109,6 @@ private void Awake() // destroy the new instance if it's not the singleton instance Destroy(gameObject); } - - if (guiInteractionPromptObject == null) - throw new NullReferenceException("GameManager: guiInteractionPromptObject not set"); - - if (guiHudObject == null) - throw new NullReferenceException("GameManager: guiHudObject not set"); } /// @@ -112,25 +117,53 @@ private void Awake() // /// generic exception it couldn't verify a safe state when starting the game private void Start() { - // set to the main menu state - SetDisplayState(DisplayState.ScreenMainMenu); - // pause the game - PauseGameHelper(DisplayState.ScreenMainMenu); + if (guiInteractionPromptObject == null) + throw new NullReferenceException("GameManager: guiInteractionPromptObject not set"); + + if (guiHudObject == null) + throw new NullReferenceException("GameManager: guiHudObject not set"); + + // if we're restarting, skip the main menu + if (_restarting) + { + Debug.Log("GameManager.Start: inherited _restarting, honouring it rn"); + NewGame(); + } + else + { + Debug.Log("GameManager.Start: setting to main menu and pausing"); + SetDisplayState(DisplayState.ScreenMainMenu); + PauseGameHelper(DisplayState.ScreenMainMenu); + } } /// /// game run speed run stopwatch logic /// - // TODO: implement this (speed-run stopwatch) private void Update() { + if (Paused) return; + + _elapsedRunTime += Time.deltaTime; + var minutes = _elapsedRunTime / 60; + var seconds = _elapsedRunTime % 60; + var milliseconds = _elapsedRunTime * 1000 % 1000; + _uiLabelStopwatch.text = $"{minutes:00}:{seconds:00}.{milliseconds:000}"; + } + + /// + /// called when the game object is enabled + /// + private void OnEnable() + { + InitialiseInterfaceElements(); } /// /// initialise ui elements used by the game[ manager] /// /// > - private void OnEnable() + private void InitialiseInterfaceElements() { _ui = guiInteractionPromptObject.GetComponent()?.rootVisualElement; _uiLabelInteractionPrompt = _ui.Q private void HideMenuHelper() { - // get all child menus in the "Menus" parent object - foreach (var menu in GameObject.FindGameObjectsWithTag("Interfaces")) - foreach (Transform menuChild in menu.transform) + // get all children in the "Menus" parent object + foreach (var child in GameObject.FindGameObjectsWithTag("Interfaces")) + foreach (Transform menuChild in child.transform) { // skip if it is 'GameInterface' object if (menuChild.gameObject.CompareTag("GameInterface")) continue; @@ -160,6 +193,24 @@ private void HideMenuHelper() } } + /// + /// helper function to hide any game interfaces that are currently showing + /// + private void SetInterfaceActive(bool active) + { + // foreach (var inter in GameObject.FindGameObjectsWithTag("GameInterface")) + foreach (var child in GameObject.FindGameObjectsWithTag("Interfaces")) + foreach (Transform inter in child.transform) + { + if (!inter.gameObject.CompareTag("GameInterface")) continue; + Debug.Log($"GameManager.SetInterfaceActive: setting interface '{inter}' {active}"); + inter.gameObject.SetActive(active); + } + + if (active) + InitialiseInterfaceElements(); + } + /// /// helper function for SetDisplayState() to pause the game, /// called before the incoming game state is set @@ -182,12 +233,14 @@ private void PauseGameHelper(DisplayState incomingState) Debug.Log("GameManager.PauseGameHelper: freeing cursor for main menu"); Cursor.lockState = CursorLockMode.None; Cursor.visible = true; + + // only hide interfaces if we're transitioning to the main menu + SetInterfaceActive(false); } // freeze player input/control if we're not transitioning to a game state if (incomingState != DisplayState.Game) { - Debug.Log(GameObject.FindGameObjectWithTag("Player")); var playerInput = GameObject.Find("PlayerArmature")?.GetComponent(); if (playerInput != null) { @@ -255,6 +308,9 @@ private void ResumeGameHelper(DisplayState incomingState) // hide any menu that is currently showing HideMenuHelper(); + // show game interfaces + SetInterfaceActive(true); + // free the character controller var playerInput = GameObject.Find("PlayerArmature")?.GetComponent(); if (playerInput == null) return; @@ -369,8 +425,17 @@ public void NewGame() /// public void RestartRun() { - // TODO: implement this - throw new NotImplementedException(); + _restarting = true; + SceneManager.LoadScene(SceneManager.GetActiveScene().name); + } + + /// + /// function to restart the game + /// + public void RestartGame() + { + SceneManager.LoadScene(SceneManager.GetActiveScene().name); + Destroy(this); } /// diff --git a/RunningLateGame/Assets/Scripts/LiftController.cs b/RunningLateGame/Assets/Scripts/LiftController.cs index 4df95b6..78d7a32 100644 --- a/RunningLateGame/Assets/Scripts/LiftController.cs +++ b/RunningLateGame/Assets/Scripts/LiftController.cs @@ -21,26 +21,32 @@ public class LiftController : MonoBehaviour /// the time it takes for the lift to move from one floor to another /// public float duration; + /// /// a bool to check if the lift is moving /// [HideInInspector] public bool moving; + /// /// the current time of the lift moving for lerps /// private float _currentTime; + /// - /// the door of the lift + /// the door of the lift /// private Door _liftDoor; + /// /// the start position of the lift /// private Vector3 _start; + /// /// the target position of the lift /// private Vector3 _target; + /// /// initialisation function /// @@ -49,6 +55,7 @@ private void Start() _liftDoor = transform.parent.GetComponentInChildren(); DoorCloser(); } + /// /// to check if the door is open and call a function to close it /// @@ -59,15 +66,17 @@ public void DoorCloser() Invoke(nameof(CloseDoor), 2f); Invoke(nameof(DoorCloser), 2f); } + /// - /// to close the door + /// to close the door /// public void CloseDoor() { _liftDoor.Interact(); } + /// - /// to move the lift + /// to move the lift /// public IEnumerator Move(int floorsMoved) { diff --git a/RunningLateGame/Assets/Scripts/OverlayPauseMenu.cs b/RunningLateGame/Assets/Scripts/OverlayPauseMenu.cs index b199690..91fc9b5 100644 --- a/RunningLateGame/Assets/Scripts/OverlayPauseMenu.cs +++ b/RunningLateGame/Assets/Scripts/OverlayPauseMenu.cs @@ -17,10 +17,10 @@ public class OverlayPauseMenu : CommonMenu /// private Button _buttonResume; - /// - /// button to retry the run - /// - private Button _buttonRetry; + // /// + // /// button to retry the run + // /// + // private Button _buttonRetry; /// /// button to return to the main menu @@ -42,10 +42,10 @@ public override void OnEnable() _buttonResume.clicked += PlayClick; _buttonResume.clicked += OptionResumeGame; - // get the retry button from the ui root and subscribe appropriate functions - _buttonRetry = UI.Q private GameManager _game; + /// + /// the raycast hit information + /// + private RaycastHit _hit; + /// /// whether the player is looking at an interactable object /// private bool _raycast; - /// - /// the raycast hit information - /// - public RaycastHit Hit; - /// /// initialisation function /// @@ -62,7 +62,7 @@ private void Update() _raycast = Physics.Raycast( playerPosition.position, playerPosition.TransformDirection(Vector3.forward), - out Hit, + out _hit, interactableDistance, raycastLayers ); @@ -75,7 +75,7 @@ private void Update() if (!_raycast) return; // show an interaction prompt if we're looking at an interactable object - var prompt = Hit.collider.GetComponent()?.interactionPrompt; + var prompt = _hit.collider.GetComponent()?.interactionPrompt; if (prompt != "") Debug.Log(prompt); } @@ -85,7 +85,7 @@ private void Update() private void OnAction() { if (!_raycast) return; - Hit.collider.GetComponent()?.Interact(); + _hit.collider.GetComponent()?.Interact(); // _currentInteractable?.Interact(); } diff --git a/RunningLateGame/Assets/Scripts/PlaygroundDonut.cs b/RunningLateGame/Assets/Scripts/PlaygroundDonut.cs index 7bca156..c39c859 100644 --- a/RunningLateGame/Assets/Scripts/PlaygroundDonut.cs +++ b/RunningLateGame/Assets/Scripts/PlaygroundDonut.cs @@ -4,7 +4,6 @@ * description: interaction prompt demo with a probuilder donut */ -using System; using UnityEngine; /// diff --git a/RunningLateGame/Assets/Scripts/RunCompletionTrigger.cs b/RunningLateGame/Assets/Scripts/RunCompletionTrigger.cs index 7d6cdc9..1ed5f87 100644 --- a/RunningLateGame/Assets/Scripts/RunCompletionTrigger.cs +++ b/RunningLateGame/Assets/Scripts/RunCompletionTrigger.cs @@ -4,7 +4,6 @@ * description: game run completion trigger collision */ -using System; using UnityEngine; /// @@ -12,9 +11,8 @@ /// public class RunCompletionTrigger : MonoBehaviour { - private void OnTriggerEnter(Collider other) - { + { GameManager.Instance.SetDisplayState(GameManager.DisplayState.OverlayCompleteUnderTimeMenu); } } \ No newline at end of file diff --git a/RunningLateGame/Assets/Scripts/RunFailureTrigger.cs b/RunningLateGame/Assets/Scripts/RunFailureTrigger.cs index 3aef5ff..e939206 100644 --- a/RunningLateGame/Assets/Scripts/RunFailureTrigger.cs +++ b/RunningLateGame/Assets/Scripts/RunFailureTrigger.cs @@ -4,7 +4,6 @@ * description: game run failure trigger collision */ -using System; using UnityEngine; /// diff --git a/RunningLateGame/Assets/Scripts/ScreenOptionsMenu.cs b/RunningLateGame/Assets/Scripts/ScreenOptionsMenu.cs index 16e2109..441fa1e 100644 --- a/RunningLateGame/Assets/Scripts/ScreenOptionsMenu.cs +++ b/RunningLateGame/Assets/Scripts/ScreenOptionsMenu.cs @@ -7,7 +7,6 @@ using Unity.Mathematics; using UnityEngine; using UnityEngine.Audio; -using UnityEngine.Serialization; using UnityEngine.UIElements; /// @@ -20,22 +19,26 @@ public class ScreenOptionsMenu : CommonMenu /// /// button to return to the main menu /// - public Button ButtonReturn; + private Button _buttonReturn; /// /// slider for master (music + sfx) volume /// - public Slider SliderAudioMaster; + private Slider _sliderAudioMaster; /// /// slider for music volume /// - public Slider SliderAudioMusic; + private Slider _sliderAudioMusic; /// /// slider for sfx volume /// - public Slider SliderAudioSfx; + private Slider _sliderAudioSfx; + + public void Start() + { + } /// /// function to associate a display state with the menu, @@ -48,35 +51,24 @@ public override void OnEnable() base.OnEnable(); // get the start button from the ui root and subscribe appropriate functions - ButtonReturn = UI.Q