Skip to content

Quiz Button

eisclimber edited this page Feb 11, 2024 · 2 revisions

Quiz Button

class in ExPresSXR.Experimentation / Extends UnityEngine.XR.Interaction.Toolkit.XRBaseInteractable
GameObject instantiable via ExPresSXR/Buttons/...

Description

An expansion of BaseButton representing the Button that is used when answering a TutorialButtonQuiz.

It is able to display answer options in the form of text and GameObject that will hover above the press anchor. In order to display the GameObjects it is advised to create a Prefab. Also move them a bit up on the y-axis and if they should be made interactable add a XRGrabInteractable to it.

Most logic is restricted to non-Toggle-Mode as Toggle-Mode is used when the quiz is in MultipleChoice-Mode. If in MultipleChoice-Mode the button will be automatically set to Toggle-Mode and the feedback is handled via an extra (See McConfirmButton).

When pressed the events OnPressedCorrect and OnPressedIncorrect are invoked to notify if the button was pressed correctly or not.

Members

Editor Properties

  • PutBackSocketInteractor feedbackObjectSocket: Socket to hold an answer object prefab. Adding a XRGrabInteractable-Component to the _answerObject will make it interactable.
    This will instantiate a new GameObject, so prefabs are recommended as normal GameObjects will be duplicated.
  • Text _feedbackTextLabel: Reference to a Text-GameObject that is used to display the answer texts.

Public Properties

  • bool correctChoice: If the question currently displayed is correct.
  • bool feedbackDisabled: If feedback should be given when pressing the button.
  • bool invertedFeedback: If the feedback should be inverted (if feedback is given).
  • string answerText: The string displayed as the answer.
  • GameObject answerObject: The prefab that is attached to the feedbackObjectSocket as answer option.
  • bool _overrideInputDisabledEvents: Used to not emit inputDisabled Events after an answer was given.
  • AudioClip answeredCorrectSound: Sound played when the button pressed with a correct answer.
  • AudioClip answeredIncorrectSound: Sound played when the button pressed with an incorrect answer.
  • AudioSource _answerFeedbackAudioPlayer: Audio Source used to play answeredCorrectSound and answeredCorrectSound. This prevents interferences with pressed/released sounds when answering.

Public Methods

  • void RestartTriggerTimer(): Resets the timer measuring the time until the button was pressed to give an answer. Will be automatically called when displaying a new answer (DisplayAnswer() is called).
  • float GetTriggerTimerValue(): The time in milliseconds since the last reset of the trigger timer.
  • void DisplayAnswer(string answerText, GameObject answerObject, bool correctChoice): Displays a new question using the given parameters and resets the trigger timer.
  • void ClearAnswer(): Removes the text and GameObject from the button and moves the button back in up position.
  • bool GiveMultipleChoiceFeedback(): Used check if the button was correctly toggled when the quiz is in MultipleChoice-Mode. This only is when the button is in ToggleMode, if not false will be returned.

Public Methods

  • void NotifyChoice(): Invokes the events to notify about an answer given. Can be overwritten is the feedback should be gathered differently, a call to base.NotifyChoice() is not necessary.
  • DisplayAnswer(string answerText, GameObject answerObject, bool correctChoice): Displays an answer using the provided information and removes the old one.
    If no information is provided will disable the button. This may only happen during differing-answers-multiple-choice-quizzes.
  • virtual void NotifyChoice(): Emits events based on the feedback type to notify the user if the answer was correct.
  • bool GiveMultipleChoiceFeedback(): Used to find out if the button was toggled correct for a multiple choice quiz.
  • void PlayAnsweredCorrectSound(): Plays the answeredCorrectSound, if assigned.
  • void PlayAnsweredIncorrectSound(): Plays the answeredIncorrectSound, if assigned.

Events

  • OnPressedCorrect: Invoked via NotifyChoice() when the button was pressed (in non-ToggleMode) and the answer was correct.
  • OnPressedIncorrect: Invoked via NotifyChoice() when the button was pressed (in non-ToggleMode) and the answer was not correct.

Inherited Members

Protected Methods

  • void Start(): Connects additional events.
  • void InternalEmitInputDisabledEvents(): Calls the base function only if not disabled via _overrideInputDisabledEvents.

ExPresS XR Wiki

Tutorial Pages

Code Documentation

Clone this wiki locally