Catlike Coding
Unity Code Documentation
Public Member Functions | Public Attributes | Protected Member Functions | Properties | List of all members
CatlikeCoding.Clipping.ClipBox Class Reference

Clipped element that behaves like a clip box. More...

Inherits CatlikeCoding.Clipping.ClippedElement.

Public Member Functions

void ActivateRebound ()
 Activate the rebound animation, if required. More...
 
void SetViewportOffsetFactorClamped (Vector2 offsetFactor)
 Set the viewport offset factor, clamped to the 0-1 tange. More...
 
- Public Member Functions inherited from CatlikeCoding.Clipping.ClippedElement
void InitializeClipHierarchy ()
 Initialize the clip hierarchy. This method is already called at the appropriate places, you typically should have no reason to call it yourself. More...
 
void UpdateClipHierarchy ()
 Update the clip hierarchy if this element's parent changed. Call this method after changing the transform parent of this element, if it was or is now part of a clip hierarchy. More...
 
void UpdateHierarchyBounds ()
 Update the bounds of the entire clip hierarchy that this element is a part of. More...
 

Public Attributes

Vector2 overshootFactor
 Overshoot factor. More...
 
AnimationCurve reboundCurve
 Curve to use for the rebound animation. More...
 
bool useDeltaTime = true
 Whether the rebound animation uses Time.deltaTime. More...
 
- Public Attributes inherited from CatlikeCoding.Clipping.ClippedElement
bool clipsChildren
 Whether the element uses its content bounds to clip its children. More...
 
bool notifiesParent = true
 Whether the element notifies its parent when its bounds have changed. More...
 

Protected Member Functions

override void OnClipBoundsChanged ()
 Called when the clip bounds have changed, because the hierarchy bounds have changed. More...
 
- Protected Member Functions inherited from CatlikeCoding.Clipping.ClippedElement
virtual void OnContentBoundsChanged ()
 Called when the content bounds have changed, by setting ContentBounds. More...
 
virtual void OnDestroy ()
 Called by Unity when the component is destroyed. More...
 
virtual void OnEnable ()
 Called by Unity when the component is enabled. More...
 

Properties

Bounds2D ViewportBounds [get]
 Get the bounds of the viewport. More...
 
ClipBoxEventHandler ViewportChanged
 Occurs after the viewport has changed. When subscribing to this event, you will be called back immediately if the clip box is already in a useful state. More...
 
Vector2 ViewportOffsetFactor [get, set]
 Get or set the offset factor for the viewport. More...
 
Vector2 ViewportSizeFactor [get]
 Get the viewport size factor. This is the size of the viewport divided by the size of the clipped content. More...
 
- Properties inherited from CatlikeCoding.Clipping.ClippedElement
Bounds2D ClipBounds [get]
 Get the clip bounds. More...
 
Bounds2D ContentBounds [get, set]
 Get or set the content bounds. More...
 
Bounds2D ContentBoundsForParent [get]
 Get the content bounds for use by the element's direct parent. More...
 

Additional Inherited Members

- Protected Attributes inherited from CatlikeCoding.Clipping.ClippedElement
Bounds2D clipBounds
 Clip bounds. More...
 
List< ClippedElementclipChildren
 Clip children. More...
 
ClippedElement clipParent
 Clip parent. More...
 
Bounds2D contentBounds
 Content bounds. More...
 

Detailed Description

Clipped element that behaves like a clip box.

Its own content bounds define the position and size of its viewport. This viewport is used to clip and position its first clipped element child, so typically a clip box only has a single child.

The clip box will move its child when its offset factor is changed, and it will also change its offset factor when the child moves for another reason.

Member Function Documentation

void CatlikeCoding.Clipping.ClipBox.ActivateRebound ( )

Activate the rebound animation, if required.

override void CatlikeCoding.Clipping.ClipBox.OnClipBoundsChanged ( )
protectedvirtual

Called when the clip bounds have changed, because the hierarchy bounds have changed.

Does nothing. Override if you need to respond to this change.

Reimplemented from CatlikeCoding.Clipping.ClippedElement.

void CatlikeCoding.Clipping.ClipBox.SetViewportOffsetFactorClamped ( Vector2  offsetFactor)

Set the viewport offset factor, clamped to the 0-1 tange.

This is equivalent to directly setting ViewportOffsetFactor, except that it prevents overshoot. If the overshoot factor is zero, they are identical.

Parameters
offsetFactorViewport offset factor.

Member Data Documentation

Vector2 CatlikeCoding.Clipping.ClipBox.overshootFactor

Overshoot factor.

Used to modify the the offset factor when it goes out of bounds, per dimension. Set to 0 if you want no overshoot. Set to 1 if you want full overshoot. Set it somewhere in between 0 and 1 if you want muted overshoot. Any other value will produce weird results.

AnimationCurve CatlikeCoding.Clipping.ClipBox.reboundCurve

Curve to use for the rebound animation.

The animation moves backwards, it ends at 0 and starts whatever is the rightmost point you defined. The amplitude is used to scale the original overshoot, so should start at 1 and end at 0. Negative amplitudes result in overshoot, which you can use for bouncy animations.

For example, if you want a complete rebound in 0.5 seconds, the curve should have endpoints at (0, 0) and (0.5, 1). The shape of the curve in between those points defines how the transition behaves.

bool CatlikeCoding.Clipping.ClipBox.useDeltaTime = true

Whether the rebound animation uses Time.deltaTime.

Disabling this makes it use Time.realtimeSinceStartup instead. This method can be less precise, but not affected by Time.timeScale.

Property Documentation

Bounds2D CatlikeCoding.Clipping.ClipBox.ViewportBounds
get

Get the bounds of the viewport.

ClipBoxEventHandler CatlikeCoding.Clipping.ClipBox.ViewportChanged
addremove

Occurs after the viewport has changed. When subscribing to this event, you will be called back immediately if the clip box is already in a useful state.

Vector2 CatlikeCoding.Clipping.ClipBox.ViewportOffsetFactor
getset

Get or set the offset factor for the viewport.

A factor of 0 corresponds with the minimum offset, while a factor 1 corresponds to the maximum offset. Think of this as dragging a scrollbar from top to bottom, or from left to right. Note that the factors can go outside of the 0-1 range, though setting is subject to the overshoot factor. Calling ActivateRebound will make the viewport move back within bounds.

Vector2 CatlikeCoding.Clipping.ClipBox.ViewportSizeFactor
get

Get the viewport size factor. This is the size of the viewport divided by the size of the clipped content.