create menu UI

This commit is contained in:
2022-11-12 18:08:21 +05:00
parent a488ab8f99
commit 800e5fbbd6
17 changed files with 4936 additions and 2589 deletions
+29 -23
View File
@@ -14,7 +14,7 @@ public enum Location
Sherbinka,
BulevardSlavyanski,
Solnechaya,
Shukenskaya,
Shukinskaya,
AprelevkaDepo
}
@@ -23,37 +23,44 @@ public class GameSystem : MonoBehaviour
public static GameSystem Instance { get; private set; }
public List<IGameComponent> gameComponents { get; private set; } = new List<IGameComponent>();
[SerializeField] UIMainMenu mainMenu;
[Space]
[SerializeField] GameObject[] sigletonComponents;
[SerializeField] CanvasGroup loadingCanvas;
public event Action OnSceneLoaded;
public Dictionary<string, string> locationsName { get; private set; } = new()
public Dictionary<string, Location> locationsName { get; private set; } = new()
{
{"StationPechatnici", "Станция Печатники"},
{"", "Станция Щербинка"},
{"", "Станция Славянский бульвар"},
{"StationSolnechnaya", "Станция Солнечная"},
{"StationShchukinskaya", "Станция Щукенская"},
{"", "Депо Апрелевка"}
{"StationPechatnici", Location.Pechatniki},
{"1", Location.Sherbinka},
{"2", Location.BulevardSlavyanski},
{"StationSolnechnaya", Location.Solnechaya},
{"StationShchukinskaya", Location.Shukinskaya},
{"3", Location.AprelevkaDepo}
};
public void LoadScene(string sceneName)
public async void LoadScene(string sceneName)
{
if(!loadingCanvas.gameObject.activeSelf)
loadingCanvas.gameObject.SetActive(true);
loadingCanvas.DOFade(1, .5f).OnComplete(async() =>
mainMenu.UpdateLocationMenu(locationsName[sceneName]);
var qrReader = FindObjectOfType<QRCodeReader>();
qrReader.camTexture.Stop();
var sceneLoadingOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
while(!sceneLoadingOperation.isDone) await Task.Yield();
OnSceneLoaded?.Invoke();
FindObjectOfType<SceneHandler>().OnSceneLoaded += ()=>
{
var qrReader = FindObjectOfType<QRCodeReader>();
qrReader.camTexture.Stop();
mainMenu.gameObject.SetActive(true);
};
}
var sceneLoadingOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
while(!sceneLoadingOperation.isDone) await Task.Yield();
OnSceneLoaded?.Invoke();
loadingCanvas.gameObject.SetActive(false);
});
public void LeaveScene()
{
var sceneLoadingOperation = SceneManager.LoadSceneAsync("MainMenu",
LoadSceneMode.Single);
}
public void AddGameComponent(IGameComponent component)
@@ -80,7 +87,6 @@ public class GameSystem : MonoBehaviour
}
DontDestroyOnLoad(this);
QRCodeReader.Instance.OnQRCodeRead += LoadScene;
}
void Update()
+10 -3
View File
@@ -4,6 +4,7 @@ using System.Collections;
using System.Collections.Generic;
using ZXing;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
@@ -11,8 +12,7 @@ public class QRCodeReader : MonoBehaviour
{
public static QRCodeReader Instance { get; private set; }
public event Action<string> OnQRCodeRead;
[SerializeField] CanvasGroup loadingCanvas;
[SerializeField] AspectRatioFitter aspectRatioFitter;
public RawImage rawImage;
public GameObject scanFrame;
@@ -105,6 +105,13 @@ public class QRCodeReader : MonoBehaviour
yield return new WaitForSeconds(1);
OnQRCodeRead?.Invoke(result.Text);
if(!loadingCanvas.gameObject.activeSelf)
loadingCanvas.gameObject.SetActive(true);
loadingCanvas.DOFade(1, .5f).OnComplete(() =>
{
FindObjectOfType<GameSystem>()
.LoadScene(result.Text);
});
}
}
+2 -8
View File
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
@@ -14,8 +15,7 @@ public class SceneHandler : MonoBehaviour
[SerializeField] float endPositionValue;
[Space]
[SerializeField] GameObject[] disableOnStart;
[Space]
[SerializeField] UnityEvent OnSceneLoaded;
public event Action OnSceneLoaded;
async Task Start()
{
@@ -63,10 +63,4 @@ public class SceneHandler : MonoBehaviour
OnSceneLoaded?.Invoke();
}
public void LeaveScene()
{
var sceneLoadingOperation = SceneManager.LoadSceneAsync("MainMenu",
LoadSceneMode.Single);
}
}
+1
View File
@@ -22,6 +22,7 @@ public class UICanvas : MonoBehaviour
public void Hide()
{
canvasGroup.DOFade(0, .4f);
gameObject.SetActive(false);
}
void OnEnable()
+40
View File
@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIMainMenu : UICanvas
{
[SerializeField] private Text stationName;
public void UpdateLocationMenu(Location location)
{
switch(location)
{
case(Location.AprelevkaDepo):
stationName.text = "Депо Апрелевка";
break;
case(Location.BulevardSlavyanski):
stationName.text = "станция Славянский бульвар";
break;
case(Location.Pechatniki):
stationName.text = "Станция Печатники";
break;
case(Location.Sherbinka):
stationName.text = "Станция Щербинка";
break;
case(Location.Shukinskaya):
stationName.text = "Станция Щукинская";
break;
case(Location.Solnechaya):
stationName.text = "Станция Солнечная";
break;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b526cb7cf627f194d853a5f25f4a9fd8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: