-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeVisualizer.cs
More file actions
131 lines (111 loc) · 3.9 KB
/
TimeVisualizer.cs
File metadata and controls
131 lines (111 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Slider))]
public class TimeVisualizer : MonoBehaviour
{
public ExperimentState expState;
public Image timerSliderImage;
public float BetweenTrialTime = 3.5f;
private AudioSource buttonClickSound;
private float startTime = 0f;
private float startTime2 = 0f;
private float startTime3 = 0f;
private Slider timerSlider;
private Color sliderInitColor;
private Coroutine sliderTimerRoutine;
private Coroutine nextTrialRoutine;
private void Start()
{
buttonClickSound = GameObject.FindGameObjectWithTag("ButtonClick").GetComponent<AudioSource>();
timerSlider = GetComponent<Slider>();
sliderInitColor = timerSliderImage.color;
}
private void Update()
{
if (expState.pause)
{
expState.ResetTrial();
if (sliderTimerRoutine != null)
{
StopCoroutine(sliderTimerRoutine);
}
if (nextTrialRoutine != null)
{
StopCoroutine(nextTrialRoutine);
}
}
// When tutorial is over then start the init experiment sequence
if (expState.startExperiment == 1)
{
startTime3 = Time.time;
StartCoroutine(InitExperimentCountDown());
expState.startExperiment = 0;
}
if (expState.startTrial[2] == 1)
{
timerSliderImage.color = sliderInitColor;
startTime = Time.time;
sliderTimerRoutine = StartCoroutine(SliderCounter());
expState.startTrial[2] = 0;
}
}
public IEnumerator SliderCounter()
{
while (Time.time - startTime < expState.trialDuration)
{
//Debug.Log("Time: " + (Time.time - startTime).ToString("F2"));
float progressTime = Mathf.Clamp01((Time.time - startTime) / expState.trialDuration);
timerSlider.value = 1f - progressTime;
timerSliderImage.color = new Color(1f, 1f - progressTime, 0f, 0.15f);
yield return null;
}
expState.inTrial = false;
startTime2 = Time.time;
nextTrialRoutine = StartCoroutine(NextTrialCountDown());
}
public IEnumerator NextTrialCountDown()
{
while (Time.time - startTime2 < BetweenTrialTime) // & expState.inTrial
{
//Debug.Log("Time: " + (Time.time - startTime2).ToString("F2"));
float progressTime = Mathf.Clamp01((Time.time - startTime2) / BetweenTrialTime);
timerSlider.value = 1f - progressTime;
timerSliderImage.color = new Color(1f, 1f - progressTime, 0f, 0.15f);
yield return null;
}
//if (!expState.pause)
//{
for (int i = 0; i < expState.startTrial.Length; i++)
{
expState.startTrial[i] = 1;
}
buttonClickSound.Play();
//}
}
public IEnumerator InitExperimentCountDown()
{
while (Time.time - startTime3 < expState.initDelay) // & expState.inTrial
{
//Debug.Log("Time: " + (Time.time - startTime2).ToString("F2"));
float progressTime = Mathf.Clamp01((Time.time - startTime3) / expState.initDelay);
timerSlider.value = 1f - progressTime;
timerSliderImage.color = new Color(1f, 1f - progressTime, 0f, 0.15f);
yield return null;
}
//if (!expState.pause)
//{
for (int i = 0; i < expState.startTrial.Length; i++)
{
expState.startTrial[i] = 1;
}
buttonClickSound.Play();
//}
}
}
//if (expState.startTrial[3] == 1)
//{
// startTime2 = Time.time;
// StartCoroutine(NextTrialCountDown());
// expState.startTrial[3] = 0;
//}