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-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
|
|
|
|
|
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
|
|
|
|
totalItemCount = 0;
|
|
|
|
|
Score = 0;
|
2022-11-22 17:28:48 +08:00
|
|
|
|
currGameState = GameState.START;
|
2022-11-17 00:23:38 +08:00
|
|
|
|
|
|
|
|
|
if (itemPool)
|
|
|
|
|
{
|
|
|
|
|
listOfItems = itemPool.GetScriptsInChildren<Item>();
|
2022-11-20 16:27:39 +08:00
|
|
|
|
if (listOfItems != null)
|
|
|
|
|
foreach (Item i in listOfItems)
|
|
|
|
|
totalItemCount += 1;
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
2022-11-17 12:54:08 +08:00
|
|
|
|
|
|
|
|
|
if (zonePool)
|
|
|
|
|
{
|
2022-11-20 16:27:39 +08:00
|
|
|
|
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
|
|
|
|
|
if (listOfZone != null)
|
|
|
|
|
foreach (ScoringZone sz in listOfZone)
|
|
|
|
|
sz.gameManger = Owner.GetScript<GameManager>();
|
2022-11-17 12:54:08 +08:00
|
|
|
|
}
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void update()
|
2022-11-17 12:54:08 +08:00
|
|
|
|
{
|
2022-11-20 16:27:39 +08:00
|
|
|
|
if (timer > 0 && currGameState == GameState.START)
|
|
|
|
|
{
|
2022-11-17 12:54:08 +08:00
|
|
|
|
timer -= Time.DeltaTimeF;
|
2022-11-20 16:27:39 +08:00
|
|
|
|
if (totalItemCount <= 0)
|
|
|
|
|
{
|
|
|
|
|
currGameState = GameState.WIN;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-17 12:54:08 +08:00
|
|
|
|
else
|
|
|
|
|
currGameState = GameState.LOSE;
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|