game: polish scripts
This commit is contained in:
parent
73d46c302b
commit
c003ed24d9
|
@ -17,31 +17,35 @@ public class AudioManager : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static AudioManager Instance;
|
public static AudioManager Instance;
|
||||||
|
|
||||||
// declare separate audio sources for music and sfx
|
/// <summary>
|
||||||
// so we can control their volumes separately
|
/// music audio source
|
||||||
[Header("Audio Sources")]
|
/// </summary>
|
||||||
|
[SerializeField] private AudioSource musicSource;
|
||||||
|
|
||||||
// music audio source
|
/// <summary>
|
||||||
[SerializeField]
|
/// music source default volume
|
||||||
private AudioSource musicSource;
|
/// </summary>
|
||||||
|
|
||||||
// music source default volume
|
|
||||||
[SerializeField] private float musicSourceDefaultVolume = 0.6f;
|
[SerializeField] private float musicSourceDefaultVolume = 0.6f;
|
||||||
|
|
||||||
// sfx audio source
|
/// <summary>
|
||||||
|
/// sound effects (sfx) audio source
|
||||||
|
/// </summary>
|
||||||
[SerializeField] private AudioSource sfxSource;
|
[SerializeField] private AudioSource sfxSource;
|
||||||
|
|
||||||
// sfx source default volume
|
/// <summary>
|
||||||
|
/// sound effects (sfx) source default volume
|
||||||
|
/// </summary>
|
||||||
[SerializeField] private float sfxSourceDefaultVolume = 0.6f;
|
[SerializeField] private float sfxSourceDefaultVolume = 0.6f;
|
||||||
|
|
||||||
// declare audio clips for music and sfx
|
/// <summary>
|
||||||
[Header("Audio Clips")]
|
/// audio clip for menu button click
|
||||||
|
/// </summary>
|
||||||
|
[SerializeField] public AudioClip menuButtonClick;
|
||||||
|
|
||||||
// audio clip for menu button clicks
|
/// <summary>
|
||||||
public AudioClip menuButtonClick;
|
/// audio clip for menu button hover
|
||||||
|
/// </summary>
|
||||||
// audio clip for menu button hover
|
[SerializeField] public AudioClip menuButtonHover;
|
||||||
public AudioClip menuButtonHover;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// function to set don't destroy on load and check for multiple instances
|
/// function to set don't destroy on load and check for multiple instances
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* author: mark joshwel
|
* author: mark joshwel
|
||||||
* date: 29/5/2024
|
* date: 29/5/2024
|
||||||
* description: common menu script for hover and click sound effects on ui toolkit buttons
|
* description: common menu script for hover and click sound effects on ui toolkit buttons
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class CreditsMenu : CommonMenu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnEnable()
|
public override void OnEnable()
|
||||||
{
|
{
|
||||||
|
// set the associated state and call the base OnEnable
|
||||||
associatedState = GameManager.DisplayState.ScreenCreditsMenu;
|
associatedState = GameManager.DisplayState.ScreenCreditsMenu;
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
|
|
||||||
|
|
|
@ -80,11 +80,11 @@ private void Start()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void HideMenuHelper()
|
private void HideMenuHelper()
|
||||||
{
|
{
|
||||||
// get parent object tagged "Menus"
|
// get all child menus in the "Menus" parent object
|
||||||
foreach (var menu in GameObject.FindGameObjectsWithTag("Menus"))
|
foreach (var menu in GameObject.FindGameObjectsWithTag("Menus"))
|
||||||
// hide each menu under the parent object\
|
|
||||||
foreach (Transform menuChild in menu.transform)
|
foreach (Transform menuChild in menu.transform)
|
||||||
{
|
{
|
||||||
|
// disable the menu
|
||||||
Debug.Log($"GameManager: HideMenuHelper - hiding menu '{menuChild}'");
|
Debug.Log($"GameManager: HideMenuHelper - hiding menu '{menuChild}'");
|
||||||
menuChild.gameObject.SetActive(false);
|
menuChild.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
@ -118,23 +118,23 @@ private void PauseGameHelper(DisplayState incomingState)
|
||||||
// hide any menu that is currently showing
|
// hide any menu that is currently showing
|
||||||
HideMenuHelper();
|
HideMenuHelper();
|
||||||
|
|
||||||
// show the menu based on the incoming state
|
// get all child menus in the "Menus" parent object
|
||||||
// 1. get all menus via the parent object tagged "Menus"
|
|
||||||
foreach (var menuParent in GameObject.FindGameObjectsWithTag("Menus"))
|
foreach (var menuParent in GameObject.FindGameObjectsWithTag("Menus"))
|
||||||
// 2. get all menus under the parent object
|
|
||||||
foreach (Transform menu in menuParent.transform)
|
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;
|
var associatedState = menu.gameObject.GetComponent<CommonMenu>().associatedState;
|
||||||
Debug.Log(
|
Debug.Log(
|
||||||
$"GameManager: PauseGameHelper - found menu '{menu}' "
|
$"GameManager: PauseGameHelper - found menu '{menu}' "
|
||||||
+ $"with associated state {associatedState} "
|
+ $"with associated state {associatedState} "
|
||||||
+ $"against incoming state {incomingState}");
|
+ $"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)
|
if (associatedState != incomingState)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// if the associated state is the same as the incoming state, then show the menu
|
||||||
Debug.Log($"GameManager: PauseGameHelper - showing menu for {incomingState}");
|
Debug.Log($"GameManager: PauseGameHelper - showing menu for {incomingState}");
|
||||||
menu.gameObject.SetActive(true);
|
menu.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class MainMenu : CommonMenu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnEnable()
|
public override void OnEnable()
|
||||||
{
|
{
|
||||||
|
// set the associated state and call the base OnEnable
|
||||||
associatedState = GameManager.DisplayState.ScreenMainMenu;
|
associatedState = GameManager.DisplayState.ScreenMainMenu;
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class OptionsMenu : CommonMenu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnEnable()
|
public override void OnEnable()
|
||||||
{
|
{
|
||||||
|
// set the associated state and call the base OnEnable
|
||||||
associatedState = GameManager.DisplayState.ScreenOptionsMenu;
|
associatedState = GameManager.DisplayState.ScreenOptionsMenu;
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
|
|
||||||
|
|
Reference in a new issue