FadeInOut: Added GetDuration

This commit is contained in:
MrGadget1024 2023-03-21 14:50:27 -04:00
parent 6e2227dcbf
commit fef184704f
2 changed files with 15 additions and 1 deletions

View File

@ -16,6 +16,19 @@ public class FadeInOut : MonoBehaviour
[Tooltip("Color to use during scene transition")] [Tooltip("Color to use during scene transition")]
public Color fadeColor = Color.black; public Color fadeColor = Color.black;
/// <summary>
/// Calculates FadeIn / FadeOut time.
/// </summary>
/// <returns>Duration in seconds</returns>
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() public IEnumerator FadeIn()
{ {
float alpha = fadeImage.color.a; float alpha = fadeImage.color.a;
@ -31,6 +44,7 @@ public IEnumerator FadeIn()
public IEnumerator FadeOut() public IEnumerator FadeOut()
{ {
Debug.Log("FadeOut");
float alpha = fadeImage.color.a; float alpha = fadeImage.color.a;
while (alpha > 0) while (alpha > 0)

View File

@ -65,7 +65,7 @@ IEnumerator SendPlayerToNewScene(GameObject player)
// Tell client to unload previous subscene. No custom handling for this. // Tell client to unload previous subscene. No custom handling for this.
conn.Send(new SceneMessage { sceneName = gameObject.scene.path, sceneOperation = SceneOperation.UnloadAdditive, customHandling = true }); 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); NetworkServer.RemovePlayerForConnection(conn, false);