Class CanvasUpdateRegistry
A place where CanvasElements can register themselves for rebuilding.
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
public class CanvasUpdateRegistry
Constructors
CanvasUpdateRegistry()
Declaration
protected CanvasUpdateRegistry()
Properties
instance
Get the singleton registry instance.
Declaration
public static CanvasUpdateRegistry instance { get; }
Property Value
| Type | Description |
|---|---|
| CanvasUpdateRegistry |
Methods
DisableCanvasElementForRebuild(ICanvasElement)
Disables the given element from both the graphic and the layout rebuild lists.
Declaration
public static void DisableCanvasElementForRebuild(ICanvasElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| ICanvasElement | element | The canvas element to disable for rebuild. |
Remarks
Disables the element so it isn't rebuilt on the next canvas update while still keeping it in the registry. Use this when temporarily hiding or disabling an element without unregistering it (for example, for object pooling).
Examples
Temporarily hide the element while keeping it in the registry so it isn't rebuilt until re-enabled. Use for object pooling or conditional visibility.
void HideTemporarily()
{
gameObject.SetActive(false);
CanvasUpdateRegistry.DisableCanvasElementForRebuild(GetComponent<RectTransform>());
}
IsRebuildingGraphics()
Are graphics currently being rebuild.
Declaration
public static bool IsRebuildingGraphics()
Returns
| Type | Description |
|---|---|
| bool | True if the rebuild loop is CanvasUpdate.PreRender or CanvasUpdate.Render |
IsRebuildingLayout()
Are graphics layouts currently being calculated..
Declaration
public static bool IsRebuildingLayout()
Returns
| Type | Description |
|---|---|
| bool | True if the rebuild loop is CanvasUpdate.Prelayout, CanvasUpdate.Layout or CanvasUpdate.Postlayout |
RegisterCanvasElementForGraphicRebuild(ICanvasElement)
Try and add the given element to the rebuild list. Will not return if successfully added.
Declaration
public static void RegisterCanvasElementForGraphicRebuild(ICanvasElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| ICanvasElement | element | The element that is needing rebuilt. |
RegisterCanvasElementForLayoutRebuild(ICanvasElement)
Try and add the given element to the layout rebuild list. Will not return if successfully added.
Declaration
public static void RegisterCanvasElementForLayoutRebuild(ICanvasElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| ICanvasElement | element | The element that is needing rebuilt. |
TryRegisterCanvasElementForGraphicRebuild(ICanvasElement)
Try and add the given element to the rebuild list.
Declaration
public static bool TryRegisterCanvasElementForGraphicRebuild(ICanvasElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| ICanvasElement | element | The element that is needing rebuilt. |
Returns
| Type | Description |
|---|---|
| bool | True if the element was successfully added to the rebuilt list. False if either already inside a Graphic Update loop OR has already been added to the list. |
TryRegisterCanvasElementForLayoutRebuild(ICanvasElement)
Try and add the given element to the layout rebuild list.
Declaration
public static bool TryRegisterCanvasElementForLayoutRebuild(ICanvasElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| ICanvasElement | element | The element that is needing rebuilt. |
Returns
| Type | Description |
|---|---|
| bool | True if the element was successfully added to the rebuilt list. False if either already inside a Graphic Update loop OR has already been added to the list. |
UnRegisterCanvasElementForRebuild(ICanvasElement)
Removes the given element from both the graphic and the layout rebuild lists.
Declaration
public static void UnRegisterCanvasElementForRebuild(ICanvasElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| ICanvasElement | element | The canvas element to remove from the rebuild lists. |
Remarks
Call this when an ICanvasElement (for example, RectTransform, Graphic) no longer receives layout or graphic rebuild callbacks. The element is removed from the internal queues so it doesn't update on the next canvas update.
Examples
Unregister from canvas rebuild when this component is disabled. The element no longer receives layout or graphic rebuild callbacks.
void OnDisable()
{
CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this);
}