Version: 2017.3

DefaultControls

class in UnityEngine.UI

Switch to Manual

Description

Utility class for creating default implementations of builtin UI controls.

The recommended workflow for using UI controls with the UI system is to create a prefab for each type of control and instantiate those when needed. This way changes can be made to the prefabs which immediately have effect on all used instances.

However, in certain cases there can be reasons to create UI controls entirely from code. The DefaultControls class provide methods to create each of the builtin UI controls. The resulting objects are the same as are obtained from using the corresponding UI menu entries in the GameObject menu in the Editor.

An example use of this is creating menu items for custom new UI controls that mimics the ones that are builtin in Unity. Some such UI controls may contain other UI controls. For example, a scroll view contains scrollbars. By using the DefaultControls methods to create those parts, it is ensured that they are identical in look and setup to the ones provided in the menu items builtin with Unity.

Note that the details of the setup of the UI controls created by the methods in this class may change with later revisions of the UI system. As such, they are not guaranteed to be 100% backwards compatible. It is recommended not to rely on the specific hierarchies of the GameObjects created by these methods, and limit your code to only interface with the root GameObject created by each method.

Static Functions

CreateButtonCreate a button.
CreateDropdownCreate a dropdown.
CreateImageCreate an image.
CreateInputFieldCreate an input field.
CreatePanelCreate a panel.
CreateRawImageCreate a raw image.
CreateScrollbarCreate a scrollbar.
CreateScrollViewCreate a scroll view.
CreateSliderCreate a slider.
CreateTextCreate a text object.
CreateToggleCreate a toggle.