game(ui,scripts): donut interactive prompt demo
This commit is contained in:
parent
43399cf933
commit
663b9114ba
|
@ -29,7 +29,7 @@ public class CommonMenu : MonoBehaviour
|
|||
/// <summary>
|
||||
/// the visual element object for the menu
|
||||
/// </summary>
|
||||
public VisualElement UI;
|
||||
protected VisualElement UI;
|
||||
|
||||
/// <summary>
|
||||
/// checks if The Menu (2022) was set up correctly
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// singleton class for managing the game state as a single source of truth
|
||||
|
@ -33,21 +35,45 @@ public enum DisplayState
|
|||
public static GameManager Instance;
|
||||
|
||||
/// <summary>
|
||||
/// property to store the heads-up display game object
|
||||
/// game object for the interaction prompt
|
||||
/// </summary>
|
||||
[SerializeField] private GameObject headsUpDisplay;
|
||||
[SerializeField] private GameObject guiInteractionPromptObject;
|
||||
|
||||
/// <summary>
|
||||
/// game object for the heads-up display
|
||||
/// </summary>
|
||||
[SerializeField] private GameObject guiHudObject;
|
||||
|
||||
/// <summary>
|
||||
/// the current state of the game
|
||||
/// </summary>
|
||||
private DisplayState _state = DisplayState.UnassociatedState;
|
||||
|
||||
/// <summary>
|
||||
/// the visual element object for game ui (hud/prompts/tooltips)
|
||||
/// </summary>
|
||||
private VisualElement _ui;
|
||||
|
||||
/// <summary>
|
||||
/// hud ui label for an interaction prompt/tooltip
|
||||
/// </summary>
|
||||
private Label _uiLabelInteractionPrompt;
|
||||
|
||||
/// <summary>
|
||||
/// hud ui label for the player's score out of a thousand
|
||||
/// </summary>
|
||||
private Label _uiLabelScore;
|
||||
|
||||
/// <summary>
|
||||
/// hud ui label for the speed-run stopwatch
|
||||
/// </summary>
|
||||
private Label _uiLabelStopwatch;
|
||||
|
||||
/// <summary>
|
||||
/// property to check if the game is paused based on the current <c>DisplayState</c>
|
||||
/// </summary>
|
||||
public bool Paused => _state != DisplayState.Game;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// function to set doesn't destroy on load and checks for multiple instances
|
||||
/// </summary>
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -90,6 +118,28 @@ private void Start()
|
|||
PauseGameHelper(DisplayState.ScreenMainMenu);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// game run speed run stopwatch logic
|
||||
/// </summary>
|
||||
// TODO: implement this (speed-run stopwatch)
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// initialise ui elements used by the game[ manager]
|
||||
/// </summary>
|
||||
/// >
|
||||
private void OnEnable()
|
||||
{
|
||||
_ui = guiInteractionPromptObject.GetComponent<UIDocument>()?.rootVisualElement;
|
||||
_uiLabelInteractionPrompt = _ui.Q<Label>("InteractionPromptLabel");
|
||||
|
||||
_ui = guiHudObject.GetComponent<UIDocument>()?.rootVisualElement;
|
||||
_uiLabelStopwatch = _ui.Q<Label>("CurrentStopwatchLabel");
|
||||
_uiLabelScore = _ui.Q<Label>("CurrentScoreLabel");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// helper function to hide any menu that is currently showing
|
||||
/// </summary>
|
||||
|
@ -99,6 +149,9 @@ private void HideMenuHelper()
|
|||
foreach (var menu in GameObject.FindGameObjectsWithTag("Interfaces"))
|
||||
foreach (Transform menuChild in menu.transform)
|
||||
{
|
||||
// skip if it is 'GameInterface' object
|
||||
if (menuChild.gameObject.CompareTag("GameInterface")) continue;
|
||||
|
||||
// disable the menu if it's currently active
|
||||
if (!menuChild.gameObject.activeSelf) continue;
|
||||
|
||||
|
@ -122,7 +175,6 @@ private void PauseGameHelper(DisplayState incomingState)
|
|||
Time.timeScale = 0f;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
|
||||
}
|
||||
// or if the incoming state is the main menu, we should probably free the cursor
|
||||
else if (incomingState == DisplayState.ScreenMainMenu)
|
||||
|
@ -309,6 +361,24 @@ public void NewGame()
|
|||
// set to game state
|
||||
SetDisplayState(DisplayState.Game);
|
||||
|
||||
// TODO
|
||||
// TODO: reset game state
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// function to set an interaction prompt/tooltip for the player
|
||||
/// </summary>
|
||||
/// <param name="prompt">string to show to the player</param>
|
||||
public void SetInteractionPrompt(string prompt)
|
||||
{
|
||||
_uiLabelInteractionPrompt.text = prompt;
|
||||
_uiLabelInteractionPrompt.visible = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// function to stop showing an interaction prompt/tooltip for the player
|
||||
/// </summary>
|
||||
public void ClearInteractionPrompt()
|
||||
{
|
||||
_uiLabelInteractionPrompt.visible = false;
|
||||
}
|
||||
}
|
24
RunningLateGame/Assets/Scripts/PlaygroundDonut.cs
Normal file
24
RunningLateGame/Assets/Scripts/PlaygroundDonut.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* author: sai puay
|
||||
* date: 11/8/2024
|
||||
* description: interaction prompt demo with a probuilder donut
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// demo donut interactable class
|
||||
/// </summary>
|
||||
public class PlaygroundDonut : CommonInteractable
|
||||
{
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
GameManager.Instance.SetInteractionPrompt("This is a Donut");
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
GameManager.Instance.ClearInteractionPrompt();
|
||||
}
|
||||
}
|
11
RunningLateGame/Assets/Scripts/PlaygroundDonut.cs.meta
Normal file
11
RunningLateGame/Assets/Scripts/PlaygroundDonut.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2b437e609ff10ac4d91353be0c7ff2a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -2,8 +2,8 @@
|
|||
<Style src="project://database/Assets/UI%20Toolkit/Interfaces/Common.uss?fileID=7433441132597879392&guid=7e22eeee55627cf478c5e125a8197039&type=3#Common" />
|
||||
<ui:VisualElement name="Root" style="flex-grow: 1; justify-content: space-around; align-items: center;">
|
||||
<ui:VisualElement name="VertHolder" style="flex-grow: 1; justify-content: flex-start; align-items: center; align-self: auto; margin-top: 2%;">
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="00:53.47" name="Stopwatch" style="color: rgb(255, 255, 255); -unity-text-align: upper-center; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF"); font-size: 64px; margin-bottom: 0; padding-bottom: 0;" />
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="1,000" name="Score" style="color: rgb(255, 255, 255); -unity-text-align: upper-center; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF"); font-size: 32px; margin-top: 0; padding-top: 0;" />
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="00:53.47" name="CurrentStopwatchLabel" style="color: rgb(255, 255, 255); -unity-text-align: upper-center; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF"); font-size: 64px; margin-bottom: 0; padding-bottom: 0;" />
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="1,000" name="CurrentScoreLabel" style="color: rgb(255, 255, 255); -unity-text-align: upper-center; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF"); font-size: 32px; margin-top: 0; padding-top: 0;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:VisualElement name="Root" style="flex-grow: 1; justify-content: space-around; align-items: center;">
|
||||
<ui:VisualElement name="VertHolder" style="flex-grow: 1; justify-content: center; margin-top: 30%;">
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="Press E to Interact" name="PromptLabel" style="background-color: rgba(0, 0, 0, 0.33); color: rgb(255, 255, 255); -unity-text-align: upper-center; padding-right: 8px; padding-left: 8px; padding-top: 8px; padding-bottom: 8px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Medium.otf?fileID=12800000&guid=9439a6fdc5392c6479cda7dd72a8f3f7&type=3#Fervojo-Medium"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Medium%20SDF.asset?fileID=11400000&guid=45943718062c86e448361bd7f6506932&type=2#Fervojo-Medium SDF"); font-size: 28px;" />
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="Press E to Interact" name="InteractionPromptLabel" style="background-color: rgba(0, 0, 0, 0.33); color: rgb(255, 255, 255); -unity-text-align: upper-center; padding-right: 8px; padding-left: 8px; padding-top: 8px; padding-bottom: 8px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Medium.otf?fileID=12800000&guid=9439a6fdc5392c6479cda7dd72a8f3f7&type=3#Fervojo-Medium"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Medium%20SDF.asset?fileID=11400000&guid=45943718062c86e448361bd7f6506932&type=2#Fervojo-Medium SDF"); font-size: 28px;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
|
|
|
@ -8,6 +8,7 @@ TagManager:
|
|||
- Interactable
|
||||
- AIs
|
||||
- Interfaces
|
||||
- GameInterface
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
|
Reference in a new issue