Drag the OnClick events of the buttons if it has multiple events

Hi

In the event that the button has more events, from my experience I think it is more intuitive and logical to be able to drag them by putting them in the order you want.

Eg:

7722283--969199--Immagine 2021-12-09 160330.png

here I initially created a button and added a scene changing event. Then in the course of development I wanted to add more events, so I clicked on the + button, and some empty events were added that I can fill in.
But what if I wanted to sort them out so that Scene.PrivacyPolicy() was the last item down? Currently to do this I have to remove the function from the event above, and put it in the event below, manually (risking also to select the wrong event from the script). Wouldn’t it make more sense if I could drag the event so I could sort it however I want?

Events are never supposed to have order dependencies like this.

I highly recommend you avoid any programming strategy that causes them to have dependency order.

You were right to remember that.

However, the request was not for technical reasons, but for aesthetic reasons.
I didn’t want to order them according to a logic of order, but only because mentally they could be clearer.

A bit like declaring variables, it doesn’t matter which one you declare before or after, but we follow a mental pattern, for example by putting those of the same type next to each other.

1 Like

At the slight risk of starting a massive flamewar (grin), I would submit that the Unity event system widget really isn’t a great place to splatter a bunch of critical logic.

I assert this because to me it lives outside the compiler space, subject to random failure whenever a function gets renamed, etc.

My personal feeling is that it’s way better to put a generic script on the Button and use that to capture a unique intent.

I use this design philosophy in my Datasacks package, where one simply drops a DSUserIntentButton script on the button, name the GameObject of the Button reasonably, and go write a snippet of code to respond to that name. Here’s the code:

https://github.com/kurtdekker/datasacks/blob/master/datasacks/Assets/Datasack/Input/DSUserIntentButton.cs

Note how it finds the Button itself. Now you could howl about how renaming the GameObject name will bust this, but as long as you’re reasonably naming your UI objects, they shouldn’t need renaming at this individual fine button level, unless their function truly changes in any case (like Button_Options becomes Button_Play), in which case the code HAS to change anyway.

And here would be how a MonoBehaviour responds to two buttons called Button_Options and Button_Play to service the user intent, using the above script.

    void    OnUserIntent( Datasack ds)
    {
        switch( ds.Value)
        {
        case "Button_Options":
            ActionButtonOptions();
            break;
        case "Button_Play":
            ActionButtonPlay();
            break;
        }
    }

    void    OnEnable()
    {
        DSM.UserIntent.OnChanged += OnUserIntent;
    }
    void    OnDisable()
    {
        DSM.UserIntent.OnChanged -= OnUserIntent;
    }

As many scripts as you want can hop on and off of that OnChanged delegate.

2 Likes

Maybe I explained myself wrong, but what I meant was just: if you give the possibility to insert more events in the buttons, give the possibility to order them by dragging them.

The ordering in this case is only an aesthetic matter, I am not interested in putting the events in a logical order, as it is not guaranteed by unity (in the button) (Yes, your method would solve this problem)

For the rest, at the moment I have no problems with the references of the buttons, but thanks for explaining your method, in case one day I have problems, I might consider it