Language
Edit

RectTransformColliderFitter Class

Definition

This script fits a Unity BoxCollider component onto a canvas element.

[UnityEngine.AddComponentMenu("MRTK/UX/Rect Transform Collider Fitter")]
[UnityEngine.ExecuteAlways]
public class RectTransformColliderFitter : UnityEngine.EventSystems.UIBehaviour, UnityEngine.UI.IClippable
[<UnityEngine.AddComponentMenu("MRTK/UX/Rect Transform Collider Fitter")>]
[<UnityEngine.ExecuteAlways>]
type RectTransformColliderFitter = class
    inherit UIBehaviour
    interface IClippable
Public Class RectTransformColliderFitter
Inherits UIBehaviour
Implements IClippable
Inheritance
UnityEngine.EventSystems.UIBehaviour
RectTransformColliderFitter
Attributes
UnityEngine.AddComponentMenuAttribute UnityEngine.ExecuteAlwaysAttribute
Implements
UnityEngine.UI.IClippable

Remarks

This script should be disabled most of the time for performance reasons. By default, for performance, this class will only recomputes the mask intersections and collider bounds when parent dimensions have been updated, the mask has changed, or a parent scroll rectangle has scrolled. If you need more frequent collider updates, you can enable the script.

This script works in both edit and play modes.

Only fits the X and Y axes values will be modified, while the z axis value is preserved.

Constructors

Name Description
RectTransformColliderFitter()

Properties

Name Description
AttachedRectTransform

Get the attached Unity rect transform.

CanToggleCollider

When true, thisCollider will be enabled/disabled based on whether or not the collider is visible.

Padding

Get or set the 2D padding around the rect transform.

ThisCollider

The collider to fit to the AttachedRectTransform.

Methods

Name Description
Awake()

A Unity event function that is called when an enabled script instance is being loaded.

Cull(Rect, Boolean) UnityEngine.UI.IClippable.Cull(UnityEngine.Rect,System.Boolean)
OnDestroy()

A Unity event function that is called when the script component has been destroyed.

OnRectTransformDimensionsChange() UnityEngine.EventSystems.UIBehaviour.OnRectTransformDimensionsChange
OnTransformParentChanged() UnityEngine.EventSystems.UIBehaviour.OnTransformParentChanged
RecalculateClipping() UnityEngine.UI.IClippable.RecalculateClipping
SetClipRect(Rect, Boolean) UnityEngine.UI.IClippable.SetClipRect(UnityEngine.Rect,System.Boolean)
SetClipSoftness(Vector2) UnityEngine.UI.IClippable.SetClipSoftness(UnityEngine.Vector2)
Update()

A Unity event function that is called every frame, if this object is enabled.

Explicit Interface Implementations

Name Description
IClippable.rectTransform

Get the attached Unity rect transform.

Applies to