The FadeUIElement class manages the fading in and out of a VisualElement.

Info: When fading a UIView, always use the public Fade variable provided by the UIView to ensure UI Actions work correctly. Typically, you should use this Fade rather than creating a custom instance.

Only create a custom Fade instance if you need to fade a VisualElement independently of UIView.

Constructor

csharp
public FadeUIElement( MonoBehaviour coroutineRunner, VisualElement visualElement, EasingMode easingMode = EasingMode.EaseOutCirc, bool debug = false)
NameTypeDescription
coroutineRunnerMonoBehaviourMonoBehaviour that handles running coroutines.
visualElementVisualElementThe VisualElement to be faded.
easingModeEasingModeDefines the easing effect applied during fade transitions.
debugboolLogs fade transitions.

Public Properties

PropertyTypeDescription
IsFadingInboolReturns true if a fade-in transition is currently active.
IsFadingOutboolReturns true if a fade-out transition is currently active.
IsFadingboolReturns true if any fade transition is currently active (either in or out).

State Tracking Example

csharp
// Check if element is currently animating if (myFade.IsFading) { Debug.Log("Fade in progress, please wait..."); return; } // Check specific direction if (myFade.IsFadingIn) { // Currently fading in } else if (myFade.IsFadingOut) { // Currently fading out }

Events

EventDescription
OnFadeInStartFired when a fade-in transition begins.
OnFadeInFired when a fade-in transition completes.
OnFadeOutStartFired when a fade-out transition begins.
OnFadeOutFired when a fade-out transition completes.
csharp
// Subscribe to fade events myFade.OnFadeInStart += () => Debug.Log("Starting fade in"); myFade.OnFadeIn += () => Debug.Log("Fade in complete"); myFade.OnFadeOutStart += () => Debug.Log("Starting fade out"); myFade.OnFadeOut += () => Debug.Log("Fade out complete");

Public Methods

FadeIn

Fades the element to full opacity.

csharp
public void FadeIn()

FadeOut

Fades the element to zero opacity.

csharp
public void FadeOut()

SetDuration

Sets the duration of fade transitions in seconds.

csharp
public void SetDuration(float seconds)

GetDuration

Returns the predefined duration of fade transitions. Note that it does not reflect the current active transition duration.

csharp
public float GetDuration()

SetEasing

Sets the easing function for fade transitions.

csharp
public void SetEasing(EasingMode easingMode)

SetFadeInDelay / SetFadeOutDelay

Sets a delay before the fade transition begins.

csharp
public void SetFadeInDelay(float seconds) public void SetFadeOutDelay(float seconds)

Stop

Stops the current fade transition immediately.

csharp
public void Stop()

Example Usage

csharp
// Create a fade controller for a panel var fadeController = new FadeUIElement(this, myPanel); fadeController.SetDuration(0.3f); fadeController.SetEasing(EasingMode.EaseOutBack); // Add delay before fade out fadeController.SetFadeOutDelay(0.5f); // Subscribe to completion fadeController.OnFadeOut += () => { Debug.Log("Panel hidden"); }; // Trigger fade out fadeController.FadeOut();

Settings

Theme

Light

Contrast

Material

Dark

Dim

Material Dark

System

Sidebar(Light & Contrast only)

Light
Dark

Font Family

DM Sans

Wix

Inclusive Sans

AR One Sans

Direction

LTR
RTL