-
Notifications
You must be signed in to change notification settings - Fork 38
Process Incoming Streams
Markus edited this page Dec 21, 2016
·
10 revisions
- 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!
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;
}
}