PhysicalButton
A class in Root.Township, the global namespace.
A push button driven by physics: the button part slides along one axis and fires Pressed and Released as it passes set depths. Runs locally on whichever machine simulates it; not networked by itself.
- Listed in Global namespace: P
- Inherits or implements
Interactable,IPreventAtlasing - Attributes
SelectionBase - Documented in Buttons and levers
Constructors
| Member | What it is |
|---|---|
PhysicalButton() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
28 private and internal fields
| Member | What it is |
|---|---|
private static readonly int _Color | Shader property ID for _Color. |
private Color activeColor | Colour when enabled. White by default. |
private Material activeMaterial | Material when enabled, if not changing colour. Defaults to the renderer's material. |
private Renderer androidButtonRenderer | A second button renderer that is also kept out of atlasing. |
private Collider buttonCollider | Backing field for ButtonCollider. |
private Renderer buttonRenderer | Backing field for ButtonRenderer. |
private Rigidbody buttonRigidbody | Rigidbody on the button collider: the part that slides. |
private static SoundEffectSet defaultSoundEffectSet | Cache for DefaultSoundEffectSet. |
private float delayEnable | Seconds after Awake before the button enables. 0.05 by default. |
private Task delayStart | The running DelayStart task. |
private CancellationTokenSource delayToken | Cancels DelayStart if IsEnabled is set or the button is destroyed first. |
private Vector.Axis freeAxis | Local axis the button slides along. Y by default. |
private Color inActiveColor | Colour when disabled. Grey by default. |
private Material inactiveMaterial | Material when disabled, if not changing colour. |
private bool isActiveAtAllScales | If false, presses only count while the button's scale is over 0.9 (so not while shrunk). |
private bool isChangingColorOnEnable | If true, enabling swaps colours. If false, it swaps materials. |
private bool isEnabled | Backing field for IsEnabled. |
private bool isPhysicallyPressed | Whether the button is currently pushed past the press threshold. |
private bool isPlayingSounds | Plays the button sound on press and release. True by default. |
private bool isTestPress | Editor button that fires a press. |
private bool isTestRelease | Editor button that fires a release. |
private float maxDepth | Fully out position along the axis. 0.67 by default. |
private float minDepth | Fully in position along the axis. 0.31 by default. |
private AltaEvent pressed | Backing event for Pressed. |
private float pressThreshold | Progress (0 out, 1 fully in) past which the button presses. 0.8 by default. |
private MaterialPropertyBlock propertyBlock | Property block used to set the colour. |
private AltaEvent released | Backing event for Released. |
private float releaseThreshold | Progress below which the button releases. 0.5 by default. |
Properties
1 private and internal property
| Member | What it is |
|---|---|
private static SoundEffectSet DefaultSoundEffectSet { get; } | The global button pressed sound, resolved once and cached. |
Events
Methods
14 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Finds the button rigidbody, disables the button and starts DelayStart to enable it shortly after. |
private void ChangeVisuals(bool isActive) | Sets the renderer to the active or inactive colour (through a property block) or material. |
private async Task DelayStart() | Waits delayEnable seconds, then enables the button unless cancelled. |
private void FakePress(Interactable interactable = null, Interactor interactor = null) | When a hand starts interacting, pushes the button in to minDepth on local Z and makes it kinematic. |
private void FakeRelease(Interactable interactable = null, Interactor interactor = null) | When the last hand lets go, moves the button partly out and makes it non-kinematic again. |
private Vector3 GetClampedVector(Vector3 original, out float progress) | Clamps a position to the depth range on the free axis (other axes 0) and returns progress, 1 at minDepth. |
private bool Alta.Utilities.Atlas.IPreventAtlasing.IsPreventAtlasing(Renderer renderer) | Keeps the button renderers out of texture atlasing, so their colour or material can change. |
private void LateUpdate() | Clamps the button along its axis and fires press or release as it crosses the thresholds. Skips buttons scaled under 0.9. |
private void OnDestroy() | Cancels a pending DelayStart. |
private void OnDisable() | Unhooks FakePress and FakeRelease. |
private void OnDrawGizmos() | Editor: draws the button's travel line. |
private void OnEnable() | Puts the button at minDepth, hooks FakePress and FakeRelease to interactions and marks it physically pressed. |
private void OnPressed() | Sets State, raises Pressed and plays the button sound if isPlayingSounds. |
private void OnReleased() | Clears State, raises Released and plays the button sound if isPlayingSounds. |
Used in
Members of other types that take, return or hold a PhysicalButton:
AccessibilityFeaturesBoard.acceptButton, AccessibilityFeaturesBoard.closeButton, AccessibilityFeaturesBoard.declineButton, ButtonEnumMenuSetting.next, ButtonEnumMenuSetting.previous, TradeConfiguration.coinDown, TradeConfiguration.coinUp, TradeConfiguration.itemDown, TradeConfiguration.itemUp, RepairBoxDevControlPanel.buildButton, RepairBoxDevControlPanel.destroyButton, ButtonCounter.down, ButtonCounter.up, LabelledButtonWrapper.button, LabelledButtonWrapper.Button, TutorialPromptBoard.joinTutorialButton, TutorialPromptBoard.skipTutorialButton.