2022-11-17 00:23:38 +08:00
|
|
|
|
using SHADE;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
public class GameManager : Script
|
|
|
|
|
{
|
2022-11-17 12:54:08 +08:00
|
|
|
|
public enum GameState
|
2022-11-17 00:23:38 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GameObject itemPool;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
public GameObject zonePool;
|
|
|
|
|
|
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-17 00:23:38 +08:00
|
|
|
|
private IEnumerable<Item> listOfItems;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
private IEnumerable<ScoringZone> listOfZone;
|
2022-11-17 00:23:38 +08:00
|
|
|
|
|
2022-11-23 20:26:53 +08:00
|
|
|
|
public GameObject scoreText;
|
|
|
|
|
public GameObject timeText;
|
|
|
|
|
|
|
|
|
|
private bool once = true;
|
|
|
|
|
|
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
2022-11-23 20:26:53 +08:00
|
|
|
|
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
|
2022-11-17 00:23:38 +08:00
|
|
|
|
totalItemCount = 0;
|
|
|
|
|
Score = 0;
|
2022-11-22 17:28:48 +08:00
|
|
|
|
currGameState = GameState.START;
|
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 (once)
|
|
|
|
|
{
|
|
|
|
|
if (itemPool)
|
|
|
|
|
{
|
|
|
|
|
listOfItems = itemPool.GetScriptsInChildren<Item>();
|
|
|
|
|
if (listOfItems != null)
|
|
|
|
|
foreach (Item i in listOfItems)
|
|
|
|
|
totalItemCount += 1;
|
|
|
|
|
}
|
2022-11-25 00:54:45 +08:00
|
|
|
|
|
|
|
|
|
if (zonePool)
|
|
|
|
|
{
|
|
|
|
|
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
|
|
|
|
|
if (listOfZone != null)
|
|
|
|
|
foreach (ScoringZone sz in listOfZone)
|
|
|
|
|
sz.gameManger = Owner.GetScript<GameManager>();
|
|
|
|
|
}
|
2022-11-23 20:26:53 +08:00
|
|
|
|
once = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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")}";
|
|
|
|
|
|
|
|
|
|
if (timer > 0 && totalItemCount <= 0)
|
2022-11-23 16:57:32 +08:00
|
|
|
|
{
|
2022-11-20 16:27:39 +08:00
|
|
|
|
currGameState = GameState.WIN;
|
2022-11-23 16:57:32 +08:00
|
|
|
|
SceneManager.ChangeScene(winScene);
|
2022-11-20 16:27:39 +08:00
|
|
|
|
}
|
2022-11-23 20:26:53 +08:00
|
|
|
|
else if(timer < 0)
|
|
|
|
|
{
|
|
|
|
|
currGameState = GameState.LOSE;
|
|
|
|
|
SceneManager.ChangeScene(loseScene);
|
|
|
|
|
}
|
2022-11-23 16:57:32 +08:00
|
|
|
|
}
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 00:54:45 +08:00
|
|
|
|
private void Cheats()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyDown(Input.KeyCode.F1))
|
|
|
|
|
{
|
|
|
|
|
SceneManager.ChangeScene(loseScene);
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKeyDown(Input.KeyCode.F2))
|
|
|
|
|
{
|
|
|
|
|
SceneManager.ChangeScene(winScene);
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKeyDown(Input.KeyCode.Escape))
|
|
|
|
|
{
|
|
|
|
|
SceneManager.ChangeScene(97158628);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|