Thank you @fffMalzbier , @_Daniel , @SimonDarksideJ and @jcredible for your replies!
I think my explanation about my idea was not clear enough, so let me describe it here again.
Let’s say we have a UI component, like some pull-down menu or popup panel, and we want to toggle its visibility (on/off) by clicking one button. You click the button once to show the component, and click again to hide it.
At the moment we are provided two ways to achieve the function:
- Place two buttons on the top of each other that represent one of on/off states and assign show/hide callbacks to them
- Write a script that toggles the component’s on/off state and assign it to the button.
I briefly described the 1st method in the initial post, but let me do it again here.
We have two buttons, namely ButtonON and ButtonOFF, and another component (to show/hide) namely Target.
In order to implement the above behavior, we need to assign some callbacks to them as following:
ButtonON:
- Target.SetActive(true)
- ButtonON.SetActive(false)
- ButtonOFF.SetActive(true)
ButtonOFF:
- Target.SetActive(false)
- ButtonOFF.SetActive(false)
- ButtonON.SetActive(true)
This is too much work to toggle one component’s visibility, isn’t it?
About the 2nd approach, one could define a function that takes in a component’s name as a string, finds it in the scene and toggles the visibility, or a function that assumes the name or whatever identifier. The problem is that it’s not strongly supported by the editor; for example, the name or whatever identifier would not synchronize with rename/replace operations taken on the Unity editor.
Now if Target had a method ToggleActive(), we only need one button (namely Button) to do the same thing:
Button:
Clearly, it makes connections between components much simpler and easier to follow. Also no extra scripting.
@SimonDarksideJ Yes, I think I will submit this as a feature request, if you think the above explanation is enough to catch their attention, or I would appreciate if you could add something. Thank you again a lot for your support 