-
Notifications
You must be signed in to change notification settings - Fork 1
Buttons
Namespace: WIDVE.Utilities
Location: WIDVE Unity Scripts/Utilities/Buttons
A set of scripts that lets you store buttons and input methods as ScriptableObjects. Many of the other scripts in this package use buttons in this way.
Since buttons are ScriptableObjects, their settings can be edited by clicking on each button in the Project tab. These settings will be shared by any script using that same button object. If you need to use the same input with different settings for different scripts, simply create an additional Button object with the same input.
Individual buttons can be created using the Create/Button/... menu.
A set of the most commonly used buttons can be generated automatically by using the top menu item WIDVE/Generate Mouse and Keyboard Buttons. Buttons can be generated for other platforms as well.
When using a script that needs a Button object, clicking on the small dot next to the button field will bring up a popup menu showing all buttons available in the project. Choose one from here, or drag one in from the Project tab.
The MKBButton class contains a good example of how to create buttons. For mouse and keyboard input, these buttons use Unity's built in input system. Currently, buttons exist for Oculus devices as well.
This is a simple component that invokes a UnityEvent in response to a button press. It requires a ButtonFloat that implements the GetDown method.
All buttons inherit from the Button<T> base class. The generic parameter determines the type of value the button outputs, and must be a value type (bool, int, float, Vector2, etc).
Note: button outputs are not scaled by Time.deltaTime. If deltaTime scaling is desired, this should be done in the script that uses the button.
| Property | Description |
|---|---|
Smoothing |
The smoothing curve influences the final button output based on the raw input value. Both dimensions of the curve should remain in the range [0, 1] |
Multiplier |
The button's output value will be multiplied by this amount. Can be used to quickly invert a button's output |
Active |
When inactive, a button should always return a value of 0 |
The GetSmoothedFloat method serves as a quick way to get a float value modified by the button's current Smoothing and Multiplier values. It does not check if the button is active or inactive.
These methods must be implemented in any custom button classes.
The GetRawValue method uses the input system to get the button's current input value and returns that value in the range [0, 1].
The GetValue method returns the button's current raw output value, adjusted by the current Smoothing, Multiplier, and Active state.
A ButtonFloat is simply a button that returns a float value. It includes a few additional methods that make it useful as a simple on/off button in many cases.
Note: Since some input devices have no simple way of implementing the Get methods, they are virtual, not abstract. If the derived button class does not implement them, they will always return false.
The GetHeld method returns true if the button is currently held down, false otherwise. It will return true on the same frame GetDown returns true, and false on the same frame GetUp returns true.
The GetDown method returns true on the first frame a button is pressed, false otherwise.
The GetUp method returns true on the first frame a button is released, false otherwise.
A ButtonVector2 is a button that returns output along a two-dimensional axis as a Vector2. This is useful for joystick input. Both input axes are evaluated using the same Smoothing and Multiplier values.