160 lines
4.3 KiB
C#
160 lines
4.3 KiB
C#
using Edia;
|
|
using UnityEngine;
|
|
using UXF;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using System.Collections.Generic;
|
|
|
|
public class TaskDrawing : XBlock
|
|
{
|
|
[SerializeField] private ObjectVisualizer objectVisualizer;
|
|
[SerializeField] private ScreenInVR messageCanvas;
|
|
[SerializeField] private Button doneButton;
|
|
[SerializeField] private TextMeshProUGUI timerText;
|
|
[SerializeField] private GameObject glassBox;
|
|
[Header("Cheat Controls")]
|
|
[SerializeField] private GameObject cheatPanel;
|
|
[SerializeField] private List<Button> familiarButtons;
|
|
[SerializeField] private List<Button> unfamiliarButtons;
|
|
|
|
private float _timer;
|
|
private bool _isDrawing;
|
|
private bool _currentFamiliarity;
|
|
private int _currentIndex;
|
|
|
|
private void Awake()
|
|
{
|
|
trialSteps.Add(Setup);
|
|
trialSteps.Add(ShowDrawingReference);
|
|
trialSteps.Add(Cleanup);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_isDrawing)
|
|
{
|
|
_timer += Time.deltaTime;
|
|
timerText.text = _timer.ToString("F2");
|
|
}
|
|
}
|
|
|
|
#region TASK STEPS
|
|
|
|
private void Setup()
|
|
{
|
|
doneButton.onClick.AddListener(DrawingDone);
|
|
_timer = 0;
|
|
_isDrawing = false;
|
|
timerText.text = "0.0";
|
|
messageCanvas.Show(true);
|
|
glassBox.SetActive(true);
|
|
|
|
XRManager.Instance.EnableAllInteraction(true);
|
|
|
|
Experiment.Instance.WaitOnProceed();
|
|
Experiment.Instance.Proceed();
|
|
}
|
|
|
|
private void ShowDrawingReference()
|
|
{
|
|
var isFamiliar = Session.instance.CurrentTrial.settings.GetBool("familiar");
|
|
var index = Session.instance.CurrentTrial.settings.GetInt("index");
|
|
objectVisualizer.ShowObjectInTypeAndIndex(isFamiliar, index);
|
|
_currentFamiliarity = isFamiliar;
|
|
_currentIndex = index;
|
|
|
|
_isDrawing = true;
|
|
|
|
Experiment.Instance.WaitOnProceed();
|
|
}
|
|
|
|
private void DrawingDone()
|
|
{
|
|
_isDrawing = false;
|
|
|
|
Experiment.Instance.AddToTrialResults("Index", (_currentFamiliarity ? "Familiar_" : "Unfamiliar_") + _currentIndex);
|
|
Experiment.Instance.AddToTrialResults("DrawingTime", _timer.ToString("F2"));
|
|
|
|
Experiment.Instance.ProceedWithDelay(.1f);
|
|
}
|
|
|
|
private void Cleanup()
|
|
{
|
|
doneButton.onClick.RemoveAllListeners();
|
|
objectVisualizer.HideAllObjects();
|
|
messageCanvas.Show(false);
|
|
glassBox.SetActive(false);
|
|
|
|
Experiment.Instance.WaitOnProceed();
|
|
Experiment.Instance.Proceed();
|
|
}
|
|
|
|
private void ForceChangeDrawingReference(bool isFamiliar, int index)
|
|
{
|
|
objectVisualizer.ShowObjectInTypeAndIndex(isFamiliar, index);
|
|
_currentFamiliarity = isFamiliar;
|
|
_currentIndex = index;
|
|
Experiment.Instance.StoreMarker("Force Change " + (isFamiliar ? "Familiar" : "Unfamiliar") + " " + index);
|
|
}
|
|
|
|
#endregion
|
|
#region STATEMACHINE OVERRIDES
|
|
|
|
public override void OnBlockStart()
|
|
{
|
|
/*
|
|
* Shows message to the user if there is a value defined in the configs with the key "_intro"
|
|
*/
|
|
|
|
Camera.main.clearFlags = CameraClearFlags.SolidColor;
|
|
|
|
cheatPanel.SetActive(true);
|
|
for (int i = 0; i < familiarButtons.Count; i++)
|
|
{
|
|
int index = i; // Capture the current value of i
|
|
familiarButtons[i].onClick.AddListener(() => ForceChangeDrawingReference(true, index));
|
|
}
|
|
for (int i = 0; i < unfamiliarButtons.Count; i++)
|
|
{
|
|
int index = i; // Capture the current value of i
|
|
unfamiliarButtons[i].onClick.AddListener(() => ForceChangeDrawingReference(false, index));
|
|
}
|
|
}
|
|
|
|
public override void OnStartTrial()
|
|
{
|
|
}
|
|
|
|
public override void OnEndTrial()
|
|
{
|
|
}
|
|
|
|
public override void OnBetweenSteps()
|
|
{
|
|
}
|
|
|
|
public override void OnBlockEnd()
|
|
{
|
|
Camera.main.clearFlags = CameraClearFlags.Skybox;
|
|
|
|
foreach (var button in familiarButtons)
|
|
{
|
|
button.onClick.RemoveAllListeners();
|
|
}
|
|
foreach (var button in unfamiliarButtons)
|
|
{
|
|
button.onClick.RemoveAllListeners();
|
|
}
|
|
cheatPanel.SetActive(false);
|
|
}
|
|
|
|
public override void OnBlockOutro()
|
|
{
|
|
/*
|
|
* Shows message to the user if there is a value defined in the configs with the key "_outro"
|
|
*/
|
|
}
|
|
|
|
#endregion
|
|
}
|