From 8dd61407cdfb890e2191409cd9bb6cfee96d8ac5 Mon Sep 17 00:00:00 2001 From: Trey Shaw Date: Fri, 17 Apr 2026 21:21:42 -0500 Subject: [PATCH] fade to correct scene when current scene doesn't match save file on load --- Assets/Scenes/SampleScene.unity | 45 ---------------------- Assets/Scripts/Management/GameManager.cs | 37 ++++++++++++------ Assets/Scripts/Management/MapPoint.cs | 6 +++ Assets/Scripts/Management/PlayerManager.cs | 16 ++++---- 4 files changed, 41 insertions(+), 63 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index cddccf4..8aff1e9 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -2984,17 +2984,6 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1286273673} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} ---- !u!114 &1299342542 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 7112063300641303959, guid: 6d1ef2b53d3ef0446852da522af66b73, type: 3} - m_PrefabInstance: {fileID: 6325623361260993107} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} - m_Name: - m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Button --- !u!1 &1316688875 GameObject: m_ObjectHideFlags: 0 @@ -3149,17 +3138,6 @@ Transform: - {fileID: 813193272} m_Father: {fileID: 265036979} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1366274845 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 1356069847872831277, guid: 6d1ef2b53d3ef0446852da522af66b73, type: 3} - m_PrefabInstance: {fileID: 6325623361260993107} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} - m_Name: - m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Button --- !u!1 &1378316137 GameObject: m_ObjectHideFlags: 0 @@ -4156,17 +4134,6 @@ Transform: - {fileID: 441147620} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &2079108456 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 4694531887666682614, guid: 6d1ef2b53d3ef0446852da522af66b73, type: 3} - m_PrefabInstance: {fileID: 6325623361260993107} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} - m_Name: - m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Button --- !u!1 &2146681811 GameObject: m_ObjectHideFlags: 0 @@ -4452,18 +4419,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 8504793874200787636, guid: 6d1ef2b53d3ef0446852da522af66b73, type: 3} - propertyPath: QuitButton - value: - objectReference: {fileID: 2079108456} - - target: {fileID: 8504793874200787636, guid: 6d1ef2b53d3ef0446852da522af66b73, type: 3} - propertyPath: SaveButton - value: - objectReference: {fileID: 1366274845} - - target: {fileID: 8504793874200787636, guid: 6d1ef2b53d3ef0446852da522af66b73, type: 3} - propertyPath: DeleteSaveButton - value: - objectReference: {fileID: 1299342542} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] diff --git a/Assets/Scripts/Management/GameManager.cs b/Assets/Scripts/Management/GameManager.cs index 3b3feb3..a392666 100644 --- a/Assets/Scripts/Management/GameManager.cs +++ b/Assets/Scripts/Management/GameManager.cs @@ -44,7 +44,6 @@ private void Awake() private void Start() { SaveSystem.Load(); - SaveSystem.Save(); // save off any corruption fixes } /// @@ -70,15 +69,15 @@ private void ReloadReferences() /// /// Triggers transition to a map point /// - public void GoToMapPoint(MapPoint mapPoint) + public void GoToMapPoint(MapPoint mapPoint, bool instantBlackScreen = false) { - StartCoroutine(GoToMapPointCoroutine(mapPoint)); + StartCoroutine(GoToMapPointCoroutine(mapPoint, instantBlackScreen)); } /// /// Executes transition to map point (scene and location) /// - 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) { diff --git a/Assets/Scripts/Management/MapPoint.cs b/Assets/Scripts/Management/MapPoint.cs index b10cf4b..db593e2 100644 --- a/Assets/Scripts/Management/MapPoint.cs +++ b/Assets/Scripts/Management/MapPoint.cs @@ -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; + } } diff --git a/Assets/Scripts/Management/PlayerManager.cs b/Assets/Scripts/Management/PlayerManager.cs index 2185360..2ae2226 100644 --- a/Assets/Scripts/Management/PlayerManager.cs +++ b/Assets/Scripts/Management/PlayerManager.cs @@ -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 }