90 lines
1.9 KiB
C#
90 lines
1.9 KiB
C#
using SHADE;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class GameManager : Script
|
|
{
|
|
public enum GameState
|
|
{
|
|
START,
|
|
WIN,
|
|
LOSE
|
|
}
|
|
|
|
public GameObject itemPool;
|
|
public GameObject zonePool;
|
|
|
|
public uint winScene = 92009475;
|
|
public uint loseScene = 91685359;
|
|
|
|
[NonSerialized]
|
|
public GameState currGameState;
|
|
[NonSerialized]
|
|
public int totalItemCount;
|
|
[NonSerialized]
|
|
public int Score;
|
|
[NonSerialized]
|
|
public float timer;
|
|
|
|
private IEnumerable<Item> listOfItems;
|
|
private IEnumerable<ScoringZone> listOfZone;
|
|
|
|
public GameObject scoreText;
|
|
public GameObject timeText;
|
|
|
|
private bool once = true;
|
|
|
|
|
|
protected override void awake()
|
|
{
|
|
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
|
|
totalItemCount = 0;
|
|
Score = 0;
|
|
currGameState = GameState.START;
|
|
|
|
if (zonePool)
|
|
{
|
|
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
|
|
if (listOfZone != null)
|
|
foreach (ScoringZone sz in listOfZone)
|
|
sz.gameManger = Owner.GetScript<GameManager>();
|
|
}
|
|
}
|
|
|
|
protected override void update()
|
|
{
|
|
if (once)
|
|
{
|
|
if (itemPool)
|
|
{
|
|
listOfItems = itemPool.GetScriptsInChildren<Item>();
|
|
if (listOfItems != null)
|
|
foreach (Item i in listOfItems)
|
|
totalItemCount += 1;
|
|
}
|
|
once = false;
|
|
}
|
|
|
|
if (currGameState == GameState.START)
|
|
{
|
|
timer -= Time.DeltaTimeF;
|
|
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)
|
|
{
|
|
currGameState = GameState.WIN;
|
|
SceneManager.ChangeScene(winScene);
|
|
}
|
|
else if(timer < 0)
|
|
{
|
|
currGameState = GameState.LOSE;
|
|
SceneManager.ChangeScene(loseScene);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|