VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_TrialExperiment.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 
5 // TODO: Need better documentation
6 
7 namespace AVR.Core {
8  /// <summary>
9  /// Base class to inherit from in order to create trial-based experiments. (One experiment consists of one or more trials.)
10  /// </summary>
11  [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_core_1_1_a_v_r___trial_experiment.html")]
12  public abstract class AVR_TrialExperiment : AVR_Behaviour
13  {
14  /// <summary>
15  /// IEnumerator-coroutine that represents a single tiral
16  /// </summary>
17  public abstract IEnumerator trial();
18 
19  /// <summary>
20  /// Function that gets called when the experiment starts
21  /// </summary>
22  public virtual void on_start() { }
23 
24  /// <summary>
25  /// Function that gets called when the experiment ends
26  /// </summary>
27  public virtual void on_end() { }
28 
29  /// <summary>
30  /// Function that gets called when a trial starts
31  /// </summary>
32  public virtual void on_start_trial() { }
33 
34  /// <summary>
35  /// Function that gets called when a trial ends
36  /// </summary>
37  public virtual void on_end_trial() { }
38 
39  /// <summary>
40  /// This function returns true *once* after the can_proceed function has been called. Use this within the trial Coroutine like so: yield return new WaitUntil(can_proceed()). Then call the proceed() function on certain events, such as button presses.
41  /// </summary>
42  public bool can_proceed() {
43  if (_p)
44  {
45  _p = false;
46  return true;
47  }
48  return false;
49  }
50  private bool _p = false;
51 
52  /// <summary>
53  /// Call this function externally to allow the trial to proceed.
54  /// </summary>
55  public void proceed() {
56  _p = true;
57  }
58 
59  private IEnumerator experiment(int trial_amount) {
60  on_start();
61 
62  for(int i=0; i<trial_amount; i++) {
63  on_start_trial();
64  yield return StartCoroutine(this.trial());
65  on_end_trial();
66  }
67 
68  on_end();
69  }
70 
71  /// <summary>
72  /// Call this function to commence an experiment with a given amount of trials.
73  /// </summary>
74  /// <param name="trial_amount"> Amount of trials to run. </param>
75  public void commence(int trial_amount=1) {
76  StartCoroutine(experiment(trial_amount));
77  }
78  }
79 }
Monobehaviour but with an added URL button to a documentation page.
virtual void on_start_trial()
Function that gets called when a trial starts
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
bool can_proceed()
This function returns true once after the can_proceed function has been called. Use this within the t...
virtual void on_end_trial()
Function that gets called when a trial ends
Base class to inherit from in order to create trial-based experiments. (One experiment consists of on...
void commence(int trial_amount=1)
Call this function to commence an experiment with a given amount of trials.
IEnumerator experiment(int trial_amount)
virtual void on_start()
Function that gets called when the experiment starts
void proceed()
Call this function externally to allow the trial to proceed.
virtual void on_end()
Function that gets called when the experiment ends