|
|
| (6 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| ==Synopsis== | | ==Synopsis== |
| UnityBCI2000 is a tool for integration of Unity applications with BCI2000. | | UnityBCI2000 is an extension for the Unity game/3D application development platform that enables control of and communication with the BCI2000 brain-computer interface research platform. It consists of a .NET library for communication with the BCI2000 operator and a Unity package which provides integration with Unity itself. |
|
| |
|
| ==Tutorial== | | ==Prerequisites== |
| 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.
| | Alongside UnityBCI2000, install Unity per the instructions at [https://unity.com/download the Unity website], and the [[Programming_Howto:Building_and_Customizing_BCI2000|BCI2000 setup tutorial]]. |
| 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.
| | ==Adding UnityBCI2000 to a Unity Project== |
| | Download the latest release of UnityBCI2000 from [https://github.com/neurotechcenter/UnityBCI2000 GitHub]. Place the <code>UnityBCI2000.cs</code> and <code>BCI2000RemoteNETStandard.dll</code> files in the <code>Assets</code> folder of the Unity project. |
|
| |
|
| Add the UnityBCI2000 script as a component to an empty GameObject. This will serve as the connection to BCI2000 within your project. | | Add the <code>UnityBCI2000.cs</code> script to a Unity object as a component. |
|
| |
|
| 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.
| | For a comprehensive tutorial of integrating BCI2000 with a Unity project, see [[User Tutorial:UnityBCI2000]]. |
|
| |
|
| 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 a minimal tutorial on using BCI2000 as a logging service for Unity, see [[User Tutorial:UnityBCI2000 Barebones]]. |
| 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.
| | ==Documentation== |
| | | [https://bci2000.org/BCI2000Unity/classUnityBCI2000.html Interface documentation] |
| 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 an extension for the Unity game/3D application development platform that enables control of and communication with the BCI2000 brain-computer interface research platform. It consists of a .NET library for communication with the BCI2000 operator and a Unity package which provides integration with Unity itself.
Prerequisites
Alongside UnityBCI2000, install Unity per the instructions at the Unity website, and the BCI2000 setup tutorial.
Adding UnityBCI2000 to a Unity Project
Download the latest release of UnityBCI2000 from GitHub. Place the UnityBCI2000.cs and BCI2000RemoteNETStandard.dll files in the Assets folder of the Unity project.
Add the UnityBCI2000.cs script to a Unity object as a component.
For a comprehensive tutorial of integrating BCI2000 with a Unity project, see User Tutorial:UnityBCI2000.
For a minimal tutorial on using BCI2000 as a logging service for Unity, see User Tutorial:UnityBCI2000 Barebones.
Documentation
Interface documentation