using NextMind.Calibration;
using NextMind.Examples.Steps;
using NextMind.Devices;
using UnityEngine;
using UnityEngine.UI;
namespace NextMind.Examples.Calibration
{
///
/// Implementation of an managed by the .
/// During this step, the calibration results are shown to the user. It is managing the loading, and eventually the error messages.
///
public class ResultStep : AbstractStep
{
[SerializeField]
private Text score = null;
[SerializeField]
protected GameObject nextButton = null;
[SerializeField]
protected GameObject backButton = null;
///
/// Array of the grade disks.
///
[SerializeField]
private Image[] gradeImage = null;
///
/// Array of the mentions.
///
[SerializeField,TextArea]
private string[] gradeMention = null;
public override void OnEnterStep()
{
// Force button being in a close state.
Animator animator = backButton.GetComponent();
animator.SetBool("IsOpened", false);
animator.Play("Close", 0, 1);
// Set the grade images to the default size and color.
for (int i = 0; i < gradeImage.Length; i++)
{
SetGrade(i, 0.25f, Vector3.one);
}
Device connectedDevice = NeuroManager.Instance.ConnectedDevices[0];
DisplayResults(connectedDevice.GetCalibrationResults().Grade);
}
public override void OnExitStep()
{
backButton.GetComponent().SetBool("IsOpened", false);
}
private void DisplayResults(CalibrationResults.CalibrationGrade grade)
{
// Display the score of the calibration.
score.text = gradeMention[(int)grade];
SetGrade((int)grade, 1, 1.2f * Vector3.one);
}
private void SetGrade(int index, float alpha, Vector3 localScale)
{
Image image = gradeImage[index];
Color newColor = image.color;
newColor.a = alpha;
image.color = newColor;
image.transform.localScale = localScale;
}
///
/// The back button displays a confirmation message on the first click.
/// Manage this behaviour and return to the beginning when a second clic happen.
///
public void OnClickOnBackButton()
{
bool opened = backButton.GetComponent().GetBool("IsOpened");
if (opened)
{
stepsManager.GoToStep(4);
}
else
{
backButton.GetComponent().SetBool("IsOpened",true);
}
}
}
}