109 lines
2.9 KiB
C#
109 lines
2.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public enum Location
|
|
{
|
|
Pechatniki,
|
|
Sherbinka,
|
|
BulevardSlavyanski,
|
|
Solnechaya,
|
|
Shukenskaya,
|
|
AprelevkaDepo
|
|
}
|
|
|
|
public class GameSystem : MonoBehaviour
|
|
{
|
|
public static GameSystem Instance { get; private set; }
|
|
public List<IGameComponent> gameComponents { get; private set; } = new List<IGameComponent>();
|
|
|
|
[SerializeField] GameObject[] sigletonComponents;
|
|
[SerializeField] CanvasGroup loadingCanvas;
|
|
|
|
public event Action OnSceneLoaded;
|
|
|
|
public Dictionary<string, string> locationsName { get; private set; } = new()
|
|
{
|
|
{"StationPechatnici", "Станция Печатники"},
|
|
{"", "Станция Щербинка"},
|
|
{"", "Станция Славянский бульвар"},
|
|
{"StationSolnechnaya", "Станция Солнечная"},
|
|
{"StationShchukinskaya", "Станция Щукенская"},
|
|
{"", "Депо Апрелевка"}
|
|
};
|
|
|
|
public void LoadScene(string sceneName)
|
|
{
|
|
if(!loadingCanvas.gameObject.activeSelf)
|
|
loadingCanvas.gameObject.SetActive(true);
|
|
|
|
loadingCanvas.DOFade(1, .5f).OnComplete(async() =>
|
|
{
|
|
var qrReader = FindObjectOfType<QRCodeReader>();
|
|
qrReader.camTexture.Stop();
|
|
|
|
var sceneLoadingOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
|
|
while(!sceneLoadingOperation.isDone) await Task.Yield();
|
|
|
|
OnSceneLoaded?.Invoke();
|
|
loadingCanvas.gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
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);
|
|
QRCodeReader.Instance.OnQRCodeRead += LoadScene;
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |