Added Accessors for the GameManager to get the Score, Cores and Level values
Added a Score to the Game Added an actual blackhole material and shader to the black hole Added a new Main menu and How to Play menu system Added Beam swords to all ships (replacing the light saber things the player had) Added a pause menu Overhauled the UI for the game scene Added List to hold the amount of core energy needed for each level Added the URP package for better rendering (apparently) Added a GameState enum to set which part of the game the player is in Added Magnet powerup to game Changed the way powerups are spawned, enemies now have a loot table Changed cores to core energy which is a percentage needed to pass a level Changed all the Ints to Hidden Value ints to maybe stop cheat engine users finding the important values Changed all level loads to use sceneloadasync Updated all of the materials to use URP shaders Removed Junk Files from external sources Rearranged the folders inside the unity project to try and reduce some name length issues
This commit is contained in:
151
Assets/Scripts/Other/MainMenuEngine.cs
Normal file
151
Assets/Scripts/Other/MainMenuEngine.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MainMenuEngine : MonoBehaviour
|
||||
{
|
||||
public GameObject hudGO;
|
||||
public GameObject joystickGO;
|
||||
public GameObject yolkAGO;
|
||||
public GameObject yolkBGO;
|
||||
public TMPro.TextMeshProUGUI versionText;
|
||||
|
||||
public BackgroundMusicManager currentBGMManager;
|
||||
public MenuAudioManager currentMenuAudioManager;
|
||||
|
||||
public float joystickJiggleSpeed;
|
||||
|
||||
public float flashFrequencyTime;
|
||||
private TimerHelper _flashTimer;
|
||||
|
||||
private MeshRenderer _meshRenderer;
|
||||
private Color _defaultEmissionColor;
|
||||
|
||||
private GameObject _lastControlSelected;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GameManager.Instance.currentGameState = GameState.MAINMENU;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
// If the BGM manager is present, queue up and play the given track index
|
||||
if (currentBGMManager)
|
||||
{
|
||||
currentBGMManager.StartAudioQueueAndPlay(0);
|
||||
}
|
||||
|
||||
_flashTimer = new TimerHelper(flashFrequencyTime);
|
||||
_meshRenderer = hudGO.GetComponent<MeshRenderer>();
|
||||
_defaultEmissionColor = _meshRenderer.materials[0].GetColor("_EmissionColor");
|
||||
|
||||
versionText.text = versionText.text.Replace("{versionNo}", GameManager.Instance.CurrentVersion);
|
||||
}
|
||||
|
||||
public void SetupVolumeOptions()
|
||||
{
|
||||
// Gets the volume settings from the player profile and sets it in the game
|
||||
float currentMasterVol = PlayerPrefs.GetFloat("currentMasterVol");
|
||||
GameObject masterVolSliderGo = GameObject.Find("MainVolSlider");
|
||||
|
||||
float currentMusicVol = PlayerPrefs.GetFloat("currentMusicVol");
|
||||
GameObject musicVolSliderGo = GameObject.Find("MusicVolSlider");
|
||||
|
||||
float currentSFXVol = PlayerPrefs.GetFloat("currentSFXVol");
|
||||
GameObject SFXVolSliderGo = GameObject.Find("SfxVolSlider");
|
||||
|
||||
masterVolSliderGo.GetComponent<Slider>().value = currentMasterVol;
|
||||
musicVolSliderGo.GetComponent<Slider>().value = currentMusicVol;
|
||||
SFXVolSliderGo.GetComponent<Slider>().value = currentSFXVol;
|
||||
}
|
||||
|
||||
public void PlayMenuClick()
|
||||
{
|
||||
if (currentMenuAudioManager)
|
||||
{
|
||||
currentMenuAudioManager.PlayMenuClick();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
// Play the menu click sound if the audio manager is present
|
||||
if (currentMenuAudioManager)
|
||||
{
|
||||
currentMenuAudioManager.PlayMenuClick();
|
||||
}
|
||||
SceneManager.LoadSceneAsync("Rules");
|
||||
}
|
||||
|
||||
public void Quit()
|
||||
{
|
||||
// Play the menu click sound if the audio manager is present
|
||||
if (currentMenuAudioManager)
|
||||
{
|
||||
currentMenuAudioManager.PlayMenuClick();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetMasterVolume(float value)
|
||||
{
|
||||
// Converts the master volume into decibels and stores it in the player profile
|
||||
GameManager.Instance.currentAudioMixer.SetFloat("masterVol", SharedMethods.ConvertToDecibels(value));
|
||||
PlayerPrefs.SetFloat("currentMasterVol", value);
|
||||
}
|
||||
|
||||
public void SetMusicVolume(float value)
|
||||
{
|
||||
// Converts the music volume into decibels and stores it in the player profile
|
||||
GameManager.Instance.currentAudioMixer.SetFloat("musicVol", SharedMethods.ConvertToDecibels(value));
|
||||
PlayerPrefs.SetFloat("currentMusicVol", value);
|
||||
}
|
||||
|
||||
public void SetSFXVolume(float value)
|
||||
{
|
||||
// Converts the sfx volume into decibels and stores it in the player profile
|
||||
GameManager.Instance.currentAudioMixer.SetFloat("sfxVol", SharedMethods.ConvertToDecibels(value));
|
||||
PlayerPrefs.SetFloat("currentSFXVol", value);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (_flashTimer.HasTicked(Time.deltaTime))
|
||||
{
|
||||
float randomNo = Random.Range(0.0f, 1.0f);
|
||||
_meshRenderer.materials[0].SetColor("_EmissionColor", Color.Lerp(Color.black, _defaultEmissionColor, randomNo));
|
||||
}
|
||||
|
||||
float horzLRot = -Input.GetAxis("Horizontal") * joystickJiggleSpeed;
|
||||
float vertLRot = -45.0f + -Input.GetAxis("Vertical") * joystickJiggleSpeed;
|
||||
joystickGO.transform.eulerAngles = new Vector3(vertLRot, 0.0f, horzLRot);
|
||||
|
||||
if (horzLRot != 0)
|
||||
{
|
||||
if (EventSystem.current.currentSelectedGameObject == null)
|
||||
{
|
||||
EventSystem.current.SetSelectedGameObject(_lastControlSelected);
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastControlSelected = EventSystem.current.currentSelectedGameObject;
|
||||
}
|
||||
}
|
||||
|
||||
float horzRRot = -25 + -Input.GetAxis("Mouse X") * joystickJiggleSpeed;
|
||||
float vertRRot = -25 + -Input.GetAxis("Mouse Y") * joystickJiggleSpeed;
|
||||
yolkAGO.transform.eulerAngles = new Vector3(vertRRot, 0.0f, 0.0f);
|
||||
yolkBGO.transform.eulerAngles = new Vector3(horzRRot, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user