|
|
| Line 3: |
Line 3: |
|
| |
|
| ==Tutorial== | | ==Tutorial== |
| For information on how to use Unity itself, see the Unity [https://docs.unity3d.com/Manual/index.html manual]. This tutorial assumes knowledge of how to use Unity.
| | [https://bci2000.org/BCI2000Unity/classUnityBCI2000.html Class documentation] |
| More in-depth detail on how UnityBCI2000 works is provided in the README.md file, as well as HTML documentation in the docs directory.
| |
| | |
| First, download UnityBCI2000 from [https://github.com/neurotechcenter/UnityBCI2000 GitHub]. As of now, UnityBCI2000 is not a full Unity package, but it works the same. Place the files UnityBCI2000.cs and BCI2000RemoteNET.dll within the Assets folder of your Unity project.
| |
| | |
| Add the UnityBCI2000 script as a component to an empty GameObject. This will serve as the connection to BCI2000 within your project.
| |
| | |
| Specify the location of the BCI2000 executable, the BCI2000 modules you want to start along with their startup arguments, and any parameter files you want to load.
| |
| | |
| Connection to BCI2000 is done by calling UnityBCI2000's methods from other scripts. Within the script object from which you want to control BCI2000, add the UnityBCI2000 component as a member variable using Unity's GameObject.Find and GameObject.GetComponent methods.
| |
| For example, if you have UnityBCI2000 attached to a GameObject called "BCI2K", your script would look like this:
| |
| <tt>
| |
| class ObjScript : MonoBehaviour {
| |
| private UnityBCI2000 bci = GameObject.Find("BCI2K").GetComponent<UnityBCI2000>();
| |
| public void Start(){}
| |
| public void Update(){}
| |
| }
| |
| </tt>
| |
| | |
| Events and States can be added to BCI2000 within the Start() methods of your scripts. If you wanted to add an Event called "X" and a State called "Y", your script would look like this:
| |
| | |
| <tt>
| |
| class ObjScript : MonoBehaviour {
| |
| private UnityBCI2000 bci = GameObject.Find("BCI2K").GetComponent<UnityBCI2000>();
| |
| public void Start(){
| |
| bci.AddEvent("M");
| |
| bci.AddState("N");
| |
| }
| |
| public void Update(){}
| |
| }
| |
| </tt>
| |
| | |
| Events and States are accessed through a few methods of UnityBCI2000 called from the Update() method. In order to access their values, use the GetEvent and GetState methods.
| |
| | |
| In order to set their values, call SetEvent, PulseEvent, or SetState. For events, SetEvent sets the value of an Event like a state, and PulseEvent sets the value of an Event for a single sample before returning it to its previous value, for use if you want to record an instantaneous event happening.
| |
| A script which interacts with events:
| |
| | |
| <tt>
| |
| class ObjScript : MonoBehaviour {
| |
| private UnityBCI2000 bci = GameObject.Find("BCI2K").GetComponent<UnityBCI2000>();
| |
| public void Start(){
| |
| bci.AddEvent("M");
| |
| bci.AddState("N");
| |
| }
| |
| public void Update(){
| |
| int x = bci.GetEvent("MousePosX");
| |
| if (condition) {
| |
| bci.PulseEvent("thingHappened", 1);
| |
| }
| |
| bci.SetEvent("Y", (int) transform.position.y);
| |
| }
| |
| }
| |
| </tt>
| |
Synopsis
UnityBCI2000 is a tool for integration of Unity applications with BCI2000.
Tutorial
Class documentation