This commit is contained in:
Daniel Tyomin 2024-08-20 03:30:10 +02:00
parent 7c50f1b9a9
commit 15a3d8238f
10 changed files with 2691 additions and 23456 deletions

View File

@ -20,7 +20,9 @@ MonoBehaviour:
TimeLimit: 120 TimeLimit: 120
LevelMessage: 'Welcome, employee! LevelMessage: 'Welcome, employee!
Please ensure the quality of our HexaTorus Please ensure the quality of our Torus product.
product.'
Dispose
of defective units using the disposal belt.'
SuccessMessage: Great job! SuccessMessage: Great job!
FailureMessage: Try again! FailureMessage: Please try harder in the future!

View File

@ -21,7 +21,13 @@ MonoBehaviour:
Quantity: 15 Quantity: 15
MaxDefectivePercentage: 25 MaxDefectivePercentage: 25
TimeLimit: 180 TimeLimit: 180
LevelMessage: We are pleased to announce that we have secured the capital for the LevelMessage: 'We have scaled up Torus production.
expansion.
The newest Torus assembly
line is equipped with an automatic defect scanner, pay attention to its signals.
We''re
also happy to announce that an E(tm) production line is now operational.'
SuccessMessage: Great job! SuccessMessage: Great job!
FailureMessage: Try again! FailureMessage: Please try harder in the future!

View File

@ -22,6 +22,6 @@ MonoBehaviour:
MaxDefectivePercentage: 25 MaxDefectivePercentage: 25
TimeLimit: 240 TimeLimit: 240
LevelMessage: We are pleased to announce that we have secured the capital for the LevelMessage: We are pleased to announce that we have secured the capital for the
expansion. expansion of E(tm) production.
SuccessMessage: Great job! SuccessMessage: Great job!
FailureMessage: Try again! FailureMessage: Please try harder in the future!

BIN
Assets/Meshes/machine2.fbx (Stored with Git LFS)

Binary file not shown.

View File

@ -292,7 +292,7 @@ namespace Nothke.Interaction
} }
else else
{ {
Cursor.lockState = CursorLockMode.Locked; //Cursor.lockState = CursorLockMode.Locked;
//System.Windows.Forms.Cursor.Position = new System.Drawing.Point(Screen.width / 2, Screen.height / 2); //System.Windows.Forms.Cursor.Position = new System.Drawing.Point(Screen.width / 2, Screen.height / 2);
} }
#endif #endif

View File

@ -19,7 +19,7 @@ namespace KinematicCharacterController.Examples
private void Start() private void Start()
{ {
Cursor.lockState = CursorLockMode.Locked; //Cursor.lockState = CursorLockMode.Locked;
// Tell camera to follow transform // Tell camera to follow transform
CharacterCamera.SetFollowTransform(Character.CameraFollowPoint); CharacterCamera.SetFollowTransform(Character.CameraFollowPoint);
@ -31,10 +31,10 @@ namespace KinematicCharacterController.Examples
private void Update() private void Update()
{ {
if (Input.GetMouseButtonDown(0)) //if (Input.GetMouseButtonDown(0))
{ //{
Cursor.lockState = CursorLockMode.Locked; // Cursor.lockState = CursorLockMode.Locked;
} //}
HandleCharacterInput(); HandleCharacterInput();
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Text; using System.Text;
using KinematicCharacterController.Examples;
using TMPro; using TMPro;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -8,6 +8,14 @@ using UnityEngine;
public class Scoreboard: MonoBehaviour public class Scoreboard: MonoBehaviour
{ {
public static Scoreboard Instance; public static Scoreboard Instance;
public ExampleCharacterController Controller;
public ExamplePlayer Player;
public ExampleCharacterCamera Camera;
public Transform StartPosition;
public Transform StartLook;
public StagingManager.StageEnum CurrentStage;
public LevelObjective CurrentObjective; public LevelObjective CurrentObjective;
public LevelObjective Stage1Objective; public LevelObjective Stage1Objective;
@ -31,6 +39,8 @@ public class Scoreboard: MonoBehaviour
public void StartStage(StagingManager.StageEnum stage) public void StartStage(StagingManager.StageEnum stage)
{ {
CurrentStage = stage;
switch (stage) switch (stage)
{ {
case StagingManager.StageEnum.Level1: case StagingManager.StageEnum.Level1:
@ -44,13 +54,15 @@ public class Scoreboard: MonoBehaviour
break; break;
} }
RestartCurrentStage();
UpdateText(); UpdateText();
} }
#if UNITY_EDITOR #if UNITY_EDITOR
[MenuItem("Tools/Restart Level")] [MenuItem("Tools/Restart Level")]
#endif #endif
public static void RestartLevel() public static void RestartCurrentStage()
{ {
foreach (var machine in StagingManager.Instance.GetComponentsInChildren<IResetable>(true)) foreach (var machine in StagingManager.Instance.GetComponentsInChildren<IResetable>(true))
{ {
@ -65,6 +77,12 @@ public class Scoreboard: MonoBehaviour
Instance.SetObjective(Instance.CurrentObjective); Instance.SetObjective(Instance.CurrentObjective);
Instance.UpdateText(); Instance.UpdateText();
Instance.Controller.Motor.SetPosition(Instance.StartPosition.position);
Instance.Controller.Motor.SetRotation(Instance.StartPosition.rotation);
Instance.Player.enabled = false;
Instance.Camera.transform.rotation = Instance.StartLook.rotation;
Instance.Player.enabled = true;
} }
public void SetObjective(LevelObjective objective) public void SetObjective(LevelObjective objective)
@ -137,9 +155,32 @@ public class Scoreboard: MonoBehaviour
{ {
StringBuilder sb = new(); StringBuilder sb = new();
int totalSeconds = (int) _timeLeft;
int minutes = (int) _timeLeft / 60; int minutes = (int) _timeLeft / 60;
int seconds = (int) _timeLeft % 60; int seconds = (int) _timeLeft % 60;
sb.Append($"Time left: {minutes}:{seconds}\n");
sb.Append("Time left: ");
if (totalSeconds < 30)
{
sb.Append("<color=red>");
}
else
{
sb.Append("<color=green>");
}
if (seconds < 10)
{
sb.Append($"{minutes}:0{seconds}");
}
else
{
sb.Append($"{minutes}:{seconds}");
}
sb.Append("</color>\n");
sb.Append("\n"); sb.Append("\n");
@ -166,20 +207,22 @@ public class Scoreboard: MonoBehaviour
public void CountScores() public void CountScores()
{ {
bool success = true; bool success = true;
StringBuilder sb = new();
foreach (var quota in CurrentObjective.Quotas) foreach (var quota in CurrentObjective.Quotas)
{ {
if (!ProductCounts.ContainsKey(quota.Type)) if (!ProductCounts.ContainsKey(quota.Type))
{ {
success = false; success = false;
Debug.LogError($"Not enough {quota.Type.name}"); sb.Append($"Not a single product of type {quota.Type.name} was produced!\n");
break; break;
} }
if (quota.Quantity > TotalCount(quota.Type)) if (quota.Quantity > TotalCount(quota.Type))
{ {
success = false; success = false;
Debug.LogError($"Not enough {quota.Type.name}"); sb.Append($"Not enough {quota.Type.name} were produced.\n");
break; break;
} }
@ -188,13 +231,15 @@ public class Scoreboard: MonoBehaviour
if (quota.MaxDefectivePercentage < DefectPercentage(quota.Type)) if (quota.MaxDefectivePercentage < DefectPercentage(quota.Type))
{ {
success = false; success = false;
Debug.LogError($"Too many broken {quota.Type.name}"); sb.Append($"Too many of {quota.Type.name} were defective!\n");
break; break;
} }
Debug.Log($"{quota.Type.name}: Quality level: {DefectPercentage(quota.Type)}%"); sb.Append($"Overall {quota.Type.name} defect percentage: {DefectPercentage(quota.Type)}%\n");
} }
Debug.Log(success? CurrentObjective.SuccessMessage : CurrentObjective.FailureMessage); sb.Append(success ? CurrentObjective.SuccessMessage : CurrentObjective.FailureMessage);
UIManager.Instance.PushStageComplete(success, sb.ToString());
} }
} }

View File

@ -1,8 +1,20 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro;
using UnityEngine; using UnityEngine;
public class UIManager: MonoBehaviour public class UIManager: MonoBehaviour
{ {
public static UIManager Instance;
public void OnEnable()
{
if (Instance == null)
{
Instance = this;
}
}
public enum UIState public enum UIState
{ {
MainMenu = 0, MainMenu = 0,
@ -11,6 +23,7 @@ public class UIManager: MonoBehaviour
HowToPlay = 3, HowToPlay = 3,
StageSelect = 4, StageSelect = 4,
ConfirmQuit = 5, ConfirmQuit = 5,
StageComplete = 6,
} }
public List<UIState> StateStack = new List<UIState>() {UIState.MainMenu}; public List<UIState> StateStack = new List<UIState>() {UIState.MainMenu};
@ -19,8 +32,14 @@ public class UIManager: MonoBehaviour
public GameObject Reticle; public GameObject Reticle;
public GameObject HowToPlay; public GameObject HowToPlay;
public GameObject StageSelect; public GameObject StageSelect;
public GameObject Pause;
public GameObject ConfirmQuit; public GameObject ConfirmQuit;
public GameObject StageComplete;
public GameObject RetryButton;
public GameObject NextStageButton;
public TextMeshProUGUI StageCompleteText;
public void Start() public void Start()
{ {
MainMenu.SetActive(false); MainMenu.SetActive(false);
@ -28,6 +47,8 @@ public class UIManager: MonoBehaviour
HowToPlay.SetActive(false); HowToPlay.SetActive(false);
StageSelect.SetActive(false); StageSelect.SetActive(false);
ConfirmQuit.SetActive(false); ConfirmQuit.SetActive(false);
Pause.SetActive(false);
StageComplete.SetActive(false);
PushState(UIState.MainMenu); PushState(UIState.MainMenu);
} }
@ -36,17 +57,106 @@ public class UIManager: MonoBehaviour
{ {
if (StateStack.Count > 0) if (StateStack.Count > 0)
{ {
if (StateStack[0] == state)
{
return;
}
OnExitState(StateStack[0]); OnExitState(StateStack[0]);
} }
PopState();
StateStack.Add(state); StateStack.Add(state);
OnEnterState(state); OnEnterState(state);
} }
public void PushMainMenu()
{
PushState(UIState.MainMenu);
}
public void PushHowToPlay()
{
PushState(UIState.HowToPlay);
}
public void PushStageSelect()
{
PushState(UIState.StageSelect);
}
public void PushConfirmQuit()
{
PushState(UIState.ConfirmQuit);
}
public void Resume()
{
TryTogglePause();
}
public void TryTogglePause()
{
switch (StateStack[0])
{
case UIState.Game:
PushState(UIState.Pause);
break;
case UIState.Pause:
PushState(UIState.Game);
break;
case UIState.MainMenu:
PushState(UIState.ConfirmQuit);
break;
case UIState.ConfirmQuit:
PushState(UIState.MainMenu);
break;
case UIState.StageSelect:
PushState(UIState.MainMenu);
break;
case UIState.HowToPlay:
TryBackFromHelp();
break;
}
}
private bool gameRunning;
public void TryToggleHelp()
{
if (StateStack[0] == UIState.Game)
{
PushState(UIState.HowToPlay);
}
else if (StateStack[0] == UIState.HowToPlay)
{
if (!gameRunning)
{
return;
}
PushState(UIState.Game);
}
}
public void TryBackFromHelp()
{
if (gameRunning)
{
PushState(UIState.Game);
}
else
{
PushState(UIState.MainMenu);
}
}
public void PopState() public void PopState()
{ {
bool backToMain = false;
if (StateStack.Count > 0) if (StateStack.Count > 0)
{ {
OnExitState(StateStack[0]); OnExitState(StateStack[0]);
StateStack.RemoveAt(0); StateStack.RemoveAt(0);
} }
@ -60,8 +170,29 @@ public class UIManager: MonoBehaviour
MainMenu.SetActive(true); MainMenu.SetActive(true);
break; break;
case UIState.Game: case UIState.Game:
AudioListener.pause = false;
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.Locked;
Reticle.SetActive(true); Reticle.SetActive(true);
break; break;
case UIState.ConfirmQuit:
ConfirmQuit.SetActive(true);
break;
case UIState.StageSelect:
StageSelect.SetActive(true);
break;
case UIState.HowToPlay:
Cursor.lockState = CursorLockMode.None;
HowToPlay.SetActive(true);
break;
case UIState.Pause:
Cursor.lockState = CursorLockMode.None;
Pause.SetActive(true);
break;
case UIState.StageComplete:
Cursor.lockState = CursorLockMode.None;
StageComplete.SetActive(true);
break;
} }
} }
@ -74,18 +205,94 @@ public class UIManager: MonoBehaviour
break; break;
case UIState.Game: case UIState.Game:
Reticle.SetActive(false); Reticle.SetActive(false);
AudioListener.pause = true;
Time.timeScale = 0f;
break;
case UIState.ConfirmQuit:
ConfirmQuit.SetActive(false);
break;
case UIState.StageSelect:
StageSelect.SetActive(false);
break;
case UIState.HowToPlay:
HowToPlay.SetActive(false);
break;
case UIState.Pause:
Pause.SetActive(false);
break; break;
} }
} }
public void StartStage(int stage) public void StartStage(int stage)
{ {
gameRunning = true;
Time.timeScale = 1f;
Scoreboard.Instance.StartStage((StagingManager.StageEnum)stage); Scoreboard.Instance.StartStage((StagingManager.StageEnum)stage);
PushState(UIState.Game); PushState(UIState.Game);
} }
public void RestartStage()
{
Time.timeScale = 1f;
Scoreboard.RestartCurrentStage();
PushState(UIState.Game);
}
public void Quit() public void Quit()
{ {
Application.Quit(); Application.Quit();
} }
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
TryTogglePause();
return;
}
if (Input.GetKeyDown(KeyCode.F1))
{
TryToggleHelp();
return;
}
}
public void PushStageComplete(bool success, string message)
{
if (Scoreboard.Instance.CurrentStage != StagingManager.StageEnum.Level3)
{
NextStageButton.SetActive(false);
RetryButton.SetActive(false);
}
if (success)
{
NextStageButton.SetActive(true);
RetryButton.SetActive(false);
}
else
{
NextStageButton.SetActive(false);
RetryButton.SetActive(true);
}
StageCompleteText.text = message;
PushState(UIState.StageComplete);
}
public void NextStage()
{
switch (Scoreboard.Instance.CurrentStage)
{
case StagingManager.StageEnum.Level1:
StartStage(1);
break;
case StagingManager.StageEnum.Level2:
StartStage(2);
break;
case StagingManager.StageEnum.Level3:
break;
}
}
} }