temporarily disable a button

Asked 2 years ago, Updated 2 years ago, 88 views

There are many buttons on the screen, but if you use other buttons during one process,
I thought it might cause freezing and bugs.

Therefore, I would like to make it impossible to touch other buttons during processing.


Setting events to be disabled while processing with false; and so on in their respective buttons is
If there are many buttons, it will take some time, so
Is there any other way to temporarily disable the buttons?

c# unity3d

2022-09-30 19:32

2 Answers

I can't say whether it's the best way to deal with the functionality that the questioner intends, but you can use a message filter to filter messages for the appropriate control.

If you register a class with the IMessageFilter interface on the form, the PreFilterMessage method for this class will be processed before message dispatch, where you can manipulate messages for buttons that you want to stop working.

However, I don't know Unity, so I can't say if I can use this method.Find out about the IMessageFilter interface.

However, judging only by what is written in the question, I think it would be easier to intuitively understand if the button control property is false for a few minutes, the cost of writing the code is not high, and the defects are not mixed up (I don't think it will take that long...).


2022-09-30 19:32

Answer with an example of .

For example, suppose you have a script for Button (ButtonSample.cs).
Suppose you have a separate script (DataManager.cs) to manage your data.

Assume that ButtonSample.cs has a method to perform button processing.

public void execute(object parameter){
    if(DataManager.instance.waitButton)return;
    DataManager.instance.waitButton=true;
    /*
        Buttons here
    */
}

It should be implemented as above.

DataManager.instance.waitButton

The above is managed as a common button flag and
Replace the true at the time.
While this flag is true, all methods with this flag will be inoperable.

If you control and use one flag like this,
I think we can implement what the questioner wants.


Setting events to be disabled while processing with false; and so on in their respective buttons is
If there are many buttons, it will take some time, so
Is there any other way to temporarily disable the buttons?

The idea is to manage all of these parts with one variable, not one button at a time!
*Instead, it is necessary to remove the flag here and there.
 It's not that I can't use callbacks well and put them together...


2022-09-30 19:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.