- Getting Start
- Project Settings
- Rich Text
- Cocos Creator
- Cry Engine
SDK - Unity
- Insert 3D
- Curved UI
Buttons are the most commonly used extension components in FairyGUI. It is used for multiple purposes, such as RadioButton, Checkbox, List Item, etc. in the traditional UI framework, all of which are buttons in FairyGUI.
There are two ways to create a button component.
Click the main menu “Resources-> New button” and follow the wizard’s prompts step by step to complete.
Create a new component and select Expand to “Button” in the component properties. Then create a controller and click, Select a button template.
In the component editing state, the properties panel of the button component is:
modeThere are three button mode options.
Ordinary buttonUse for click response, stateless.
single buttonThere is a state of being selected. After being clicked, it will be selected, and click again to remain selected. If you want to implement a radio button group, you can bind the “connection” property of multiple radio buttons to the same controller. For details, refer to Controller。
Check buttonThere is a state of being selected. After being clicked, it is selected, and then clicked to become unselected.
soundSet the sound effect when the button is clicked. If all buttons share a sound effect, there is no need to set each button, there is a global setting in the project properties dialog.
volumeSet the playback volume of the button click sound. 0-100。
Press effectThe controller can be used to control the shape of the buttons on different pages at will, but for convenience, several commonly used button pressing effects are built in.
ZoomThe button becomes larger or smaller when pressed. Push-to-zoom is achieved by changing the ScaleX and ScaleY of the button component. Note: After the zoom is set, the axis will be automatically set to (0.5, 0.5) when the button is initialized. (Except for the Unity platform, other platforms may have a set to make the press smaller. When pressed exactly on the edge of the button, there will be a press effect, but the click event is not triggered. The solution is to use a larger press than a smaller press. If you must press it to become smaller, it is recommended that the threshold value is not too large, it can be slightly effective,)
darkenThe button appears dimmed when pressed. Dimming is actually achieved by changing the color of all images in the button component.If you also have separate settings for the color of the image inside the button, this may conflict and cause the color settings to be lost.
buttonThe button controller must be named “button”. If you don’t need the button to have a special effect, then this controller is not necessary.
Description of each page of the button controller:
upNormal state of the button;
downThe state when the normal button is pressed / the state when the radio or multi-select button is selected;
overThe state when the mouse pointer is hovering over the button;
selectedOverThe state of the mouse pointer when the radio button or multi-select button is selected;
disabledState when the button is unavailable;
selectedDisabledThe state of a button when it is unavailable when a radio or multi-select button is selected.
Usually we design a 4-state button, use up / down / over / selectedOver. If it is used on a mobile device, then use up / down. When the button is unavailable, FairyGUI provides a default grayed-out effect. If you don’t want this effect, you should use disabled and selectedDisabled for design.
titleCan be plain text, rich text, labels, buttons.
iconIt can be a loader, or a label or button.
Note: There is not only “title” and “icon” inside the button component, you can place any component, such as placing as many texts, loaders, etc. The “title” and “icon” settings are only used for the button components to be intuitively set when the editor is instantiated.
Select a button component on the stage, and the property panel list on the right appears:
statusThe radio button or multi-select button can set whether the button is selected. Ordinary button properties have no meaning.
titleThe set text will be assigned to the text property of the “title” element inside the button component. If the “title” element does not exist, nothing will happen.
Title when selectedWhen the button is selected, set the text property of the “title” component to the value set here; when the button is not selected, restore the value of the original title property.
Title colorThe default title color is the text color of the “title” element in the button component. After checking, you can modify the text color. If the “title” element does not exist, nothing will happen.
font sizeThe default font size is the font size of the “title” element in the button component. After checking, you can modify the font size. If the “title” element does not exist, nothing will happen.
iconThe set URL will be assigned to the icon attribute of the “icon” element in the button component. If the “icon” element does not exist, nothing will happen.
Icon when selectedWhen the button is selected, the icon attribute of the “icon” element in the button component is set to the value set here; when the button is not selected, the original icon attribute value is restored.
Click soundAfter ticking, you can reset the click sound of the button, which overrides the setting of the button during the design period.
volumeSet the playback volume of the button click sound. 0-100。
connectionThe controller can be linked with buttons. See controller
Set the button’s title or icon. You don’t even need to force the object to be the type of GButton. You can use the interface provided by GObject directly, for example:
If it is a radio or multi-select button, the following method sets whether it is selected:
Normally for a single / multi-select button, the user can switch the state after clicking. If you don’t need this and want to change the state only through the API, then you can:
The global sound of the button is set as follows:
The volume of the button global sound is set as follows:
This setting can only be set before any UI is created. If you want to dynamically control the global sound (including dynamic sound effects) on or off, the Unity platform can use the following methods, other platforms need to consult the functions provided by the engine.
The method of monitoring the click of a common button is: (Note that the click event is not only a button, any touch-enabled components, such as common components, loaders, graphics, etc., and their click event registration method is the same as the button.)
The button can simulate a triggered click:
There are notification events when the radio button and radio button state change: