Skip to content

Process Incoming Streams

Markus Fleck edited this page Dec 21, 2016 · 10 revisions

Process Values from Stream Inlets

First see the new example scene! -> Demo_IncomingStreams.unity

  • Add Resolver component to a GameObject in your Scene
  • Create a new Script and inherit from a basic implementation of a sample type your expected stream provides
using UnityEngine; 
using Assets.LSL4Unity.Scripts.AbstractInlets;

public class DemoInletForFloatSamples : InletFloatSamples
{ ... }
  • Override the following methods:
public class DemoInletForFloatSamples : InletFloatSamples
{ 
   protected override void Process(float[] newSample, double timeStamp)
   {...}
   protected override void OnStreamAvailable()
   {...}
}

Process should contain your logic for processing your sample in the current state of your game.

OnStreamAvailable serves as a initialization for the moment the stream comes available. Within this method you should decide how the pullsample() sample method got called. The pullSample() method is already implemented in the base class!

  • Reference the AStreamIsFound method as a Dynamic Method of your script which is also already implemented in the base class to the Resolvers On Stream Found - Event. See more details on Unity here and see the tutorial video.

Inspector view

For one stream (older implementation - deprecated)

Use this example as a new Script and instantiate it. Don't forget to reference a transform component from a GameObject in your scene.

using Assets.LSL4Unity.Scripts.AbstractInlets;
using UnityEngine;

public class TransformMapping : AFloatInlet
{
    public Transform targetTransform;

    protected override void Process(float[] newSample, double timeStamp)
    {
        //Assuming that a sample contains at least 3 values for x,y,z
        float x = newSample[0];
        float y = newSample[1];
        float z = newSample[2];

        // we map the coordinates to a rotation
        var targetRotation = Quaternion.Euler(x, y, z);

        // apply the rotation to the target transform
        targetTransform.rotation = targetRotation;
    }
}