canto/Assets/Scripts/UI/Effect/AddTransitionEffect.cs
2025-07-18 20:38:44 -04:00

40 lines
1.3 KiB
C#

using System.Collections.Generic;
using System.Threading;
using R3;
using UnityEngine.UIElements;
namespace KitsuneCafe.UI
{
public readonly struct AddTransitionEffect : IUiEffect
{
public readonly StylePropertyName PropertyName;
public readonly TimeValue Duration;
public readonly EasingFunction Easing;
public readonly TimeValue Delay;
public readonly IUiEffect Effect;
public AddTransitionEffect(StylePropertyName name, TimeValue duration, EasingFunction easing, TimeValue delay, IUiEffect effect)
{
PropertyName = name;
Duration = duration;
Easing = easing;
Delay = delay;
Effect = effect;
}
private static StyleList<T> ToStyleList<T>(T value)
{
return new StyleList<T>(new List<T> { value });
}
public Observable<R3.Unit> Execute(VisualElement target, CancellationToken token)
{
target.style.transitionProperty = ToStyleList(PropertyName);
target.style.transitionDuration = ToStyleList(Duration);
target.style.transitionTimingFunction = ToStyleList(Easing);
target.style.transitionDelay = ToStyleList(Delay);
return Effect.Execute(target, token);
}
}
}