2022-11-17 00:23:38 +08:00
|
|
|
|
using SHADE;
|
2023-02-03 00:40:22 +08:00
|
|
|
|
using SHADE_Scripting.Audio;
|
2022-11-17 00:23:38 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
public class GameManager : Script
|
|
|
|
|
{
|
2022-11-17 12:54:08 +08:00
|
|
|
|
public enum GameState
|
2023-02-02 22:44:30 +08:00
|
|
|
|
{
|
2022-11-20 16:27:39 +08:00
|
|
|
|
START,
|
2022-11-17 12:54:08 +08:00
|
|
|
|
WIN,
|
2022-11-22 17:28:48 +08:00
|
|
|
|
LOSE
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 16:57:32 +08:00
|
|
|
|
public uint winScene = 92009475;
|
|
|
|
|
public uint loseScene = 91685359;
|
|
|
|
|
|
2022-11-22 17:28:48 +08:00
|
|
|
|
[NonSerialized]
|
|
|
|
|
public GameState currGameState;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
[NonSerialized]
|
2022-11-17 00:23:38 +08:00
|
|
|
|
public int totalItemCount;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
[NonSerialized]
|
2022-11-17 00:23:38 +08:00
|
|
|
|
public int Score;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
[NonSerialized]
|
|
|
|
|
public float timer;
|
|
|
|
|
|
2022-11-23 20:26:53 +08:00
|
|
|
|
public GameObject scoreText;
|
|
|
|
|
public GameObject timeText;
|
|
|
|
|
|
2023-02-02 22:44:30 +08:00
|
|
|
|
//mulitpler info
|
|
|
|
|
public GameObject multiplierText;
|
|
|
|
|
public float maxMultiplierDuration = 5.0f;
|
|
|
|
|
public float currMultiplierDuration { get; set; }
|
|
|
|
|
public int maxMultiplierCombo = 10;
|
|
|
|
|
public bool itemScored {get;set;}
|
|
|
|
|
public int currMultiplierCombo { get; set;}
|
|
|
|
|
public float multiplierFont = 60.0f;
|
|
|
|
|
private Vector3 fontScalar;
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
public static GameManager Instance { get; private set; }
|
2022-11-23 20:26:53 +08:00
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
2023-01-31 18:13:34 +08:00
|
|
|
|
if (Instance != null && Instance != this)
|
|
|
|
|
RemoveScript<GameManager>();
|
|
|
|
|
else
|
|
|
|
|
Instance = this;
|
|
|
|
|
|
2023-02-03 00:40:22 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
|
|
|
|
|
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
|
2023-02-04 00:23:05 +08:00
|
|
|
|
//AudioHandler.audioClipHandlers["BGMAdaptive"].SetParameter("Detected", 0.0f);
|
|
|
|
|
Audio.SetParameter("Detected", 0.0f);
|
2023-02-03 00:40:22 +08:00
|
|
|
|
//Audio.PlayBGMOnce2D("event:/Music/player_undetected");
|
2023-02-04 00:23:05 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["KitchenAmbience"] = Audio.CreateAudioClip("event:/Ambience/roomtone_kitchen");
|
|
|
|
|
AudioHandler.audioClipHandlers["KitchenAmbience"].Play();
|
|
|
|
|
//Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen");
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXHumming"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_humming");
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXHumming"].SetVolume(0.15f);
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXHumming"].Play();
|
2022-11-17 00:23:38 +08:00
|
|
|
|
totalItemCount = 0;
|
|
|
|
|
Score = 0;
|
2022-11-22 17:28:48 +08:00
|
|
|
|
currGameState = GameState.START;
|
2023-02-02 22:44:30 +08:00
|
|
|
|
itemScored = false;
|
|
|
|
|
currMultiplierCombo = 1;
|
|
|
|
|
currMultiplierDuration = 0;
|
|
|
|
|
fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration);
|
2023-02-04 00:23:05 +08:00
|
|
|
|
|
|
|
|
|
AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win");
|
|
|
|
|
AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void update()
|
2022-11-17 12:54:08 +08:00
|
|
|
|
{
|
2022-11-25 00:54:45 +08:00
|
|
|
|
Cheats();
|
2022-11-23 20:26:53 +08:00
|
|
|
|
if (currGameState == GameState.START)
|
2022-11-23 16:57:32 +08:00
|
|
|
|
{
|
2022-11-17 12:54:08 +08:00
|
|
|
|
timer -= Time.DeltaTimeF;
|
2022-11-23 20:26:53 +08:00
|
|
|
|
if(scoreText)
|
|
|
|
|
scoreText.GetComponent<TextRenderable>().Text = $"Score: {Score}";
|
|
|
|
|
if(timeText)
|
|
|
|
|
timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0.00")}";
|
|
|
|
|
|
2023-02-02 22:44:30 +08:00
|
|
|
|
if (itemScored)
|
|
|
|
|
{
|
|
|
|
|
multiplierText.GetComponent<TextRenderable>().Text = $"X {currMultiplierCombo}";
|
|
|
|
|
multiplierText.GetComponent<Transform>().LocalScale -= fontScalar * Time.DeltaTimeF;
|
|
|
|
|
currMultiplierDuration += Time.DeltaTimeF;
|
|
|
|
|
|
|
|
|
|
if (currMultiplierDuration >= maxMultiplierDuration)
|
|
|
|
|
{
|
|
|
|
|
itemScored = false;
|
|
|
|
|
currMultiplierCombo = 1;
|
|
|
|
|
currMultiplierDuration = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
multiplierText.GetComponent<Transform>().LocalScale = Vector3.Zero;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
if ((timer > 0 && totalItemCount < 0) || Input.GetKeyDown(Input.KeyCode.F1))
|
2022-11-23 16:57:32 +08:00
|
|
|
|
{
|
2022-11-20 16:27:39 +08:00
|
|
|
|
currGameState = GameState.WIN;
|
2022-11-25 16:23:26 +08:00
|
|
|
|
Audio.StopAllSounds();
|
2022-11-23 16:57:32 +08:00
|
|
|
|
SceneManager.ChangeScene(winScene);
|
2023-02-04 00:23:05 +08:00
|
|
|
|
//Audio.PlaySFXOnce2D("event:/Music/stingers/game_win");
|
|
|
|
|
AudioHandler.audioClipHandlers["BGMWin"].Play();
|
2022-11-20 16:27:39 +08:00
|
|
|
|
}
|
2022-11-25 22:32:41 +08:00
|
|
|
|
else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2))
|
2022-11-23 20:26:53 +08:00
|
|
|
|
{
|
|
|
|
|
currGameState = GameState.LOSE;
|
2022-11-25 16:23:26 +08:00
|
|
|
|
Audio.StopAllSounds();
|
2022-11-23 20:26:53 +08:00
|
|
|
|
SceneManager.ChangeScene(loseScene);
|
2023-02-04 00:23:05 +08:00
|
|
|
|
//Audio.PlaySFXOnce2D("event:/Music/stingers/game_lose");
|
|
|
|
|
AudioHandler.audioClipHandlers["BGMLose"].Play();
|
2022-11-23 20:26:53 +08:00
|
|
|
|
}
|
2022-11-23 16:57:32 +08:00
|
|
|
|
}
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
protected override void onDestroy()
|
|
|
|
|
{
|
|
|
|
|
if (Instance == this)
|
|
|
|
|
Instance = null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 00:54:45 +08:00
|
|
|
|
private void Cheats()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyDown(Input.KeyCode.Escape))
|
|
|
|
|
{
|
2022-11-25 16:23:26 +08:00
|
|
|
|
Audio.StopAllSounds();
|
2022-11-25 00:54:45 +08:00
|
|
|
|
SceneManager.ChangeScene(97158628);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-02 22:44:30 +08:00
|
|
|
|
|
|
|
|
|
public void ItemScored()
|
|
|
|
|
{
|
|
|
|
|
totalItemCount -= 1;
|
|
|
|
|
itemScored = true;
|
|
|
|
|
currMultiplierDuration = 0;
|
|
|
|
|
multiplierText.GetComponent<Transform>().LocalScale = new Vector3(multiplierFont, multiplierFont, multiplierFont);
|
|
|
|
|
if (currMultiplierCombo < maxMultiplierCombo)
|
|
|
|
|
currMultiplierCombo += 1;
|
|
|
|
|
}
|
2022-11-25 00:54:45 +08:00
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|