Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixer Threshold Validation - Annoying #343

Open
wrymn opened this issue May 3, 2024 · 5 comments
Open

Mixer Threshold Validation - Annoying #343

wrymn opened this issue May 3, 2024 · 5 comments
Labels
Bug Something isn't working Solved A solution is available here (but may not yet be included in the latest release)

Comments

@wrymn
Copy link

wrymn commented May 3, 2024

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.

@wrymn wrymn added the Bug Something isn't working label May 3, 2024
@KybernetikGames
Copy link
Owner

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).

@KybernetikGames KybernetikGames added the Solved A solution is available here (but may not yet be included in the latest release) label May 3, 2024
@wrymn
Copy link
Author

wrymn commented May 3, 2024

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
Copy link
Owner

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
Copy link
Author

wrymn commented May 3, 2024

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!

@wrymn wrymn closed this as completed May 5, 2024
@KybernetikGames
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Solved A solution is available here (but may not yet be included in the latest release)
Projects
None yet
Development

No branches or pull requests

2 participants