From 590b72dc75eeae90083c93c117ccb0e14808a5eb Mon Sep 17 00:00:00 2001 From: BRomans Date: Tue, 22 Jun 2021 10:17:40 +0200 Subject: [PATCH 1/3] :memo: updated README-Unity.md code examples with new naming convention --- README-Unity.md | 76 ++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/README-Unity.md b/README-Unity.md index fd0ffac..d4f474f 100644 --- a/README-Unity.md +++ b/README-Unity.md @@ -20,7 +20,7 @@ LSL.cs includes a Unity interface to liblsl as a [Unity native plug-in](https:// 1. When the cube is selected, in the Inspector click on "Add Component", and create a new script called LSLInput. 1. In the Project viewer, double click on LSLInput.cs. This should launch Visual Studio or another IDE. 1. Fill in the script. Use [LSL4Unity AInlet](https://github.com/labstreaminglayer/LSL4Unity/blob/master/Scripts/AInlet.cs) for inspiration. - * There is [currently a bug](https://github.com/sccn/liblsl/issues/29) that prevents liblsl in Unity from resolving streams from _other_ computers while running in editor, and also the built product but only when using `ContinuousResolver`. For this reason we recommend using `liblsl.resolve_stream` instead. + * There is [currently a bug](https://github.com/sccn/liblsl/issues/29) that prevents liblsl in Unity from resolving streams from _other_ computers while running in editor, and also the built product but only when using `ContinuousResolver`. For this reason we recommend using `LSL.resolve_stream` instead. ```cs using System.Collections; @@ -32,8 +32,8 @@ public class LSLInput : MonoBehaviour { public string StreamType = "EEG"; public float scaleInput = 0.1f; - liblsl.StreamInfo[] streamInfos; - liblsl.StreamInlet streamInlet; + LSL.StreamInfo[] streamInfos; + LSL.StreamInlet streamInlet; float[] sample; private int channelCount = 0; @@ -41,10 +41,10 @@ public class LSLInput : MonoBehaviour { if (streamInlet == null) { - streamInfos = liblsl.resolve_stream("type", StreamType, 1, 0.0); + streamInfos = LSL.LSL.resolve_stream("type", StreamType, 1, 0.0); if (streamInfos.Length > 0) { - streamInlet = new liblsl.StreamInlet(streamInfos[0]); + streamInlet = new LSL.StreamInlet(streamInfos[0]); channelCount = streamInlet.info().channel_count(); streamInlet.open_stream(); } @@ -79,41 +79,41 @@ public class LSLInput : MonoBehaviour 1. Attach a new component called LSLPosOutput to the cube. 1. Edit it as follows: - ```cs - using System.Collections; - using System.Collections.Generic; - using UnityEngine; - using LSL; +```cs +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using LSL; - public class LSLOutput : MonoBehaviour - { - private liblsl.StreamOutlet outlet; - private float[] currentSample; +public class LSLOutput : MonoBehaviour +{ + private LSL.StreamOutlet outlet; + private float[] currentSample; - public string StreamName = "Unity.ExampleStream"; - public string StreamType = "Unity.StreamType"; - public string StreamId = "MyStreamID-Unity1234"; + public string StreamName = "Unity.ExampleStream"; + public string StreamType = "Unity.StreamType"; + public string StreamId = "MyStreamID-Unity1234"; - // Start is called before the first frame update - void Start() - { - liblsl.StreamInfo streamInfo = new liblsl.StreamInfo(StreamName, StreamType, 3, Time.fixedDeltaTime * 1000, liblsl.channel_format_t.cf_float32); - liblsl.XMLElement chans = streamInfo.desc().append_child("channels"); - chans.append_child("channel").append_child_value("label", "X"); - chans.append_child("channel").append_child_value("label", "Y"); - chans.append_child("channel").append_child_value("label", "Z"); - outlet = new liblsl.StreamOutlet(streamInfo); - currentSample = new float[3]; - } + // Start is called before the first frame update + void Start() + { + LSL.StreamInfo streamInfo = new LSL.StreamInfo(StreamName, StreamType, 3, Time.fixedDeltaTime * 1000, LSL.channel_format_t.cf_float32); + LSL.XMLElement chans = streamInfo.desc().append_child("channels"); + chans.append_child("channel").append_child_value("label", "X"); + chans.append_child("channel").append_child_value("label", "Y"); + chans.append_child("channel").append_child_value("label", "Z"); + outlet = new LSL.StreamOutlet(streamInfo); + currentSample = new float[3]; + } - // Update is called once per frame - void FixedUpdate() - { - Vector3 pos = gameObject.transform.position; - currentSample[0] = pos.x; - currentSample[1] = pos.y; - currentSample[2] = pos.z; - outlet.push_sample(currentSample); - } + // Update is called once per frame + void FixedUpdate() + { + Vector3 pos = gameObject.transform.position; + currentSample[0] = pos.x; + currentSample[1] = pos.y; + currentSample[2] = pos.z; + outlet.push_sample(currentSample); } - ``` +} +``` From 2c5f9dcc36cca0d2dca8f34dc115cd83918a61f1 Mon Sep 17 00:00:00 2001 From: BRomans Date: Tue, 22 Jun 2021 10:24:01 +0200 Subject: [PATCH 2/3] :memo: using static import of LSL.LSL class --- README-Unity.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README-Unity.md b/README-Unity.md index d4f474f..a0e50a4 100644 --- a/README-Unity.md +++ b/README-Unity.md @@ -27,6 +27,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using LSL; +using static LSL.LSL; public class LSLInput : MonoBehaviour { @@ -41,7 +42,7 @@ public class LSLInput : MonoBehaviour { if (streamInlet == null) { - streamInfos = LSL.LSL.resolve_stream("type", StreamType, 1, 0.0); + streamInfos = resolve_stream("type", StreamType, 1, 0.0); if (streamInfos.Length > 0) { streamInlet = new LSL.StreamInlet(streamInfos[0]); From d93c3481559da86d6fe47b33d6d5a9ea5f769703 Mon Sep 17 00:00:00 2001 From: BRomans Date: Wed, 23 Jun 2021 00:15:42 +0200 Subject: [PATCH 3/3] :art: improved the clarity of code examples --- README-Unity.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README-Unity.md b/README-Unity.md index a0e50a4..25635db 100644 --- a/README-Unity.md +++ b/README-Unity.md @@ -33,8 +33,8 @@ public class LSLInput : MonoBehaviour { public string StreamType = "EEG"; public float scaleInput = 0.1f; - LSL.StreamInfo[] streamInfos; - LSL.StreamInlet streamInlet; + StreamInfo[] streamInfos; + StreamInlet streamInlet; float[] sample; private int channelCount = 0; @@ -45,7 +45,7 @@ public class LSLInput : MonoBehaviour streamInfos = resolve_stream("type", StreamType, 1, 0.0); if (streamInfos.Length > 0) { - streamInlet = new LSL.StreamInlet(streamInfos[0]); + streamInlet = new StreamInlet(streamInfos[0]); channelCount = streamInlet.info().channel_count(); streamInlet.open_stream(); } @@ -88,7 +88,7 @@ using LSL; public class LSLOutput : MonoBehaviour { - private LSL.StreamOutlet outlet; + private StreamOutlet outlet; private float[] currentSample; public string StreamName = "Unity.ExampleStream"; @@ -98,12 +98,12 @@ public class LSLOutput : MonoBehaviour // Start is called before the first frame update void Start() { - LSL.StreamInfo streamInfo = new LSL.StreamInfo(StreamName, StreamType, 3, Time.fixedDeltaTime * 1000, LSL.channel_format_t.cf_float32); - LSL.XMLElement chans = streamInfo.desc().append_child("channels"); + StreamInfo streamInfo = new StreamInfo(StreamName, StreamType, 3, Time.fixedDeltaTime * 1000, LSL.channel_format_t.cf_float32); + XMLElement chans = streamInfo.desc().append_child("channels"); chans.append_child("channel").append_child_value("label", "X"); chans.append_child("channel").append_child_value("label", "Y"); chans.append_child("channel").append_child_value("label", "Z"); - outlet = new LSL.StreamOutlet(streamInfo); + outlet = new StreamOutlet(streamInfo); currentSample = new float[3]; }