Add Alot of stuff, Computer, repairStation, Whole game, Many things!
This commit is contained in:
141
Assets/GameScrips/GameController.cs
Normal file
141
Assets/GameScrips/GameController.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class GameController : MonoBehaviour {
|
||||
public static GameController Instance { get; private set; }
|
||||
|
||||
[SerializeField] private MainHUDController _mainHudController;
|
||||
[SerializeField] private DayEndHUDController _dayEndHudController;
|
||||
[SerializeField] private GameObject _playerGameObject;
|
||||
|
||||
private float _money = 0; //The money the player has
|
||||
private int _charisma = 0; //The charisma of the player, 0 - 100;
|
||||
|
||||
//Time stuff
|
||||
[SerializeField] private int _hoursPerDay = 8; //9 - 17
|
||||
[SerializeField] private int _realLifeMinutes = 5;
|
||||
|
||||
private float _time; //The actual time in gameHours
|
||||
private float _timeScale;
|
||||
private float _elapsedTime;
|
||||
|
||||
//End of day variables
|
||||
private float _gains;
|
||||
private float _rent;
|
||||
private float _profit;
|
||||
|
||||
private float _startingMoney;
|
||||
private bool _dayEnded = false;
|
||||
|
||||
public enum LooseCondition {
|
||||
Bankrupt,
|
||||
Charisma
|
||||
}
|
||||
|
||||
|
||||
public float Money {
|
||||
get => _money;
|
||||
//Set the money and update the HUD
|
||||
set {
|
||||
_money = value;
|
||||
_mainHudController.SetMoneyText(_money);
|
||||
}
|
||||
}
|
||||
|
||||
public int Charisma {
|
||||
get => _charisma;
|
||||
set {
|
||||
_charisma = value;
|
||||
_mainHudController.SetCharisma(_charisma);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
//Start a new day
|
||||
_time = 0;
|
||||
_dayEnded = false;
|
||||
_gains = 0;
|
||||
_rent = 0;
|
||||
_profit = 0;
|
||||
|
||||
_startingMoney = Money;
|
||||
HUDManager.Instance.HideCurrentHUD();
|
||||
_playerGameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void Awake() {
|
||||
if (Instance != null) {
|
||||
Debug.LogError("What? 2 GameControllers crazy!!!");
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void CustomerLeft(object sender, CustomerManager.OnCustomerLeftArgs e) {
|
||||
if (e.Angry) {
|
||||
//Customer left angry
|
||||
Charisma -= 10;
|
||||
if(Charisma <= 0) {
|
||||
GameOver(LooseCondition.Charisma);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_charisma + 10 <= 100) {
|
||||
_charisma += 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
Money = 100;
|
||||
Charisma = 50;
|
||||
_timeScale = (float)_hoursPerDay / (_realLifeMinutes * 60);
|
||||
Reset();
|
||||
|
||||
CustomerManager.Instance.OnCustomerLeft += CustomerLeft;
|
||||
|
||||
}
|
||||
|
||||
private void DayEnd() {
|
||||
_playerGameObject.SetActive(false);
|
||||
HUDManager.Instance.ShowDayEndHUD();
|
||||
_gains = _money - _startingMoney;
|
||||
_rent = 10;
|
||||
_profit = _gains - _rent;
|
||||
|
||||
_money += _profit; //Add the profit to the money, also includes rent
|
||||
_mainHudController.SetMoneyText(_money);
|
||||
|
||||
|
||||
HUDManager.Instance.GetDayEndController().DayEnd(_gains, _rent, _profit);
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if (!_dayEnded) {
|
||||
Debug.Log("Time: " + _time + " Elapsed Time: " + _elapsedTime + " TimeScale: " + _timeScale);
|
||||
_elapsedTime += UnityEngine.Time.deltaTime * _timeScale;
|
||||
if (_elapsedTime >= 1) {
|
||||
_time += 1;
|
||||
_elapsedTime = 0;
|
||||
}
|
||||
|
||||
int hours = (int)_time;
|
||||
|
||||
_mainHudController.SetTime(hours + 9); //Offset by 9 so it starts at 9 am
|
||||
|
||||
if (_time >= _hoursPerDay) {
|
||||
//End the day
|
||||
Debug.Log("Day Ended");
|
||||
_dayEnded = true;
|
||||
DayEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void GameOver(LooseCondition condition) {
|
||||
SceneManager.LoadScene(condition == LooseCondition.Bankrupt ? "Bankrupt" : "Charisma");
|
||||
}
|
||||
}
|
||||
11
Assets/GameScrips/GameController.cs.meta
Normal file
11
Assets/GameScrips/GameController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39c4878df96a95643a23e2d0ba8dd7d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
77
Assets/GameScrips/TutorialController.cs
Normal file
77
Assets/GameScrips/TutorialController.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TutorialController : MonoBehaviour
|
||||
{
|
||||
public List<GameObject> _uiElements = new List<GameObject>();
|
||||
|
||||
[SerializeField] private ComputerBehaviour _computerBehaviour;
|
||||
[SerializeField] private ObjectSO _item;
|
||||
|
||||
private SellCounter[] _counters;
|
||||
|
||||
private int _currentElement = 0;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Awake() { //Use Awake instead of Start to ensure that all the data is set before adding events
|
||||
_counters = FindObjectsOfType<SellCounter>();
|
||||
|
||||
|
||||
_computerBehaviour.OnBuyItem += ItemBought;
|
||||
foreach (var counter in _counters) {
|
||||
counter.OnCounterStartSelling += ItemOnSellingPedestal;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
_computerBehaviour.SetItem(_item, true);
|
||||
}
|
||||
|
||||
private void ItemBought(object sender, System.EventArgs e) {
|
||||
_computerBehaviour.OnBuyItem -= ItemBought;
|
||||
Next();
|
||||
}
|
||||
|
||||
private void ItemOnSellingPedestal(object sender, System.EventArgs e) {
|
||||
foreach (var counter in _counters) {
|
||||
counter.OnCounterStartSelling -= ItemOnSellingPedestal;
|
||||
}
|
||||
CustomerManager.Instance.OnCustomerLeft += CustomerLeft;
|
||||
Next();
|
||||
}
|
||||
|
||||
private void CustomerLeft(object sender, System.EventArgs e) {
|
||||
CustomerManager.Instance.OnCustomerLeft -= CustomerLeft;
|
||||
StartCoroutine(Countdown());
|
||||
Next();
|
||||
}
|
||||
|
||||
//20 Seconds after the customer leaves
|
||||
private IEnumerator Countdown() {
|
||||
yield return new WaitForSeconds(20);
|
||||
Next();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnEnable() {
|
||||
_uiElements[_currentElement].SetActive(true);
|
||||
}
|
||||
|
||||
private void Next() {
|
||||
_uiElements[_currentElement].SetActive(false);
|
||||
_currentElement++;
|
||||
if (_currentElement >= _uiElements.Count) {
|
||||
//End of tutorial
|
||||
Debug.Log("End of tutorial");
|
||||
this.gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
_uiElements[_currentElement].SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/GameScrips/TutorialController.cs.meta
Normal file
11
Assets/GameScrips/TutorialController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fdcaca5501821d47a0ac7f1e528281a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user