216 lines
4.6 KiB
C#
216 lines
4.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UFS2.Gameplay;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class SceneLoader : Singleton<SceneLoader>
|
|
{
|
|
[Serializable]
|
|
private class logoList
|
|
{
|
|
public string mapName;
|
|
|
|
public Sprite mapLogo;
|
|
}
|
|
|
|
public Sprite[] backgroundSprites;
|
|
|
|
public Image backgroundImage;
|
|
|
|
public string sceneLoadName = "";
|
|
|
|
public Animator animator;
|
|
|
|
private bool isLoaded;
|
|
|
|
[Range(0f, 1f)]
|
|
public float progress;
|
|
|
|
public bool goToMenu;
|
|
|
|
private AsyncOperation asyncOperation;
|
|
|
|
[SerializeField]
|
|
private GameObject SpaceText;
|
|
|
|
[SerializeField]
|
|
private GameObject ReelGameObject;
|
|
|
|
[SerializeField]
|
|
private GameObject UfsLogo;
|
|
|
|
[SerializeField]
|
|
private GameObject ReelHideGameObject;
|
|
|
|
[SerializeField]
|
|
private GameObject LineGameObject;
|
|
|
|
[SerializeField]
|
|
private Image MapLogo;
|
|
|
|
[SerializeField]
|
|
private Text TipTitle;
|
|
|
|
[SerializeField]
|
|
private Text TipText;
|
|
|
|
[SerializeField]
|
|
private string[] tipsTitleKeys;
|
|
|
|
[SerializeField]
|
|
private string[] tipsTextKeys;
|
|
|
|
private bool isFishesLoaded;
|
|
|
|
private int tipIndex;
|
|
|
|
[SerializeField]
|
|
private logoList[] logoslist;
|
|
|
|
public static event Action<string> OnBeginSceneLoad;
|
|
|
|
public static event Action<string> OnSceneLoaded;
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
tipIndex = UnityEngine.Random.Range(0, tipsTitleKeys.Length);
|
|
SceneLoader.OnBeginSceneLoad?.Invoke(sceneLoadName);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
TipTitle.text = LanguageManager.Instance.GetText(tipsTitleKeys[tipIndex]);
|
|
TipText.text = LanguageManager.Instance.GetText(tipsTextKeys[tipIndex]);
|
|
backgroundImage.sprite = GetMapSpriteByName(sceneLoadName);
|
|
MapLogo.sprite = GetMapLogoByMapName(sceneLoadName);
|
|
if (sceneLoadName != "")
|
|
{
|
|
StartCoroutine(LoadSceneAsync(sceneLoadName));
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
FishSpawner.OnStartFishesSpawned += FishSpawner_OnStartFishesSpawned;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
FishSpawner.OnStartFishesSpawned -= FishSpawner_OnStartFishesSpawned;
|
|
}
|
|
|
|
private void FishSpawner_OnStartFishesSpawned()
|
|
{
|
|
isFishesLoaded = true;
|
|
}
|
|
|
|
public void FixedUpdate()
|
|
{
|
|
if (sceneLoadName == "Startowa")
|
|
{
|
|
isFishesLoaded = true;
|
|
}
|
|
if (isFishesLoaded && isLoaded && asyncOperation.isDone)
|
|
{
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
SceneLoader.OnSceneLoaded?.Invoke(sceneLoadName);
|
|
}
|
|
}
|
|
|
|
public void OnGUI()
|
|
{
|
|
if (Input.GetKeyUp(KeyCode.A))
|
|
{
|
|
tipIndex--;
|
|
if (tipIndex < 0)
|
|
{
|
|
tipIndex = tipsTitleKeys.Length - 1;
|
|
}
|
|
TipTitle.text = LanguageManager.Instance.GetText(tipsTitleKeys[tipIndex]);
|
|
TipText.text = LanguageManager.Instance.GetText(tipsTextKeys[tipIndex]);
|
|
}
|
|
else if (Input.GetKeyUp(KeyCode.D))
|
|
{
|
|
tipIndex++;
|
|
if (tipIndex >= tipsTitleKeys.Length)
|
|
{
|
|
tipIndex = 0;
|
|
}
|
|
TipTitle.text = LanguageManager.Instance.GetText(tipsTitleKeys[tipIndex]);
|
|
TipText.text = LanguageManager.Instance.GetText(tipsTextKeys[tipIndex]);
|
|
}
|
|
}
|
|
|
|
private void OnLevelWasLoaded()
|
|
{
|
|
Debug.Log("Level" + sceneLoadName + " was Loaded");
|
|
StartCoroutine(SetDoneEnumerator());
|
|
}
|
|
|
|
private IEnumerator LoadSceneAsync(string scenename)
|
|
{
|
|
yield return null;
|
|
asyncOperation = SceneManager.LoadSceneAsync(scenename);
|
|
asyncOperation.allowSceneActivation = false;
|
|
while (!asyncOperation.isDone)
|
|
{
|
|
progress = asyncOperation.progress;
|
|
animator.Play("Loading", 0, progress);
|
|
if (progress >= 0.9f)
|
|
{
|
|
asyncOperation.allowSceneActivation = true;
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
private IEnumerator SetDoneEnumerator()
|
|
{
|
|
if (sceneLoadName == "Niemcy")
|
|
{
|
|
yield return new WaitForSeconds(3f);
|
|
}
|
|
else
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
}
|
|
ReelHideGameObject.SetActive(value: false);
|
|
LineGameObject.SetActive(value: false);
|
|
isLoaded = true;
|
|
}
|
|
|
|
private Sprite GetMapSpriteByName(string scenename)
|
|
{
|
|
for (int i = 0; i < GameManager.Instance.gameLocations.Length; i++)
|
|
{
|
|
if (GameManager.Instance.gameLocations[i].sceneName == scenename)
|
|
{
|
|
if (GameManager.Instance.gameLocations[i].mapScreens.Length == 0)
|
|
{
|
|
break;
|
|
}
|
|
int num = UnityEngine.Random.Range(0, GameManager.Instance.gameLocations[i].mapScreens.Length);
|
|
return GameManager.Instance.gameLocations[i].mapScreens[num];
|
|
}
|
|
}
|
|
UfsLogo.SetActive(value: false);
|
|
return backgroundSprites[UnityEngine.Random.Range(0, backgroundSprites.Length)];
|
|
}
|
|
|
|
private Sprite GetMapLogoByMapName(string scenename)
|
|
{
|
|
for (int i = 0; i < GameManager.Instance.gameLocations.Length; i++)
|
|
{
|
|
if (GameManager.Instance.gameLocations[i].sceneName == scenename)
|
|
{
|
|
return GameManager.Instance.gameLocations[i].mapLogo;
|
|
}
|
|
}
|
|
MapLogo.gameObject.SetActive(value: false);
|
|
return null;
|
|
}
|
|
}
|