Skip to content

Quiz Button

eisclimber edited this page Jan 18, 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

  • 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 answerPrefab: The prefab that is attached to the feedbackObjectSocket as answer option.
  • PutBackSocketInteractor feedbackObjectSocket: Socket to hold an answer object prefab. Only if the prefab has a XRGrabInteractable-Component it can be interacted with. This will instantiate a new GameObject, so prefabs are recommended as normal GameObjects will be duplicated.

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.

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.

ExPresS XR Wiki

Tutorial Pages

Code Documentation

Clone this wiki locally