From fef184704f993095dfc150c98b9b25279ec2e6de Mon Sep 17 00:00:00 2001
From: MrGadget1024 <9826063+MrGadget1024@users.noreply.github.com>
Date: Tue, 21 Mar 2023 14:50:27 -0400
Subject: [PATCH] FadeInOut: Added GetDuration
---
.../Examples/AdditiveLevels/Scripts/FadeInOut.cs | 14 ++++++++++++++
.../Examples/AdditiveLevels/Scripts/Portal.cs | 2 +-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/Assets/Mirror/Examples/AdditiveLevels/Scripts/FadeInOut.cs b/Assets/Mirror/Examples/AdditiveLevels/Scripts/FadeInOut.cs
index bb9709d3e..f50758f99 100644
--- a/Assets/Mirror/Examples/AdditiveLevels/Scripts/FadeInOut.cs
+++ b/Assets/Mirror/Examples/AdditiveLevels/Scripts/FadeInOut.cs
@@ -16,6 +16,19 @@ public class FadeInOut : MonoBehaviour
[Tooltip("Color to use during scene transition")]
public Color fadeColor = Color.black;
+ ///
+ /// Calculates FadeIn / FadeOut time.
+ ///
+ /// Duration in seconds
+ public float GetDuration()
+ {
+ float frames = 1 / (stepRate * 0.1f);
+ float frameRate = Time.deltaTime;
+ float duration = frames * frameRate * 0.1f;
+ Debug.Log($"GetDuration {stepRate} : {frames} * {frameRate} = {duration}");
+ return duration;
+ }
+
public IEnumerator FadeIn()
{
float alpha = fadeImage.color.a;
@@ -31,6 +44,7 @@ public IEnumerator FadeIn()
public IEnumerator FadeOut()
{
+ Debug.Log("FadeOut");
float alpha = fadeImage.color.a;
while (alpha > 0)
diff --git a/Assets/Mirror/Examples/AdditiveLevels/Scripts/Portal.cs b/Assets/Mirror/Examples/AdditiveLevels/Scripts/Portal.cs
index 6db6c911d..717ab8168 100644
--- a/Assets/Mirror/Examples/AdditiveLevels/Scripts/Portal.cs
+++ b/Assets/Mirror/Examples/AdditiveLevels/Scripts/Portal.cs
@@ -65,7 +65,7 @@ IEnumerator SendPlayerToNewScene(GameObject player)
// Tell client to unload previous subscene. No custom handling for this.
conn.Send(new SceneMessage { sceneName = gameObject.scene.path, sceneOperation = SceneOperation.UnloadAdditive, customHandling = true });
- yield return AdditiveLevelsNetworkManager.singleton.fadeInOut.FadeIn();
+ yield return new WaitForSeconds(AdditiveLevelsNetworkManager.singleton.fadeInOut.GetDuration());
NetworkServer.RemovePlayerForConnection(conn, false);