fade to correct scene when current scene doesn't match save file on load
This commit is contained in:
@@ -44,7 +44,6 @@ private void Awake()
|
||||
private void Start()
|
||||
{
|
||||
SaveSystem.Load();
|
||||
SaveSystem.Save(); // save off any corruption fixes
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,15 +69,15 @@ private void ReloadReferences()
|
||||
/// <summary>
|
||||
/// Triggers transition to a map point
|
||||
/// </summary>
|
||||
public void GoToMapPoint(MapPoint mapPoint)
|
||||
public void GoToMapPoint(MapPoint mapPoint, bool instantBlackScreen = false)
|
||||
{
|
||||
StartCoroutine(GoToMapPointCoroutine(mapPoint));
|
||||
StartCoroutine(GoToMapPointCoroutine(mapPoint, instantBlackScreen));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes transition to map point (scene and location)
|
||||
/// </summary>
|
||||
private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint)
|
||||
private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint, bool instantBlackScreen)
|
||||
{
|
||||
Instance.isTransitioningScenes = true;
|
||||
Instance.PlayerController.SetCharacterControl(false);
|
||||
@@ -89,15 +88,24 @@ private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint)
|
||||
float fadeTime = 0;
|
||||
Color blackScreenColor = Color.black;
|
||||
|
||||
while (fadeTime < fadeDuration)
|
||||
// Fade to black when instantBlackScreen is false
|
||||
if (!instantBlackScreen)
|
||||
{
|
||||
blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration);
|
||||
Instance.BlackScreen.color = blackScreenColor;
|
||||
fadeTime += Time.deltaTime;
|
||||
yield return null;
|
||||
while (fadeTime < fadeDuration)
|
||||
{
|
||||
blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration);
|
||||
Instance.BlackScreen.color = blackScreenColor;
|
||||
fadeTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
fadeTime = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// instantly make screen black before scene transition
|
||||
blackScreenColor.a = 1;
|
||||
Instance.BlackScreen.color = blackScreenColor;
|
||||
}
|
||||
fadeTime = 0;
|
||||
|
||||
|
||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(mapPoint.Scene);
|
||||
while (!asyncLoad.isDone)
|
||||
@@ -126,6 +134,9 @@ private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint)
|
||||
yield return null;
|
||||
}
|
||||
|
||||
blackScreenColor.a = 0;
|
||||
Instance.BlackScreen.color = blackScreenColor;
|
||||
|
||||
// move character a little more
|
||||
while (fadeTime < moveDuration)
|
||||
{
|
||||
@@ -183,6 +194,7 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
|
||||
ReloadReferences();
|
||||
|
||||
// Make sure screen is black in new scene
|
||||
blackScreenColor.a = 1;
|
||||
Instance.BlackScreen.color = blackScreenColor;
|
||||
|
||||
SceneDoor door = GameSceneManager.Instance.GetDoorWithId(doorId);
|
||||
@@ -207,6 +219,9 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
|
||||
yield return null;
|
||||
}
|
||||
|
||||
blackScreenColor.a = 0;
|
||||
Instance.BlackScreen.color = blackScreenColor;
|
||||
|
||||
// move character a little more
|
||||
while (fadeTime < moveDuration)
|
||||
{
|
||||
|
||||
@@ -7,4 +7,10 @@ public class MapPoint
|
||||
{
|
||||
public string Scene;
|
||||
public Vector3 SpawnPosition;
|
||||
|
||||
public MapPoint(string scene, Vector3 spawnPosition)
|
||||
{
|
||||
this.Scene = scene;
|
||||
this.SpawnPosition = spawnPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,16 @@ public void SavePlayerData(ref PlayerSaveData data)
|
||||
|
||||
public void LoadPlayerData(PlayerSaveData data)
|
||||
{
|
||||
/*if (data.currentScene != null && data.currentScene != SceneManager.GetActiveScene().name)
|
||||
if (data.currentScene != null && data.currentScene != SceneManager.GetActiveScene().name)
|
||||
{
|
||||
SceneManager.LoadScene(data.currentScene);
|
||||
}*/
|
||||
|
||||
GameManager.Instance.PlayerManager.CurrentToolIndex = data.activeToolIndex;
|
||||
GameManager.Instance.PlayerController.cameraController.SnapToRotation(data.camRotation);
|
||||
GameManager.Instance.PlayerController.transform.position = data.dougPosition;
|
||||
GameManager.Instance.GoToMapPoint(new MapPoint(data.currentScene, data.dougPosition), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameManager.Instance.PlayerManager.CurrentToolIndex = data.activeToolIndex;
|
||||
GameManager.Instance.PlayerController.cameraController.SnapToRotation(data.camRotation);
|
||||
GameManager.Instance.PlayerController.transform.position = data.dougPosition;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user