Skip to content

Commit 890bebc

Browse files
committed
Fixed way more issues with TestExperiment.cs
1 parent 022955e commit 890bebc

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

Example/Scripts/TestExperiment.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
//PsyForge is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
88
//You should have received a copy of the GNU General Public License along with PsyForge. If not, see <https://www.gnu.org/licenses/>.
99

10+
using System;
1011
using System.Threading;
1112
using System.Threading.Tasks;
13+
using System.Collections.Generic;
1214
using UnityEngine;
1315

16+
using PsyForge;
1417
using PsyForge.Experiment;
1518
using PsyForge.Localization;
16-
using System.Collections.Generic;
17-
using Codice.CM.Common;
19+
using PsyForge.Utilities;
1820

1921
public class TestExperiment : ExperimentBase<TestExperiment, TestSession, TestTrial, TestConstants> {
2022
protected override void AwakeOverride() { }
@@ -36,14 +38,13 @@ protected override async Awaitable InitialStates() {
3638
protected override async Awaitable TrialStates(CancellationToken ct) {
3739
await StartTrial();
3840
await SoundPhase();
39-
await KeySelectionPhase();
40-
await DisplayChoicePhase();
41+
await KeySelectionPhase(ct);
4142
}
4243

4344
// Show a starting message and wait for a key press to begin.
4445
protected virtual async Awaitable StartSession() {
4546
// This automatically puts a "Press Any Key to Continue" message at the bottom.
46-
await ExpHelpers.PressAnyKey("session start", LangStrings.SessionStart(), ct);
47+
await ExpHelpers.PressAnyKey("session start", LangStrings.SessionStart());
4748
}
4849

4950
// End the session if we have completed enough trials.
@@ -62,7 +63,7 @@ protected virtual void HowToThrowError() {
6263
throw new Exception("This is an error!");
6364
}
6465

65-
protected virtual async Awaitable KeySelectionPhase() {
66+
protected virtual async Awaitable KeySelectionPhase(CancellationToken ct) {
6667
textDisplayer.Display("Press 1 or 2", text: LangStrings.Press1or2());
6768
var keyOptions = new List<KeyCode>() { KeyCode.Alpha1, KeyCode.Alpha2 };
6869
var selectedKey = await inputManager.WaitForKey(keyOptions, ct: ct);
@@ -71,17 +72,15 @@ protected virtual async Awaitable KeySelectionPhase() {
7172
{ "selectedKey", selectedKey },
7273
});
7374
textDisplayer.Clear();
74-
}
7575

76-
// Display Choice Phase
77-
protected virtual async Awaitable DisplayChoicePhase() {
7876
textDisplayer.Display("You pressed: " + selectedKey, text: LangStrings.YouPressed(selectedKey));
79-
await Timing.Delay(CONSTANTS.keycodeDisplayDurationMs, ct);
77+
await Timing.Delay(CONSTANTS.keycodeDisplayDurationMs, ct: ct);
78+
textDisplayer.Clear();
8079
}
8180

8281
protected virtual async Awaitable SoundPhase() {
8382
// Load the clip
84-
audioPath = FileManager.ExpResourcePath(Config.testAudioPath);
83+
var audioPath = FileManager.ExpResourcePath(Config.testAudioPath);
8584
manager.playback.clip = await UnityUtilities.LoadAudioAsync(audioPath);
8685
int durationMs = (int) manager.playback.clip.length*1000;
8786

0 commit comments

Comments
 (0)