Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PanelRenderer

Defines a component that connects VisualElement to GameObject.
Read time 10 minutesLast updated 6 days ago

Definition

[HelpURL("ui-systems/panel-renderer-component")][AddComponentMenu("UI Toolkit/Panel Renderer (UI Toolkit)")]public sealed class PanelRenderer : Renderer, IPanelComponent

Remarks

The following example uses the Panel Renderer component to display a runtime UI in a scene:

Examples

using UnityEngine;using UnityEngine.UIElements;public class SimpleRuntimeUI : MonoBehaviour{ Button button; Toggle toggle; int clickCount = 0; int uiVersion = 0; void Awake() { GetComponent<PanelRenderer>().RegisterUIReloadCallback(OnUIReload); } void OnDestroy() { GetComponent<PanelRenderer>().UnregisterUIReloadCallback(OnUIReload); } private void OnUIReload(PanelRenderer panelRenderer, VisualElement root, int version) { // The version number only changes when the UI actually reloads, // so this checks prevents duplicated elements. if (uiVersion == version) return; uiVersion = version; button = new Button() { text = "Click me!" }; root.Add(button); button.RegisterCallback<ClickEvent>(PrintClickMessage); toggle = new Toggle() { text = "Show click count" }; root.Add(toggle); var input = new TextField() { label = "Type something:" }; root.Add(input); input.RegisterCallback<ChangeEvent<string>>(InputMessage); } private void PrintClickMessage(ClickEvent evt) { ++clickCount; Debug.Log($"{"button"} was clicked!" + (toggle.value ? " Count: " + clickCount : "")); } public static void InputMessage(ChangeEvent<string> evt) { Debug.Log($"{evt.newValue} -> {evt.target}"); }}

Properties

Property

Description

panelSettingsSpecifies the PanelSettings instance to connect this PanelRenderer component to.
parentUIIf the GameObject that this PanelRenderer component is attached to has a parent GameObject, and that parent GameObject also has a PanelRenderer component attached to it, this value is set to the parent GameObject's PanelRenderer component automatically.
pivotDefines the pivot point for positioning and transformation, such as rotation and scaling, of the UI Document in world space. The default pivot is the center.
pivotReferenceSizeDefines how the size of the container is calculated for pivot positioning.
positionThe position (relative or absolute) of the root visual element. Relative only applies for nested PanelRenderers.
visualTreeAssetThe VisualTreeAsset automatically loaded into the root visual element.
worldSpaceSizeWhen the _worldSpaceSizeMode is set to WorldSpaceSizeMode.Fixed, this property determines the size of the PanelRenderer in world space.
worldSpaceSizeModeDefines how the size of the root element is calculated for world space.

Methods

Method

Description

RegisterUIReloadCallbackRegisters a callback to be invoked when the UI is reloaded.
UnregisterUIReloadCallbackUnregisters a previously registered UI reload callback.

Delegates

Delegate

Description

PanelRenderer.UIReloadCallbackCallback type for UI reload events.
PanelRenderer.VersionedUIReloadCallbackCallback type for UI reload events.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.