Skip to main content

AnalyticalButton

A class in Root.Township, the global namespace.

A button pressed by the local player's fingertips, worked out geometrically each frame instead of with physics. Client side.

Constructors​

MemberWhat it is
AnalyticalButton()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

39 private and internal fields
MemberWhat it is
private static readonly int _ColorShader ID of _Color.
private static HashSet<AnalyticalButton> activeButtonsEvery button being updated for fingertip presses.
private static List<AnalyticalButton> activeButtonsCacheScratch copy of activeButtons used while iterating.
private Color activeColorColour when usable, if colour changing is on.
private Material activeMaterialMaterial when usable, if colour changing is off.
private Renderer androidButtonRendererSecond button renderer kept out of atlasing; kept from an older field name.
private Collider buttonColliderCollider that moves as the button is pushed and is tested against the fingertips. Backing field for ButtonCollider.
private Renderer buttonRendererRenderer whose colour or material shows whether the button is usable. Backing field for ButtonRenderer.
private Timeline.IEntry delayScheduled call that ends the enable delay.
private float enableDelaySeconds after enabling before the button can be pressed.
private Vector.Axis freeAxisLocal axis the button collider slides along when pushed.
private bool hasDelayedOnceSet after the first enable delay, for isEnableDelayOnlyOnTheFirstTime.
private Color inActiveColorColour when not usable, if colour changing is on.
private Material inactiveMaterialMaterial when not usable, if colour changing is off.
private bool isActiveAtAllScalesLets the button fire even when its world scale is 0.9 or less; otherwise small (shrunk) buttons don't fire.
private bool isChangingColorOnEnableShows usable state by colour; when off, by swapping materials.
private bool isDelayingTrue while waiting out the enable delay.
private bool isEnabledWhether the button can be used. Backing field for IsEnabled.
private bool isEnableDelayOnlyOnTheFirstTimeOnly applies the enable delay the first time the button is enabled.
private bool isFreeSet once no fingertip overlaps the button after enabling, so a finger already inside can't press it.
private bool isIgnoringDelayStops OnEnable from restarting the delay while the button enables itself.
private bool isPhysicallyPressedWhether the button is pushed past the press threshold and not yet back past release.
private bool isPlayingDefaultSoundsPlays the default button sounds when no custom sound is set.
private bool isPlayingSoundsWhether pressing and releasing play sounds.
private WorldSpaceTriangle lastLeftTriangleFingertip triangle of the left hand from the last update.
private WorldSpaceTriangle lastRightTriangleFingertip triangle of the right hand from the last update.
private float maxDepthCollider position along the free axis when the button is fully out.
private float minDepthCollider position along the free axis when the button is fully pushed in.
private AltaEvent onBecameActiveEvent raised when the button finishes its enable animation.
private static Action onFinishedFrameOne-shot callback run after all buttons update in a frame; nothing sets it in this build.
private AltaEvent pressedEvent raised on press; exposed as Pressed.
private SoundEffectSet pressedSoundCustom sound for pressing.
private float pressSpeedNot used in this build.
private float pressThresholdHow far pushed (0 to 1) the button must be to count as pressed.
private MaterialPropertyBlock propertyBlockProperty block used to set the button colour.
private AltaEvent releasedEvent raised on release; exposed as Released.
private SoundEffectSet releasedSoundCustom sound for releasing.
private float releaseThresholdPushed amount (0 to 1) below which a pressed button releases.
private static IUnityUpdateMethod updateButtonsHandle of the shared UpdateButtons late update; removed when no buttons are tracked.

Properties​

MemberWhat it is
Collider ButtonCollider { get; }The moving part of the button, pushed in by the fingers.
Renderer ButtonRenderer { get; }Renderer recoloured or re-materialed when enabled or disabled.
static bool HoldButtonPresses { get; set; }Static: while true every button stays up and shows as inactive.
bool IsEnabled { get; set; }Whether it can be pressed. Setting it updates the collider, visuals and position.
bool State { get; private set; }True while pressed.

Events​

MemberWhat it is
event Action PressedFired when pushed in.
event Action ReleasedFired when let out.

Methods​

MemberWhat it is
void SetStateInternal(bool state)Sets State directly without firing events.
19 private and internal methods
MemberWhat it is
private IEnumerator ButtonEnableAnimation() (iterator)Coroutine after the enable delay: slides the button out to its rest depth, raises onBecameActive and starts tracking it.
private void ChangeVisuals(bool isActive)Shows the button as usable or not, by colour through a property block or by swapping materials.
private static bool CheckIntersection(WorldSpaceTriangle triangle, Matrix4x4 matrix, Bounds bounds)Tests whether a fingertip triangle overlaps the button collider's box, using a separating axis test.
private void EndDelay()Ends the enable delay and plays the enable animation if the button is enabled.
private Vector3 GetClampedVector(Vector3 original, out float progress)Clamps a local position to the button's travel along its free axis and returns how far pressed it is.
private bool Alta.Utilities.Atlas.IPreventAtlasing.IsPreventAtlasing(Renderer renderer)Keeps the button renderers out of texture atlasing so their colour can change.
private void OnDisable()Stops tracking the button.
private void OnDrawGizmos()Empty.
private void OnEnable()Starts the enable delay if one is set, otherwise starts tracking the button for fingertip presses.
private void OnPressed()Sets State, raises Pressed and plays the pressed sound (custom or default).
private void OnReleased()Clears State, raises Released and plays the released sound (custom or default).
private void OnValidate()Keeps minDepth no greater than maxDepth and fills activeMaterial from the renderer.
private Vector3 ProgressVector(float position, out float progress)Like GetClampedVector but from a single depth value along the free axis.
private void StartDelay()Disables the button and schedules EndDelay after enableDelay seconds.
private static bool TestVector(Vector3 vector, WorldSpaceTriangle triangle, Vector3 extents)One separating axis check of a triangle against a box's extents.
private static void UpdateButtons()Late update for all tracked buttons: gets the local player's fingertip triangles and updates each button.
private void UpdateEnableDelay()Older per-frame version of the enable animation. Not called in this build.
private void UpdateUsableStatus()Applies enabled and delay state to visuals, collider and component, and resets the button's depth.
private void UpdateWithTriangle(WorldSpaceTriangle rightTriangle, WorldSpaceTriangle leftTriangle)Moves the button along its axis so the fingertips don't overlap it and fires press or release on the thresholds.

Used in​

Members of other types that take, return or hold a AnalyticalButton: