Preparing search index...

    Represents a Switch component that extends the Slider functionality.

    Toggleable

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    _colliderCenter: vec3 = ...
    _colliderFitElement: boolean = true
    _colliderSize: vec3 = ...
    _currentValue: number = ...
    _defaultValue: number = 0
    _hasError: boolean = false
    _initialized: boolean = false
    _interactableStateMachine: InteractableStateMachine
    _isDragged: boolean = false

    Indicates whether the element is currently being dragged. This property is used to track the drag state of the element.

    _knobSize: vec2 = ...
    _knobVisual: Visual
    _renderOrder: number = 0
    _size: vec3 = ...
    _style: SnapOS2Styles = SnapOS2Styles.Custom
    _trackFillVisual: Visual
    _visual: Visual
    addCallbacks: boolean = false
    api: Record<string, any>

    Generic object accessible by other instances of ScriptComponent. Use this object to store references to properties and methods that need to be accessible from other ScriptComponents.

    colliderObject: SceneObject
    colliderShape: BoxShape
    colliderTransform: Transform
    currentPosition: vec3 = ...
    currentScale: vec3 = ...
    customKnobSize: boolean = false
    enabled: boolean

    If disabled, the Component will stop enacting its behavior.

    hasTrackVisual: boolean = true
    isEnabledInHierarchy: boolean

    Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.

    managedComponents: Set<Component> = ...
    managedSceneObjects: Set<SceneObject> = ...
    name: string
    numberOfSegments: number = 2
    onFinished: PublicApi<boolean> = ...

    Event that is triggered when the toggle finishes its action. The event data represents whether it's an explicit change.

    onHoverEnter: PublicApi<void> = ...

    An event that is triggered when a hover interaction starts on the element.

    onHoverExit: PublicApi<void> = ...

    An event that is triggered when a hover interaction ends on the element.

    onInitialized: PublicApi<void> = ...

    A public API event that is triggered when the element is initialized.

    onKnobMoved: PublicApi<number> = ...
    onStateChanged: PublicApi<StateName> = ...

    An event that is triggered whenever the state of the element changes.

    onStateChangedEvent: ReplayEvent<StateName> = ...
    onTriggerDown: PublicApi<void> = ...

    An event that is triggered when a trigger interaction starts on the element.

    onTriggerUp: PublicApi<void> = ...

    An event that is triggered when a trigger interaction ends on the element.

    onValueChange: PublicApi<number> = ...

    Event that is triggered when the toggle value changes.

    sceneObject: SceneObject

    The SceneObject this component is on.

    segmented: boolean = true
    snapToTriggerPosition: boolean = true
    stateName: StateName = StateName.default
    uniqueIdentifier: string
    updatePriority: number
    visualEventHandlerUnsubscribes: unsubscribe[] = []

    Accessors

    • get collider(): ColliderComponent

      Gets the ColliderComponent instance associated with this element. The collider is used for detecting interactions or collisions with the element.

      Returns ColliderComponent

      The collider instance.

    • get colliderCenter(): vec3

      Gets the custom center position of the collider. This position is only used when colliderFitElement is false.

      Returns vec3

      The custom collider center position in local space coordinates.

    • set colliderCenter(center: vec3): void

      Sets the custom center position of the collider. This position is only applied when colliderFitElement is false.

      Parameters

      • center: vec3

        The custom collider center position in local space coordinates.

      Returns void

    • get colliderFitElement(): boolean

      Gets whether the collider automatically fits the element's size.

      Returns boolean

      True if the collider fits the element, false if using custom size/position.

    • set colliderFitElement(colliderFitElement: boolean): void

      Sets whether the collider should automatically fit the element's size.

      Parameters

      • colliderFitElement: boolean

        True to make the collider fit the element, false to use custom size/position.

      Returns void

    • get colliderSize(): vec3

      Gets the custom size of the collider. This size is only used when colliderFitElement is false.

      Returns vec3

      The custom collider size in local space coordinates.

    • set colliderSize(size: vec3): void

      Sets the custom size of the collider. This size is only applied when colliderFitElement is false.

      Parameters

      • size: vec3

        The custom collider size in local space coordinates.

      Returns void

    • get contentChildren(): SceneObject[]

      Gets the children of the element that are not managed by the element.

      Returns SceneObject[]

      The children of the element that are not managed by the element.

    • get contentChildrenCount(): number

      Gets the number of children of the element that are not managed by the element.

      Returns number

      The number of children of the element that are not managed by the element.

    • get currentValue(): number

      Gets the current value of the slider. This is the actual value of the element, and is updated immediately after user input

      Returns number

      The current value.

    • set currentValue(value: number): void

      Sets the current value of the slider.

      Parameters

      • value: number

        The new value to set, which should be between 0 and 1.

        If the value is outside the range [0, 1], a warning is logged and the value is not set. If the value is the same as the current value, a debug message is logged and the value is not set. Otherwise, the current value is updated, a debug message is logged, the knob position is updated, and the onValueChangeEvent is invoked.

      Returns void

    • get deltaPosition(): vec3

      Returns vec3

    • get deltaScale(): vec3

      Returns vec3

    • get hasShadow(): boolean

      Gets whether the visual element has a shadow.

      Returns boolean

      Whether the visual element has a shadow.

    • set hasShadow(value: boolean): void

      Sets whether the visual element has a shadow. If the hasShadow is set to true, the shadowVisual object will be created and configured.

      Parameters

      • value: boolean

        Whether the visual element has a shadow.

      Returns void

    • get inactive(): boolean

      Returns boolean

      is inactive or not

    • set inactive(inactive: boolean): void

      Parameters

      • inactive: boolean

        set is inactive or is not inactive

      Returns void

    • get initialized(): boolean

      Indicates whether the element has been initialized.

      Returns boolean

      true if the element is initialized, otherwise false.

    • get interactable(): Interactable

      Gets the interactable property of the element.

      Returns Interactable

      The current interactable instance associated with this element.

    • get isDraggable(): boolean

      Gets a value indicating whether the slider component is draggable.

      Returns boolean

      always return true, as it is always draggable.

    • get isExplicit(): boolean

      Returns boolean

    • get isOn(): boolean

      Gets the current state of the switch.

      Returns boolean

      • Returns true if the switch's current state is not set to 0, otherwise false.
    • set isOn(on: boolean): void

      Sets the state of the switch to either "on" or "off".

      Parameters

      • on: boolean

        A boolean value indicating whether the switch should be turned on (true) or off (false).

      Returns void

    • get isToggle(): boolean

      Returns boolean

    • get knobSize(): vec2

      Gets the size of the knob.

      Returns vec2

      The size of the knob.

    • set knobSize(size: vec2): void

      Sets the size of the knob. If the new size is different from the current size, it updates the knob size.

      Parameters

      Returns void

    • get knobSpringConfig(): SpringConfig

      Gets the current spring animation configuration for the knob.

      Returns SpringConfig

      The current spring configuration including stiffness (k), damping, and mass values.

    • set knobSpringConfig(springConfig: SpringConfig): void

      Updates the spring animation configuration for the knob.

      Parameters

      • springConfig: SpringConfig

        The new spring configuration. Only provided properties will be updated.

      Returns void

    • get knobValue(): number

      The current position of the knob as a normalized value from 0-1. This differs from the currentValue, as the currentValue may be set, while the knobValue is animating to that position. If you want the actual value of the element, please use currentValue

      Returns number

      The current value.

    • get knobVisual(): Visual

      Gets the visual representation of the slider's knob.

      Returns Visual

      The visual object representing the knob.

    • set knobVisual(value: Visual): void

      Sets the visual representation of the slider's knob. If a previous visual exists, it will be destroyed before assigning the new one.

      Parameters

      • value: Visual

        The new visual to be assigned to the knob.

      Returns void

    • get playAudio(): boolean

      Gets the value indicating whether audio playback is enabled.

      Returns boolean

      true if audio playback is enabled; otherwise, false.

    • set playAudio(playAudio: boolean): void

      Sets the playAudio behavior and initializes the audio component if necessary.

      Parameters

      • playAudio: boolean

        A boolean indicating whether audio should be played. If set to true and the audio component is not already created, a new audio component will be instantiated and attached to the scene object.

      Returns void

    • get playTriggerDownAudio(): boolean

      Gets the value indicating whether trigger down audio playback is enabled.

      Returns boolean

      true if trigger down audio playback is enabled; otherwise, false.

    • set playTriggerDownAudio(playTriggerDownAudio: boolean): void

      Sets the playTriggerDownAudio behavior and initializes the audio component if necessary.

      Parameters

      • playTriggerDownAudio: boolean

        A boolean indicating whether trigger down audio should be played. If set to true and the audio component is not already created, a new audio component will be instantiated and attached to the scene object.

      Returns void

    • get playTriggerUpAudio(): boolean

      Gets the value indicating whether trigger up audio playback is enabled.

      Returns boolean

      true if trigger up audio playback is enabled; otherwise, false.

    • set playTriggerUpAudio(playTriggerUpAudio: boolean): void

      Sets the playTriggerUpAudio behavior and initializes the audio component if necessary.

      Parameters

      • playTriggerUpAudio: boolean

        A boolean indicating whether trigger up audio should be played. If set to true and the audio component is not already created, a new audio component will be instantiated and attached to the scene object.

      Returns void

    • get renderOrder(): number

      Gets the render order of the Slider.

      Returns number

      The render order of the Slider.

    • set renderOrder(order: number): void

      Sets the render order of the Slider.

      Parameters

      • order: number

        The render order of the Slider.

      Returns void

    • get shadowPositionOffset(): vec3

      Gets the position offset of the shadow.

      Returns vec3

      The position offset of the shadow.

    • set shadowPositionOffset(value: vec3): void

      Sets the position offset of the shadow.

      Parameters

      • value: vec3

        The position offset of the shadow.

      Returns void

    • get shadowVisual(): DropShadowVisual

      Gets the associated DropShadowVisual instance for this component.

      Returns DropShadowVisual

      The DropShadowVisual instance linked to this component, if any.

    • get size(): vec3

      Gets the size of the visual element.

      Returns vec3

      The size of the visual element.

    • set size(size: vec3): void

      Sets the size of the visual element.

      Parameters

      • size: vec3

        A vec3 representing the dimensions of the visual element.

      Returns void

    • get style(): string

      Gets the style of the visual element.

      Returns string

      The style of the visual element.

    • get trackFillVisual(): Visual

      Gets the visual representation of the slider's track fill.

      Returns Visual

      The visual object representing the track fill.

    • set trackFillVisual(value: Visual): void

      Sets the visual representation of the slider's track fill. If a previous visual exists, it will be destroyed before assigning the new one.

      Parameters

      • value: Visual

        The new visual to be assigned to the track fill.

      Returns void

    • get transform(): Transform

      Gets the transform associated with this element.

      Returns Transform

      The transform of the element.

    • get triggerEndAudioTrack(): AudioTrackAsset

      Gets the audio track to be played at the end of a trigger event.

      Returns AudioTrackAsset

      The audio track asset associated with the trigger end event.

    • set triggerEndAudioTrack(audioTrack: AudioTrackAsset): void

      Sets the audio track to be played at the end of a trigger event.

      Parameters

      Returns void

    • get triggerEndAudioVolume(): number

      Gets the volume level for the trigger end audio.

      Returns number

      The volume level for the trigger end audio.

    • set triggerEndAudioVolume(volume: number): void

      Sets the volume level for the trigger end audio.

      Parameters

      • volume: number

        The desired volume level as a number.

      Returns void

    • get triggerStartAudioTrack(): AudioTrackAsset

      Gets the audio track to be played when the trigger starts.

      Returns AudioTrackAsset

      The audio track asset associated with the trigger start event.

    • set triggerStartAudioTrack(audioTrack: AudioTrackAsset): void

      Sets the audio track to be played when the trigger starts.

      Parameters

      Returns void

    • get triggerStartAudioVolume(): number

      Gets the volume level for the trigger start audio.

      Returns number

      The volume level for the trigger start audio.

    • set triggerStartAudioVolume(volume: number): void

      Sets the volume level for the trigger start audio.

      Parameters

      • volume: number

        The desired audio volume level as a number.

      Returns void

    • get typeString(): string

      Gets the type string of the visual element.

      Returns string

      The type string of the visual element.

    • get visual(): Visual

      Gets the associated Visual instance for this component.

      Returns Visual

      The Visual instance linked to this component.

    • set visual(value: Visual): void

      Sets the associated Visual instance for this component.

      Parameters

      • value: Visual

        The Visual instance to assign.

      Returns void

    Methods

    • Destroys the component.

      Returns void

    • Returns the name of this object's type.

      Returns string

    • Returns true if the object matches or derives from the passed in type.

      Parameters

      • type: string

      Returns boolean

    • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

      Parameters

      Returns boolean

    • Plays the specified audio track at the given volume.

      Parameters

      • audioTrack: AudioTrackAsset

        The audio track asset to be played.

      • volume: number

        The volume level at which the audio track should be played.

      Returns void

    • Registers a tooltip instance with the current component

      Parameters

      • tooltip: Tooltip

        The Tooltip instance to associate with this component.

      Returns void

    • Sets the tooltip text for the visual element.

      Parameters

      • text: string

        The text to be displayed in the tooltip.

      Returns void

    • Toggles the switch to the on/off state.

      This method sets the current state of the switch to 1 or 0 and updates the knob position accordingly.

      Parameters

      • on: boolean

        A boolean value indicating the desired toggle state.

      Returns void

    • Updates the current value of the slider with optional animation control.

      Parameters

      • value: number

        The new value to set. Must be between 0 and 1 (inclusive).

      • OptionalshouldAnimate: boolean

        Whether to animate the transition to the new value using spring physics. When true, the knob will spring animate from current to target value. When false (default), the knob jumps immediately to the new value.

      Returns void