[Solved] Color Tint Transition for `Item View Slot` will never fadeout if you use a controller instead of a mouse

Justus

Member
If you use a mouse, when keep in clicking down, the slot will fading in to target `Pressed Color`, once you release mouse button, it will start to fade out.
If you use the UI Submit key of you controller to do same thing, the slot will fading to target `Pressed Color`, and never come back even if you release the controller button.
1651737910865.png
 
You are right, I had never paid attention to that. The ItemViewSlot inherits from an ActionButton class which I made to use instead of the default Unity Button class. The reason we do this is because the Unity Button class is too restrictive.

Unfortunatly the Unity API does not have anything for knowing when the Submit button is no longer pressed within the navigation interfaces. So I took inspiration from the default Unity button for this fade transition. They use a coroutine to fade in->out when submitting.

So in the ActionButton class you can replace/add those functions:
Code:
/// <summary>
///   <para>Registered ISubmitHandler callback.</para>
/// </summary>
/// <param name="eventData">Data passed in (Typically by the event system).</param>
public virtual void OnSubmit(BaseEventData eventData)
{
    Press();
    if (!IsActive() || !IsInteractable()) {
        return;
    }
    DoStateTransition(SelectionState.Pressed, false);
    StartCoroutine(OnFinishSubmit());
}
/// <summary>
/// Coroutine when pressing a submit input to press the Action Button.
/// </summary>
/// <returns></returns>
private IEnumerator OnFinishSubmit()
{
    var fadeTime = colors.fadeDuration;
    var elapsedTime = 0f;
    while (elapsedTime < fadeTime)
    {
        elapsedTime += Time.unscaledDeltaTime;
        yield return null;
    }
    DoStateTransition(currentSelectionState, false);
}

I hope that helps
 
Top