using UnityEngine; using System.Collections; using UnityEngine.EventSystems; public enum GameState { Gameplay, InventoryUI, GameOverUI, PauseUI } public class GameController : MonoBehaviour { public HudController hud; public GameOverUIController gameOverScreen; public InventoryUIController inventoryController; public PauseUiController pauseUi; private GameState _state; private float _tenseState = 100; public float _tenseReleaseSpeed = 5; private HorizontalProgressBar _tenseBar; private UiController _currentUi; private UiController _previousUi; public AudioClip gameOverClip; public GameState State { get { return _state; } } public void OnSuspiciousSound(HumanController source) { } public void OnCanSeePlayer(HumanController source) { } public void ShowUI(UiController ui) { if (_currentUi == ui) { return; } _previousUi = _currentUi; if (_previousUi != null) { _previousUi.gameObject.SetActive(false); } _currentUi = ui; if (_currentUi != null) { _currentUi.gameObject.SetActive(true); } if (_currentUi == null || _currentUi == hud || _currentUi == gameOverScreen) { Time.timeScale = 1; } else { Time.timeScale = 0; } if (_currentUi == hud) { _state = GameState.Gameplay; } } public void ShowPreviousUi(bool removeCurrentFromHistory = false) { ShowUI(_previousUi); if (removeCurrentFromHistory) { _previousUi = null; } } void Start () { _tenseBar = new HorizontalProgressBar(); ShowUI(hud); } public void GameOver(){ _state = GameState.GameOverUI; ShowUI(gameOverScreen); if (gameOverClip != null) { AudioSource.PlayClipAtPoint(gameOverClip, Vector3.zero); } //hud.gameObject.SetActive(false); //gameOverScreen.gameObject.SetActive(true); } public void PauseGame(bool pause) { Time.timeScale = pause ? 0 : 1; } void Update () { if (_state == GameState.GameOverUI) { return; } if (Input.GetKeyDown(KeyCode.I)) { var playerController = FindObjectOfType(); // bool menuVisible = inventoryController.gameObject.activeInHierarchy; if (_state == GameState.InventoryUI) { // inventoryController.gameObject.SetActive(false); _state = GameState.Gameplay; // hud.gameObject.SetActive(true); ShowUI(hud); // PauseGame(false); } else if (_state == GameState.Gameplay) { // PauseGame(true); inventoryController.inventory = playerController.GetComponent(); //inventoryController.gameObject.SetActive(true); ShowUI(inventoryController); inventoryController.Rebuild(); _state = GameState.InventoryUI; //hud.gameObject.SetActive(false); } } if (Input.GetKeyDown(KeyCode.Escape)) { if (_state != GameState.PauseUI) { ShowUI(pauseUi); } else { ShowPreviousUi(); } } } }