169 lines
4.1 KiB
C#
169 lines
4.1 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public enum Location
|
|
{
|
|
Pechatniki,
|
|
Sherbinka,
|
|
BulevardSlavyanski,
|
|
Solnechaya,
|
|
Shukinskaya,
|
|
AprelevkaDepo
|
|
}
|
|
|
|
public class GameSystem : MonoBehaviour
|
|
{
|
|
public static GameSystem Instance { get; private set; }
|
|
public List<IGameComponent> gameComponents { get; private set; } = new List<IGameComponent>();
|
|
|
|
[SerializeField] UIMainMenu mainMenu;
|
|
[SerializeField] UICanvas trainsMenu;
|
|
[Space]
|
|
public UICanvas trainEP2D;
|
|
public UICanvas train2;
|
|
public UICanvas train3;
|
|
[Space]
|
|
[SerializeField] GameObject[] sigletonComponents;
|
|
|
|
public event Action OnSceneLoaded;
|
|
|
|
public Dictionary<string, Location> locationsName { get; private set; } = new()
|
|
{
|
|
{"StationPechatnici", Location.Pechatniki},
|
|
{"StationSherbinka", Location.Sherbinka},
|
|
{"StationSlavyanskyBoulevard", Location.BulevardSlavyanski},
|
|
{"StationSolnechnaya", Location.Solnechaya},
|
|
{"StationShchukinskaya", Location.Shukinskaya},
|
|
{"AprelevkaDepo", Location.AprelevkaDepo}
|
|
};
|
|
|
|
public async void LoadScene(string sceneName)
|
|
{
|
|
if(mainMenu.gameObject.activeSelf)
|
|
mainMenu.Hide();
|
|
|
|
mainMenu.UpdateLocationMenu(locationsName[sceneName]);
|
|
|
|
try
|
|
{
|
|
var qrReader = FindObjectOfType<QRCodeReader>();
|
|
qrReader.camTexture.Stop();
|
|
}
|
|
catch {}
|
|
|
|
var sceneLoadingOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
|
|
while(!sceneLoadingOperation.isDone) await Task.Yield();
|
|
|
|
OnSceneLoaded?.Invoke();
|
|
|
|
FindObjectOfType<SceneHandler>().OnSceneLoaded.AddListener(()=>
|
|
{
|
|
mainMenu.gameObject.SetActive(true);
|
|
});
|
|
}
|
|
|
|
public void ShowAboutTrain()
|
|
{
|
|
switch(mainMenu.currentTrain.type)
|
|
{
|
|
case(TrainType.EP2D):
|
|
ShowAboutEP2D();
|
|
break;
|
|
|
|
case(TrainType.Ivolga2):
|
|
ShowAboutIvolga2();
|
|
break;
|
|
|
|
case(TrainType.Ivolga3):
|
|
ShowAboutIvolga3();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void ShowAboutEP2D()
|
|
{
|
|
train2.gameObject.SetActive(false);
|
|
train3.gameObject.SetActive(false);
|
|
|
|
trainsMenu.gameObject.SetActive(true);
|
|
trainEP2D.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void ShowAboutIvolga2()
|
|
{
|
|
train3.gameObject.SetActive(false);
|
|
trainEP2D.gameObject.SetActive(false);
|
|
|
|
trainsMenu.gameObject.SetActive(true);
|
|
train2.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void ShowAboutIvolga3()
|
|
{
|
|
train2.gameObject.SetActive(false);
|
|
trainEP2D.gameObject.SetActive(false);
|
|
|
|
trainsMenu.gameObject.SetActive(true);
|
|
train3.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void LeaveScene()
|
|
{
|
|
var sceneLoadingOperation = SceneManager.LoadSceneAsync("MainMenu",
|
|
LoadSceneMode.Single);
|
|
}
|
|
|
|
public void AddGameComponent(IGameComponent component)
|
|
{
|
|
if(!gameComponents.Contains(component))
|
|
gameComponents.Add(component);
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
foreach(var item in sigletonComponents)
|
|
DontDestroyOnLoad(item.gameObject);
|
|
|
|
Instance = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
GameSystem[] gameSystems = FindObjectsOfType<GameSystem>();
|
|
if(gameSystems.Length > 1)
|
|
{
|
|
Destroy(this.gameObject);
|
|
return;
|
|
}
|
|
|
|
DontDestroyOnLoad(this);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
for(int i = 0; i < gameComponents.Count; i++)
|
|
gameComponents[i].OnUpdate();
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
for(int i = 0; i < gameComponents.Count; i++)
|
|
gameComponents[i].OnFixedUpdate();
|
|
}
|
|
|
|
void LateUpdate()
|
|
{
|
|
for(int i = 0; i < gameComponents.Count; i++)
|
|
gameComponents[i].OnLateUpdate();
|
|
}
|
|
|
|
public void RemoveGameComponent(IGameComponent component)
|
|
{
|
|
if(gameComponents.Contains(component))
|
|
gameComponents.Remove(component);
|
|
}
|
|
} |