305 lines
7.3 KiB
C#
305 lines
7.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using I2.Loc;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class LoadingManager : MonoBehaviour
|
|
{
|
|
public enum LoadingState
|
|
{
|
|
NOTHING = 0,
|
|
PRELOADING = 1,
|
|
LOADING = 2,
|
|
BUTTON = 3,
|
|
INITIALIZING = 4
|
|
}
|
|
|
|
private LoadingState loadingState;
|
|
|
|
private float timer;
|
|
|
|
public bool infiniteTest;
|
|
|
|
public static string chosenLevel = "MainMenu";
|
|
|
|
public static string chosenLevelPrev = string.Empty;
|
|
|
|
public static bool spawnFish;
|
|
|
|
public Text hintLabel;
|
|
|
|
public Text percentLabel;
|
|
|
|
public Text textLabel;
|
|
|
|
public Text textDemoLabel;
|
|
|
|
public Text loadingFishLabel;
|
|
|
|
public List<GameObject> progressIndicators = new List<GameObject>();
|
|
|
|
public float animationSpeed = 1f;
|
|
|
|
private string loadingText = string.Empty;
|
|
|
|
public Image logo;
|
|
|
|
public Outline logoOutline;
|
|
|
|
public List<string> levelsWithLogoOutline = new List<string>();
|
|
|
|
private AsyncOperation async;
|
|
|
|
public Image background;
|
|
|
|
public Sprite backgroundStart;
|
|
|
|
public Texture backgroundStartVR;
|
|
|
|
public OVROverlay backgroundOverlay;
|
|
|
|
public Texture testOverlayTexture;
|
|
|
|
public Sprite testOverlaySprite;
|
|
|
|
public static int currentBackground;
|
|
|
|
public Camera backgroundCamera;
|
|
|
|
public Camera guiCamera;
|
|
|
|
public Canvas backgroundCanvas;
|
|
|
|
public Canvas guiCanvas;
|
|
|
|
private CameraFilterPack_Distortion_Water_Drop cameraEffect_01;
|
|
|
|
private CameraFilterPack_Distortion_Wave_Horizontal cameraEffect_02;
|
|
|
|
private static LoadingManager instance;
|
|
|
|
public static LoadingManager Instance
|
|
{
|
|
get
|
|
{
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
private LoadingManager()
|
|
{
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (VRManager.IsVROn())
|
|
{
|
|
backgroundCanvas.renderMode = RenderMode.WorldSpace;
|
|
RectTransform component = backgroundCanvas.GetComponent<RectTransform>();
|
|
component.anchoredPosition3D = new Vector3(component.anchoredPosition3D.x, 250.8f, 9f);
|
|
guiCanvas.renderMode = RenderMode.WorldSpace;
|
|
component = guiCanvas.GetComponent<RectTransform>();
|
|
component.localScale = Vector3.one * 0.009f;
|
|
component.anchoredPosition3D = new Vector3(component.anchoredPosition3D.x, 250.7f, 9f);
|
|
guiCamera.gameObject.SetActive(false);
|
|
guiCamera.GetComponent<CameraFilterPack_Distortion_Water_Drop>().enabled = false;
|
|
backgroundCamera.GetComponent<CameraFilterPack_Distortion_Water_Drop>().enabled = false;
|
|
UnityEngine.Object.DestroyImmediate(backgroundCamera.GetComponent<CameraFilterPack_Distortion_Water_Drop>());
|
|
VRManager.Instance.ShowMenuEnviro(false);
|
|
VRManager.Instance.HideGazeAndPointer();
|
|
if ((bool)VRControllersManager.Instance)
|
|
{
|
|
VRControllersManager.Instance.ShowHandsQuick(false);
|
|
}
|
|
}
|
|
if (Screen.width == 0 || Screen.height == 0 || Screen.width == 1 || Screen.height == 1)
|
|
{
|
|
Screen.fullScreen = false;
|
|
}
|
|
if (chosenLevelPrev == string.Empty)
|
|
{
|
|
Debug.Log("Screen prefs resolution" + Screen.width + " " + Screen.height);
|
|
Debug.Log("Screen.currentResolution" + Screen.currentResolution.width + " " + Screen.currentResolution.height);
|
|
}
|
|
Time.timeScale = 1f;
|
|
if (instance == null)
|
|
{
|
|
instance = this;
|
|
}
|
|
cameraEffect_01 = guiCamera.GetComponent<CameraFilterPack_Distortion_Water_Drop>();
|
|
cameraEffect_02 = guiCamera.GetComponent<CameraFilterPack_Distortion_Wave_Horizontal>();
|
|
logoOutline = logo.GetComponent<Outline>();
|
|
logoOutline.enabled = false;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (infiniteTest)
|
|
{
|
|
return;
|
|
}
|
|
LeanTween.reset();
|
|
LeanTween.init(1000);
|
|
if (VRManager.IsVROn())
|
|
{
|
|
if ((bool)backgroundOverlay)
|
|
{
|
|
backgroundOverlay.transform.position = new Vector3(0f, VRManager.Instance.eyeCenterTransform.position.y, VRManager.Instance.eyeCenterTransform.position.z + 1.3f);
|
|
}
|
|
LeanTween.delayedCall(0.2f, (Action)delegate
|
|
{
|
|
StartLoading(chosenLevel);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
StartLoading(chosenLevel);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (loadingState == LoadingState.PRELOADING)
|
|
{
|
|
loadingState = LoadingState.LOADING;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
if (chosenLevel == "MainMenu" || chosenLevel == "EquipmentTest" || chosenLevel == "TrophyRoom" || chosenLevel == "FisheryEditor" || chosenLevel == "FisheryEditor_Game" || GlobalSettings.Instance.levelsManager.GetCurrentFishery().loadingBackground == null)
|
|
{
|
|
background.sprite = backgroundStart;
|
|
cameraEffect_01.enabled = true;
|
|
textDemoLabel.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
LevelsManager.FisheryDefinition currentFishery = GlobalSettings.Instance.levelsManager.GetCurrentFishery();
|
|
background.sprite = currentFishery.loadingBackground;
|
|
cameraEffect_01.enabled = false;
|
|
textDemoLabel.enabled = false;
|
|
}
|
|
if (levelsWithLogoOutline.Contains(chosenLevel))
|
|
{
|
|
logoOutline.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
logoOutline.enabled = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
background.sprite = backgroundStart;
|
|
}
|
|
if ((bool)percentLabel)
|
|
{
|
|
percentLabel.text = string.Empty;
|
|
}
|
|
if ((bool)textLabel)
|
|
{
|
|
textLabel.text = loadingText;
|
|
}
|
|
timer = 1f;
|
|
StartCoroutine(Utilities.CleanUp());
|
|
}
|
|
else if (loadingState == LoadingState.LOADING)
|
|
{
|
|
loadingState = LoadingState.INITIALIZING;
|
|
async = SceneManager.LoadSceneAsync(chosenLevel);
|
|
}
|
|
else
|
|
{
|
|
if (loadingState != LoadingState.INITIALIZING)
|
|
{
|
|
return;
|
|
}
|
|
timer -= Time.deltaTime;
|
|
if (async != null && async.isDone)
|
|
{
|
|
textLabel.text = "Creating Fish";
|
|
}
|
|
if (async != null)
|
|
{
|
|
float num = async.progress * 100f;
|
|
num += 10f;
|
|
if (async.isDone)
|
|
{
|
|
num = 100f;
|
|
}
|
|
if (num > 100f)
|
|
{
|
|
num = 100f;
|
|
}
|
|
if ((bool)percentLabel)
|
|
{
|
|
percentLabel.text = string.Empty + (int)num + " %";
|
|
}
|
|
}
|
|
foreach (GameObject progressIndicator in progressIndicators)
|
|
{
|
|
progressIndicator.transform.Rotate(new Vector3(0f, 0f, (0f - Time.deltaTime) * animationSpeed));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void StartLoading(string levelName)
|
|
{
|
|
chosenLevel = levelName;
|
|
loadingState = LoadingState.PRELOADING;
|
|
loadingText = LocalizationManager.GetTermTranslation("GUI/LOADING");
|
|
loadingFishLabel.gameObject.SetActive(false);
|
|
if ((bool)MenuManager.Instance)
|
|
{
|
|
}
|
|
if (VRManager.IsVROn())
|
|
{
|
|
LeanTween.delayedCall(1f, (Action)delegate
|
|
{
|
|
VRManager.Instance.eyeCenterTransform.GetComponent<Camera>().farClipPlane = 30f;
|
|
VRManager.Instance.eyeCenterTransform.GetComponent<Camera>().clearFlags = CameraClearFlags.Skybox;
|
|
});
|
|
}
|
|
}
|
|
|
|
public static void LoadScene(string sceneName)
|
|
{
|
|
chosenLevelPrev = chosenLevel;
|
|
chosenLevel = sceneName;
|
|
spawnFish = false;
|
|
if (VRManager.IsVROn())
|
|
{
|
|
OVRInput.canChangeGamepad = false;
|
|
VRManager.Instance.eyeCenterTransform.GetComponent<Camera>().farClipPlane = VRManager.Instance.eyeCenterTransform.GetComponent<Camera>().nearClipPlane + 0.01f;
|
|
VRManager.Instance.eyeCenterTransform.GetComponent<Camera>().clearFlags = CameraClearFlags.Color;
|
|
LeanTween.delayedCall(0.5f, (Action)delegate
|
|
{
|
|
SceneManager.LoadScene("LoadingScreen");
|
|
});
|
|
}
|
|
else
|
|
{
|
|
SceneManager.LoadScene("LoadingScreen");
|
|
}
|
|
}
|
|
|
|
public void SpawnFish()
|
|
{
|
|
spawnFish = true;
|
|
textLabel.text = "Creating Fish";
|
|
}
|
|
|
|
public void UpdateRotation()
|
|
{
|
|
foreach (GameObject progressIndicator in progressIndicators)
|
|
{
|
|
progressIndicator.transform.Rotate(new Vector3(0f, 0f, -10f));
|
|
}
|
|
}
|
|
|
|
public void ShowLoadingFishText()
|
|
{
|
|
loadingFishLabel.gameObject.SetActive(true);
|
|
}
|
|
}
|