Skip to content

Commit 7b1c46b

Browse files
committed
Updates with new settings system
1 parent 9a66298 commit 7b1c46b

14 files changed

+2496
-5759
lines changed

Assets/ExpMngr/Example.unity

Lines changed: 264 additions & 5468 deletions
Large diffs are not rendered by default.

Assets/ExpMngr/ExampleScript.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using UnityEngine;
45
using System.IO;
@@ -16,7 +17,7 @@ public void GenerateAndRunExperiment() {
1617
/// This function can be called using the ExperimentSession inspector OnSessionStart() event, or otherwise
1718

1819

19-
// / In the example_output/experiment_name/ folder we have a settings.json
20+
// / In the StreamingAssets folder we have a several .json files that contain settings, e.g.
2021
// / that looks like this:
2122
//
2223
// {
@@ -35,29 +36,31 @@ public void GenerateAndRunExperiment() {
3536

3637
// practice block
3738
var practiceBlock = new ExpMngr.Block(exp); // block 1
38-
for (int i = 0; i < (long)exp.settings["n_practice_trials"]; i++)
39+
for (int i = 0; i < Convert.ToInt32(exp.settings["n_practice_trials"]); i++)
3940
new ExpMngr.Trial(practiceBlock);
4041
// main block
4142
var mainBlock = new ExpMngr.Block(exp); // block 2
42-
for (int i = 0; i < (long) exp.settings["n_main_trials"]; i++)
43+
for (int i = 0; i < Convert.ToInt32(exp.settings["n_main_trials"]); i++)
4344
new ExpMngr.Trial(mainBlock);
4445

4546

4647
// here we set a setting for the 2nd trial of the main block as an example.
47-
exp.GetBlock(2).GetRelativeTrial(2).settings["size"] = 2;
48+
exp.GetBlock(2).GetRelativeTrial(2).settings["size"] = 10;
4849

49-
// start first trial
50-
RunNextTrial();
50+
// begin first trial
51+
exp.BeginNextTrial();
5152
}
5253

5354
void Update()
5455
{
55-
// here we are mimicking some experiment behaviour
56+
// here we are mimicking some experiment behaviour, e.g waiting for user to interact with scene
5657
if (Time.time > startNextTime && exp.inTrial)
5758
{
58-
exp.currentTrial.End();
59+
Debug.Log("Ending trial");
5960
if (exp.currentTrial == exp.lastTrial)
6061
{
62+
// end, then quit
63+
exp.currentTrial.End();
6164
#if UNITY_EDITOR
6265
UnityEditor.EditorApplication.isPlaying = false;
6366
#elif UNITY_WEBPLAYER
@@ -68,16 +71,19 @@ void Update()
6871
}
6972
else
7073
{
71-
RunNextTrial();
72-
}
74+
// end trial
75+
exp.currentTrial.End();
76+
}
7377
}
7478
}
7579

76-
void RunNextTrial()
80+
public void RunTrial()
7781
{
78-
Debug.Log("Starting trial!");
79-
exp.nextTrial.Begin();
82+
Debug.Log("Running trial!");
8083

84+
// we can access our settings to (e.g.) modify our scene
85+
Debug.LogFormat("The 'size' for this trial is: {0}", Convert.ToSingle(exp.currentTrial.settings["size"]));
86+
8187
// record custom values...
8288
string observation = UnityEngine.Random.value.ToString();
8389
Debug.Log(string.Format("We observed: {0}", observation));

0 commit comments

Comments
 (0)