Class FrameSwapAnimator
- Namespace
- Fallencake.UI
- Assembly
- Fallencake.UI.dll
Animated frame swapper that cycles through sprites with smooth fading transitions.
public class FrameSwapAnimator : MonoBehaviour
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourFrameSwapAnimator
Properties
BackImage
public Image BackImage { get; }
Property Value
- Image
CrossfadeOverlapDelay
public float CrossfadeOverlapDelay { get; set; }
Property Value
- float
CurrentFrameIndex
public int CurrentFrameIndex { get; }
Property Value
- int
FadeDuration
Auto-calculated fade duration for perfectly balanced ping-pong transitions. Equals FrameSwapTime minus CrossfadeOverlapDelay, ensuring fade in and fade out have identical duration.
public float FadeDuration { get; }
Property Value
- float
FrameCount
public int FrameCount { get; }
Property Value
- int
FrameSwapTime
public float FrameSwapTime { get; set; }
Property Value
- float
FrontImage
public Image FrontImage { get; }
Property Value
- Image
IsAnimating
public bool IsAnimating { get; }
Property Value
- bool
IsPlayOnEnable
public bool IsPlayOnEnable { get; set; }
Property Value
- bool
LoopAnimation
public bool LoopAnimation { get; set; }
Property Value
- bool
Methods
Play()
Starts the frame swap animation with crossfade transitions. Analyzes current image alpha states and starts animation correctly:
- Image with alpha 0 starts fading IN with new frame
- Image with alpha 100% starts fading OUT after delay
public void Play()
Restart()
Restarts the animation from the first frame.
public void Restart()
SetFrame(int)
Sets the current frame without animation.
public void SetFrame(int frameIndex)
Parameters
frameIndexintIndex of the frame to set
Stop()
Stops the animation and ensures proper image state:
- One image MUST have alpha 100% (fully visible)
- Other image MUST have alpha 0% (fully transparent) This guarantees no visual gaps when animation stops.
public void Stop()
ValidateImageStates()
Validates that at least one image is visible and logs warnings if both are transparent. Call this method periodically during animation to catch potential issues.
public void ValidateImageStates()