add gamemaster canvas
This commit is contained in:
3
Assets/Escape Room Engine/Engine/Fonts.meta
Normal file
3
Assets/Escape Room Engine/Engine/Fonts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e23fe57328d4ca89779b491fb194e72
|
||||
timeCreated: 1668937570
|
||||
BIN
Assets/Escape Room Engine/Engine/Fonts/BebasNeue-Regular.otf
Normal file
BIN
Assets/Escape Room Engine/Engine/Fonts/BebasNeue-Regular.otf
Normal file
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 220c55da163c4bc381099af8030cc0d5
|
||||
timeCreated: 1668937570
|
||||
1837
Assets/Escape Room Engine/Engine/Prefabs/Gamemaster Canvas.prefab
Normal file
1837
Assets/Escape Room Engine/Engine/Prefabs/Gamemaster Canvas.prefab
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ab6b46f22ab480fbd1c85d5e8601025
|
||||
timeCreated: 1668937536
|
||||
129
Assets/Escape Room Engine/Engine/Scripts/GameControl.cs
Normal file
129
Assets/Escape Room Engine/Engine/Scripts/GameControl.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts
|
||||
{
|
||||
public enum GameState
|
||||
{
|
||||
Stopped, Paused, Running
|
||||
}
|
||||
|
||||
public class GameControl : MonoBehaviour
|
||||
{
|
||||
private const int InitialTime = 5 * 60;
|
||||
|
||||
[SerializeField] private Button startButton, stopButton, pauseButton, resumeButton, addMinuteButton, removeMinuteButton;
|
||||
[SerializeField] private Text timeText;
|
||||
|
||||
[HideInInspector] public GameState gameState = GameState.Stopped;
|
||||
|
||||
public float TimeRemaining => _totalTime - _timeElapsed;
|
||||
|
||||
private float _timeElapsed, _totalTime;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetGamemasterTimeText(_totalTime);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Update time
|
||||
if (gameState == GameState.Running)
|
||||
{
|
||||
if (Time.deltaTime <= TimeRemaining)
|
||||
{
|
||||
_timeElapsed += Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
_timeElapsed = _totalTime;
|
||||
StopGame();
|
||||
}
|
||||
|
||||
SetGamemasterTimeText(TimeRemaining);
|
||||
}
|
||||
|
||||
// Enable or disable buttons
|
||||
startButton.interactable = gameState == GameState.Stopped;
|
||||
stopButton.interactable = gameState != GameState.Stopped;
|
||||
pauseButton.interactable = gameState == GameState.Running;
|
||||
resumeButton.interactable = gameState == GameState.Paused;
|
||||
addMinuteButton.interactable = gameState != GameState.Stopped;
|
||||
removeMinuteButton.interactable = gameState != GameState.Stopped && TimeRemaining >= 60;
|
||||
}
|
||||
|
||||
#region Time Controls
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
gameState = GameState.Running;
|
||||
|
||||
_totalTime = InitialTime;
|
||||
_timeElapsed = 0;
|
||||
}
|
||||
|
||||
public void StopGame()
|
||||
{
|
||||
gameState = GameState.Stopped;
|
||||
}
|
||||
|
||||
public void PauseGame()
|
||||
{
|
||||
gameState = GameState.Paused;
|
||||
}
|
||||
|
||||
public void ResumeGame()
|
||||
{
|
||||
gameState = GameState.Running;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the allowed time by a specified amount of seconds.
|
||||
/// </summary>
|
||||
/// <param name="seconds">The amount of seconds that will be added to the time. Can be negative to remove time.</param>
|
||||
public void ChangeTime(int seconds)
|
||||
{
|
||||
if (_totalTime + seconds >= 0)
|
||||
{
|
||||
_totalTime += seconds;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetGamemasterTimeText(float time)
|
||||
{
|
||||
if (timeText != null)
|
||||
{
|
||||
timeText.text = TimeToText(time);
|
||||
}
|
||||
}
|
||||
|
||||
private static string TimeToText(float time)
|
||||
{
|
||||
var minutes = (int) (time / 60);
|
||||
var seconds = (int) Math.Ceiling(time - minutes * 60);
|
||||
if (seconds == 60)
|
||||
{
|
||||
minutes += 1;
|
||||
seconds = 0;
|
||||
}
|
||||
|
||||
return $"{minutes:D2}:{seconds:D2}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void ExitGame()
|
||||
{
|
||||
StopGame();
|
||||
|
||||
#if UNITY_STANDALONE
|
||||
Application.Quit();
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 676ef7e7d34646dbb24b1978563ab63b
|
||||
timeCreated: 1668937602
|
||||
Reference in New Issue
Block a user