-
Notifications
You must be signed in to change notification settings - Fork 1
Utilities
Namespace: WIDVE.Utilities
Location: WIDVE Unity Scripts/Utilities
The Utilities namespace contains scripts that don't fit into any other specific category. Many of these scripts or components are used by scripts in other namespaces.
The Interpolator
is a component that provides a simple inspector interface to control other components. It features a slider that is passed through an easing function to give a value between 0
and 1
. It also features a list of GameObjects
that it affects. Any components on these objects that implement the IInterpolatable
interface will be notified that the Interpolator's
value has changed and will update accordingly. The slider value can be controlled in the inspector as well as through code and coroutines, described below.
Property | Description |
---|---|
Smoothing |
An AnimationCurve that should return a value between 0 and 1 . Serves as an easing function for the raw slider value. |
RawValue |
The raw slider value, without any easing. |
Value |
The current value of the Interpolator . Returns RawValue passed through the Smoothing curve, clamped between 0 and 1 . |
Function | Description |
---|---|
SetRawValue(float rawValue) |
Sets RawValue to the given value. Has the same effect as moving the slider in the inspector. Calling this function will update any components controlled by the Interpolator . |
LerpOverTime(float start, float end, float time) |
Starts a coroutine to interpolate RawValue from the start to the end value over the given time . |
LerpOverTime(float value, float time) |
Starts a coroutine to interpolate RawValue from the current value to the given value over the given time . |
LerpTo0(float time) |
Starts a coroutine to interpolate RawValue from 1 to 0 over the given time . |
LerpTo1(float time) |
Starts a coroutine to interpolate RawValue from 0 to 1 over the given time . |
StopLerp() |
Stops any ongoing lerp coroutines. |
The Interpolator
also offers two events that are invoked whenever the slider value is changed. Scripts that wish to be notified of the new slider value should subscribe to these events.
Event | Type | Description |
---|---|---|
RawValueChanged |
float |
Invoked whenever the slider value has changed. Includes the new RawValue as an argument. |
ValueChanged |
float |
Invoked whenever the slider value has changed. Includes the new Value as an argument. |
This is a simple script designed for use with UnityEvents
. It provides an interface so that an Interpolator's
lerp methods can be called from a UnityEvent
with customizable time values. It also provides a Vector3
envelope that can perform a more complicated interpolation sequence when the PlayEnvelope()
function is called.
Property | Description |
---|---|
Envelope.x |
The Attack value of the envelope. The Interpolator will lerp from 0 to 1 using this time value. |
Envelope.y |
The Hold value of the envelope. The Interplator will stay at a value of 1 for this amount of time. |
Envelope.z |
The Release value of the envelope. The Interpolator will lerp from 1 to 0 using this time value. |
The IInterpolatable
interface must be used by any component able to be controlled by an Interpolator
.
Property/Function | Description |
---|---|
Enabled |
Returns whether this script is enabled. For components, should simply return the current enabled value. |
FunctionWhenDisabled |
If true , the script will respond to changes in Interpolator value even when Enabled is false . |
SetValue(float value) |
This function is called by the Interpolator whenever its value changes. It should contain logic that updates the interpolatable component to use the new value. |