From 663b9114bac2a90b70706d664918baeeafe83b4a Mon Sep 17 00:00:00 2001 From: sippy-thinks Date: Sun, 11 Aug 2024 15:02:17 +0800 Subject: [PATCH] game(ui,scripts): donut interactive prompt demo --- RunningLateGame/Assets/Scripts/CommonMenu.cs | 2 +- RunningLateGame/Assets/Scripts/GameManager.cs | 88 +++++++++++++++++-- .../Assets/Scripts/PlaygroundDonut.cs | 24 +++++ .../Assets/Scripts/PlaygroundDonut.cs.meta | 11 +++ .../UI Toolkit/Interfaces/OverlayHUD.uxml | 4 +- .../Interfaces/OverlayInteractionPrompt.uxml | 2 +- .../ProjectSettings/TagManager.asset | 1 + 7 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 RunningLateGame/Assets/Scripts/PlaygroundDonut.cs create mode 100644 RunningLateGame/Assets/Scripts/PlaygroundDonut.cs.meta diff --git a/RunningLateGame/Assets/Scripts/CommonMenu.cs b/RunningLateGame/Assets/Scripts/CommonMenu.cs index bdf70e0..aaa62ca 100644 --- a/RunningLateGame/Assets/Scripts/CommonMenu.cs +++ b/RunningLateGame/Assets/Scripts/CommonMenu.cs @@ -29,7 +29,7 @@ public class CommonMenu : MonoBehaviour /// /// the visual element object for the menu /// - public VisualElement UI; + protected VisualElement UI; /// /// checks if The Menu (2022) was set up correctly diff --git a/RunningLateGame/Assets/Scripts/GameManager.cs b/RunningLateGame/Assets/Scripts/GameManager.cs index 53d1eb6..46573e4 100644 --- a/RunningLateGame/Assets/Scripts/GameManager.cs +++ b/RunningLateGame/Assets/Scripts/GameManager.cs @@ -1,5 +1,5 @@ /* - * author: mark joshwel + * author: mark joshwel, sai puay * date: 11/8/2024 * description: game manager singleton for a single source of truth state management */ @@ -7,6 +7,8 @@ using System; using UnityEngine; using UnityEngine.InputSystem; +using UnityEngine.UIElements; +using Cursor = UnityEngine.Cursor; /// /// singleton class for managing the game state as a single source of truth @@ -33,21 +35,45 @@ public enum DisplayState public static GameManager Instance; /// - /// property to store the heads-up display game object + /// game object for the interaction prompt /// - [SerializeField] private GameObject headsUpDisplay; + [SerializeField] private GameObject guiInteractionPromptObject; + + /// + /// game object for the heads-up display + /// + [SerializeField] private GameObject guiHudObject; /// /// the current state of the game /// private DisplayState _state = DisplayState.UnassociatedState; + /// + /// the visual element object for game ui (hud/prompts/tooltips) + /// + private VisualElement _ui; + + /// + /// hud ui label for an interaction prompt/tooltip + /// + private Label _uiLabelInteractionPrompt; + + /// + /// hud ui label for the player's score out of a thousand + /// + private Label _uiLabelScore; + + /// + /// hud ui label for the speed-run stopwatch + /// + private Label _uiLabelStopwatch; + /// /// property to check if the game is paused based on the current DisplayState /// public bool Paused => _state != DisplayState.Game; - /// /// function to set doesn't destroy on load and checks for multiple instances /// @@ -73,9 +99,11 @@ private void Awake() Destroy(gameObject); } - // check if the heads-up display is set - if (headsUpDisplay == null) - throw new NullReferenceException("GameManager: heads-up display is not set in game manager properties"); + if (guiInteractionPromptObject == null) + throw new NullReferenceException("GameManager: guiInteractionPromptObject not set"); + + if (guiHudObject == null) + throw new NullReferenceException("GameManager: guiHudObject not set"); } /// @@ -90,6 +118,28 @@ private void Start() PauseGameHelper(DisplayState.ScreenMainMenu); } + /// + /// game run speed run stopwatch logic + /// + // TODO: implement this (speed-run stopwatch) + private void Update() + { + } + + /// + /// initialise ui elements used by the game[ manager] + /// + /// > + private void OnEnable() + { + _ui = guiInteractionPromptObject.GetComponent()?.rootVisualElement; + _uiLabelInteractionPrompt = _ui.Q