UI Actions

UI Actions are a core feature of the UIView system that allow developers to link custom behaviors to the view's visibility transitions (fade in/out). These actions implement the IUIViewAction interface and are executed automatically when the UIView's visibility changes.

Action Lifecycle

  • OnFadeIn: Called when the UIView becomes visible (fades in).

  • OnFadeOut: Called when the UIView becomes hidden (fades out).

This provides a simple, event-driven way to manage UI behavior that needs to sync with the view's state.

Creating Custom Action

using System;
using CupkekGames.UITK;
using UnityEngine;

// Implement IUIViewAction interface
public class UIViewDebugAction : IUIViewAction
{
    private string _message;
    
    public UIViewDebugAction(string message)
    {
        _message = message;
    }

    // This method is called when the UIView fades in (becomes visible).
    public void OnFadeIn()
    {
        Debug.Log("OnFadeIn: " + _message);
    }

    // This method is called when the UIView fades out (becomes invisible).
    public void OnFadeOut()
    {
        Debug.Log("OnFadeOut: " + _message);
    }
}

Adding Action to UIView

UIView.AddAction(new UIViewDebugAction("Hello World!"));

Last updated