Files
blackhole-escape/Assets/Scripts/Other/RulesMenuEngine.cs
iDunnoDev 62254a0332 Updated Unity Version
Added graphics options and rendering quality level settings
Added new movement patterns to the dumb enemy AI
Added chance for Coward Enemies to drop a random
Added method to correctly reset the game variables on death and win screens
Updated the UI to work on different resolutions without breaking
Moved Sprites into a sprites folder
Fixed issue where score would overflow the int because the multiplier was too high
Fixed issue where new lives gained from the score breakpoints were not being calculated correctly
Fixed issue where clicking off a menu element then trying to control the menu with the controller did not correctly reselect a menu item
Fixed issue where enemies colliding with the outer boundary too much would break the sfx and music (i assume from a buffering issue)
2022-07-23 14:43:52 +01:00

171 lines
4.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.Playables;
public class RulesMenuEngine : MonoBehaviour
{
public GameObject playerCameraGO;
public GameObject playerTrailsGO;
public ParticleSystem starParticles;
public PlayableDirector howToTimeline;
private Vector3 _startPosition;
public GameObject startGameCutscene;
public GameObject startButton;
public GameObject replayButton;
public GameObject skipButton;
public BackgroundMusicManager currentBGMManager;
public MenuAudioManager currentMenuAudioManager;
private bool _cutsceneEnded;
private GameObject _lastControlSelected;
private void Awake()
{
GameManager.Instance.currentGameState = GameState.RULESMENU;
}
// 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);
}
_lastControlSelected = EventSystem.current.firstSelectedGameObject;
_startPosition = playerCameraGO.transform.position;
_cutsceneEnded = false;
}
public void StartGame()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
startGameCutscene.GetComponent<PlayableDirector>().time = 0;
startGameCutscene.SetActive(true);
}
public void ChangeScene()
{
GameManager.Instance.ResetStats();
SceneManager.LoadSceneAsync("Game");
}
public void PlayMenuClick()
{
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
}
public void SlowStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.simulationSpeed = 0.1f;
}
public void NormalStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.simulationSpeed = 1.0f;
CheckIfEndOfTimeline();
}
public void BoostStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.simulationSpeed = 10.0f;
}
public void EscapeStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.maxParticles = 10000;
starsMainPS.simulationSpeed = 100.0f;
starsMainPS.startColor = Color.red;
}
public void DoCutSceneSkip()
{
double fullTime = System.Math.Floor(howToTimeline.time);
int previousSecondMark = (int)fullTime % 10;
howToTimeline.time = (fullTime - previousSecondMark) + 10;
CheckIfEndOfTimeline();
}
public void CheckIfEndOfTimeline()
{
if ((howToTimeline.time + 11) >= howToTimeline.duration)
{
skipButton.SetActive(false);
EventSystem.current.SetSelectedGameObject(startButton);
}
}
public void RestartHowToTimeline()
{
howToTimeline.gameObject.SetActive(true);
skipButton.SetActive(true);
NormalStarRate();
_cutsceneEnded = false;
playerCameraGO.transform.position = _startPosition;
foreach (TrailRenderer currentTrail in playerTrailsGO.GetComponentsInChildren<TrailRenderer>())
{
currentTrail.Clear();
}
howToTimeline.Play();
}
public void EndHowToTimeline()
{
howToTimeline.gameObject.SetActive(false);
skipButton.SetActive(false);
EventSystem.current.SetSelectedGameObject(startButton);
replayButton.SetActive(true);
playerCameraGO.transform.position = _startPosition;
_cutsceneEnded = true;
NormalStarRate();
}
// Update is called once per frame
void Update()
{
if (_cutsceneEnded)
{
//playerTrailsGO.SetActive(true);
playerCameraGO.transform.position = playerCameraGO.transform.forward * 0.05f * Time.deltaTime;
}
float horzIn = Input.GetAxis("Horizontal");
float vertIn = Input.GetAxis("Vertical");
if (horzIn != 0 || vertIn != 0)
{
if (EventSystem.current.currentSelectedGameObject == null)
{
EventSystem.current.SetSelectedGameObject(_lastControlSelected);
}
else
{
_lastControlSelected = EventSystem.current.currentSelectedGameObject;
}
}
}
}