game: polish scripts

This commit is contained in:
Mark Joshwel 2024-07-04 04:50:59 +08:00
parent 73d46c302b
commit c003ed24d9
6 changed files with 32 additions and 25 deletions

View file

@ -17,31 +17,35 @@ public class AudioManager : MonoBehaviour
/// </summary>
public static AudioManager Instance;
// declare separate audio sources for music and sfx
// so we can control their volumes separately
[Header("Audio Sources")]
/// <summary>
/// music audio source
/// </summary>
[SerializeField] private AudioSource musicSource;
// music audio source
[SerializeField]
private AudioSource musicSource;
// music source default volume
/// <summary>
/// music source default volume
/// </summary>
[SerializeField] private float musicSourceDefaultVolume = 0.6f;
// sfx audio source
/// <summary>
/// sound effects (sfx) audio source
/// </summary>
[SerializeField] private AudioSource sfxSource;
// sfx source default volume
/// <summary>
/// sound effects (sfx) source default volume
/// </summary>
[SerializeField] private float sfxSourceDefaultVolume = 0.6f;
// declare audio clips for music and sfx
[Header("Audio Clips")]
/// <summary>
/// audio clip for menu button click
/// </summary>
[SerializeField] public AudioClip menuButtonClick;
// audio clip for menu button clicks
public AudioClip menuButtonClick;
// audio clip for menu button hover
public AudioClip menuButtonHover;
/// <summary>
/// audio clip for menu button hover
/// </summary>
[SerializeField] public AudioClip menuButtonHover;
/// <summary>
/// function to set don't destroy on load and check for multiple instances

View file

@ -1,4 +1,4 @@
/*
/*
* author: mark joshwel
* date: 29/5/2024
* description: common menu script for hover and click sound effects on ui toolkit buttons

View file

@ -22,6 +22,7 @@ public class CreditsMenu : CommonMenu
/// </summary>
public override void OnEnable()
{
// set the associated state and call the base OnEnable
associatedState = GameManager.DisplayState.ScreenCreditsMenu;
base.OnEnable();

View file

@ -80,11 +80,11 @@ private void Start()
/// </summary>
private void HideMenuHelper()
{
// get parent object tagged "Menus"
// get all child menus in the "Menus" parent object
foreach (var menu in GameObject.FindGameObjectsWithTag("Menus"))
// hide each menu under the parent object\
foreach (Transform menuChild in menu.transform)
{
// disable the menu
Debug.Log($"GameManager: HideMenuHelper - hiding menu '{menuChild}'");
menuChild.gameObject.SetActive(false);
}
@ -118,23 +118,23 @@ private void PauseGameHelper(DisplayState incomingState)
// hide any menu that is currently showing
HideMenuHelper();
// show the menu based on the incoming state
// 1. get all menus via the parent object tagged "Menus"
// get all child menus in the "Menus" parent object
foreach (var menuParent in GameObject.FindGameObjectsWithTag("Menus"))
// 2. get all menus under the parent object
foreach (Transform menu in menuParent.transform)
{
// 2. check its associated state
// show the menu based on the incoming state
// get the associated state of the menu
var associatedState = menu.gameObject.GetComponent<CommonMenu>().associatedState;
Debug.Log(
$"GameManager: PauseGameHelper - found menu '{menu}' "
+ $"with associated state {associatedState} "
+ $"against incoming state {incomingState}");
// 3. if the associated state is the same as the incoming state, then show the menu
// guard clause if the menu isn't what we're looking for
if (associatedState != incomingState)
continue;
// if the associated state is the same as the incoming state, then show the menu
Debug.Log($"GameManager: PauseGameHelper - showing menu for {incomingState}");
menu.gameObject.SetActive(true);
}

View file

@ -38,6 +38,7 @@ public class MainMenu : CommonMenu
/// </summary>
public override void OnEnable()
{
// set the associated state and call the base OnEnable
associatedState = GameManager.DisplayState.ScreenMainMenu;
base.OnEnable();

View file

@ -33,6 +33,7 @@ public class OptionsMenu : CommonMenu
/// </summary>
public override void OnEnable()
{
// set the associated state and call the base OnEnable
associatedState = GameManager.DisplayState.ScreenOptionsMenu;
base.OnEnable();