com.alicizax.unity.ui.exten.../Runtime/UXComponent/Controller/ControllerStateBase.cs
2026-03-04 16:50:30 +08:00

66 lines
1.9 KiB
C#

using System;
using UnityEngine;
namespace AlicizaX.UI
{
/// <summary>
/// Base class for all controller states
/// </summary>
public abstract class ControllerStateBase
{
/// <summary>
/// Initialize the state when added to a recorder
/// </summary>
public abstract void Init(UXControllerStateRecorder recorder);
/// <summary>
/// Execute the state when controller index changes
/// </summary>
/// <param name="recorder">The state recorder</param>
/// <param name="entryIndex">The index this state entry is bound to</param>
/// <param name="selectedIndex">The currently selected controller index</param>
public abstract void Execute(UXControllerStateRecorder recorder, int entryIndex, int selectedIndex);
/// <summary>
/// Validate if the state can be properly executed
/// </summary>
public abstract bool Valid(UXControllerStateRecorder recorder);
/// <summary>
/// Get a human-readable description of this state
/// </summary>
public virtual string GetDescription()
{
return GetType().Name;
}
}
/// <summary>
/// Attribute to define display name for a controller state type
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class ControlerStateNameAttribute : Attribute
{
public string StateName { get; }
public ControlerStateNameAttribute(string stateName)
{
StateName = stateName;
}
}
/// <summary>
/// Attribute to define if a state can be attached multiple times to the same recorder
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class ControlerStateAttachTypeAttribute : Attribute
{
public bool Repeat { get; }
public ControlerStateAttachTypeAttribute(bool repeat)
{
Repeat = repeat;
}
}
}