Class ScreenFadeBaseBehaviour
Abstract base MonoBehaviour for implementing screen fade-in and fade-out behavior. Provides a common foundation for components that handle visual transition effects. Derive from this class to define custom screen fading logic.
public abstract class ScreenFadeBaseBehaviour : MonoBehaviour
Inheritance
Derived
Examples
Implement a custom fade by subclassing ScreenFadeBaseBehaviour and overriding all four abstract
methods. The parameterless overloads should delegate to the duration overloads so callers can use either
form. Return the actual tween duration so the caller can yield or await for the correct
length. The example below drives a global shader float the same way RendererScreenFadeBehaviour
does, but adds a minimum-duration guard.
using DG.Tweening;
using UnityEngine;
using mobisim.Scenes.Transition;
public class PostProcessScreenFadeBehaviour : ScreenFadeBaseBehaviour
{
private readonly int k_alphaId = Shader.PropertyToID("_FadeAlpha");
private const float MinDuration = 0.1f;
public override float FadeOut() => FadeOut(ScreenTransitionSettings.instance.Duration);
public override float FadeOut(float duration)
{
duration = Mathf.Max(duration, MinDuration);
DOTween.To(() => 0f, v => Shader.SetGlobalFloat(k_alphaId, v), 1f, duration);
return duration;
}
public override float FadeIn() => FadeIn(ScreenTransitionSettings.instance.Duration);
public override float FadeIn(float duration)
{
duration = Mathf.Max(duration, MinDuration);
DOTween.To(() => 1f, v => Shader.SetGlobalFloat(k_alphaId, v), 0f, duration);
return duration;
}
}
Methods
FadeIn()
Starts fading in the screen from black using a default duration.
public abstract float FadeIn()
Returns
float — The duration (in seconds) of the fade in operation.
FadeIn(float)
Starts fading in the screen from black over the specified duration.
public abstract float FadeIn(float duration)
Parameters
| Name | Type | Description |
|---|---|---|
duration | float | The duration (in seconds) to complete the fade in. |
Returns
float — The duration (in seconds) of the fade in operation.