KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
63 stars 8 forks source link

Mixer Threshold Validation - Annoying #343

Closed wrymn closed 6 days ago

wrymn commented 3 months ago

When changing threshold value in mixer, in the picture bellow, I wanted to type from 1 to 0.3, it always breaks focus and throws this error icon image

so as soon as I type first letter, 0, it breaks input focus and then I continue type into nothing image

and I just wanted to type valid value, 0.3 for example.

image

This is super annoying and should be removed. Warning icon can be kept, but the validation of losing focus needs to be removed.

KybernetikGames commented 3 months ago

That's a weird one. Easy fix, but not quite how I expected it to work and I'm only seeing it in Unity 2021 (not 2022).

Open LinearMixerTransitionAsset.cs and add in this line in DoThresholdGUI at line 208:

if (index > 0)
{
    // Stuff.

    GUIUtility.GetControlID(FocusType.Passive);// Add this.
}

base.DoThresholdGUI(area, index);

I would have expected it to need to be in an else after the block where the error icon's GUI.Button is drawn because it's the presence or absence of the button that's allocating an extra control ID or not and therefore changing the ID of the number field which is what it uses to track the fact that it's the field you're currently editing. But putting it in an else doesn't fix the issue and this does so I'm not sure what's going on (or why Unity 2022 doesn't have the same issue).

wrymn commented 3 months ago

That's a weird one. Easy fix, but not quite how I expected it to work and I'm only seeing it in Unity 2021 (not 2022).

Open LinearMixerTransitionAsset.cs and add in this line in DoThresholdGUI at line 208:

if (index > 0)
{
    // Stuff.

    GUIUtility.GetControlID(FocusType.Passive);// Add this.
}

base.DoThresholdGUI(area, index);

I would have expected it to need to be in an else after the block where the error icon's GUI.Button is drawn because it's the presence or absence of the button that's allocating an extra control ID or not and therefore changing the ID of the number field which is what it uses to track the fact that it's the field you're currently editing. But putting it in an else doesn't fix the issue and this does so I'm not sure what's going on (or why Unity 2022 doesn't have the same issue).

I have added the check, but the issue still persists. I'm on Unity 2023.2.18

image
KybernetikGames commented 3 months ago

Not sure why 2023 is any different because all the internal stuff looks the same.

Replace the whole method with this:

protected override void DoThresholdGUI(Rect area, int index)
{
    var color = GUI.color;

    var iconArea = default(Rect);

    if (index > 0)
    {
        var previousThreshold = CurrentThresholds.GetArrayElementAtIndex(index - 1);
        var currentThreshold = CurrentThresholds.GetArrayElementAtIndex(index);
        if (previousThreshold.floatValue >= currentThreshold.floatValue)
        {
            iconArea = AnimancerGUI.StealFromRight(
                ref area,
                area.height,
                AnimancerGUI.StandardSpacing);

            GUI.color = AnimancerGUI.ErrorFieldColor;
        }
    }

    base.DoThresholdGUI(area, index);

    if (iconArea != default)
    {
        _SortingErrorContent ??= new(AnimancerIcons.Error)
        {
            tooltip =
                "Linear Mixer Thresholds must always be unique" +
                " and sorted in ascending order (click to sort)"
        };

        _SortingErrorStyle ??= new(GUI.skin.label)
        {
            padding = new(),
        };

        if (GUI.Button(iconArea, _SortingErrorContent, _SortingErrorStyle))
        {
            AnimancerGUI.Deselect();
            Serialization.RecordUndo(Context.Property);
            ((LinearMixerTransition)Context.Transition).SortByThresholds();
        }
    }

    GUI.color = color;
}

That fixes it properly by drawing the button after the text field so the button can't interfere with the text.

wrymn commented 3 months ago

Not sure why 2023 is any different because all the internal stuff looks the same.

Replace the whole method with this:

protected override void DoThresholdGUI(Rect area, int index)
{
    var color = GUI.color;

    var iconArea = default(Rect);

    if (index > 0)
    {
        var previousThreshold = CurrentThresholds.GetArrayElementAtIndex(index - 1);
        var currentThreshold = CurrentThresholds.GetArrayElementAtIndex(index);
        if (previousThreshold.floatValue >= currentThreshold.floatValue)
        {
            iconArea = AnimancerGUI.StealFromRight(
                ref area,
                area.height,
                AnimancerGUI.StandardSpacing);

            GUI.color = AnimancerGUI.ErrorFieldColor;
        }
    }

    base.DoThresholdGUI(area, index);

    if (iconArea != default)
    {
        _SortingErrorContent ??= new(AnimancerIcons.Error)
        {
            tooltip =
                "Linear Mixer Thresholds must always be unique" +
                " and sorted in ascending order (click to sort)"
        };

        _SortingErrorStyle ??= new(GUI.skin.label)
        {
            padding = new(),
        };

        if (GUI.Button(iconArea, _SortingErrorContent, _SortingErrorStyle))
        {
            AnimancerGUI.Deselect();
            Serialization.RecordUndo(Context.Property);
            ((LinearMixerTransition)Context.Transition).SortByThresholds();
        }
    }

    GUI.color = color;
}

That fixes it properly by drawing the button after the text field so the button can't interfere with the text.

This is working indeed, thank you!

KybernetikGames commented 3 months ago

I'll leave this one open so people can see it until Animancer v8.0 releases with the fix.

KybernetikGames commented 1 month ago

Animancer v8.0 is now available for Alpha Testing and includes this fix..

KybernetikGames commented 6 days ago

Animancer v8.0 is now fully released.