Skip to content

Commit

Permalink
Add missing method requested in issue #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Fleck committed Jan 6, 2017
1 parent b43e70b commit a2b966f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 150 deletions.
157 changes: 9 additions & 148 deletions Demos/Demo_IncomingStreams.unity
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 2059534480}
m_MethodName: AStreamIsFound
m_TypeName: Assets.LSL4Unity.Scripts.StreamEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
onStreamLost:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 193850119}
m_MethodName: AStreamGotLost
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
Expand All @@ -147,11 +152,6 @@ MonoBehaviour:
m_CallState: 2
m_TypeName: Assets.LSL4Unity.Scripts.StreamEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
onStreamLost:
m_PersistentCalls:
m_Calls: []
m_TypeName: Assets.LSL4Unity.Scripts.StreamEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!4 &68353127
Transform:
m_ObjectHideFlags: 0
Expand All @@ -178,7 +178,7 @@ GameObject:
- component: {fileID: 193850116}
- component: {fileID: 193850119}
m_Layer: 0
m_Name: A
m_Name: AObjectListeningToAStream
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand All @@ -191,7 +191,7 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 193850114}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1, y: 0, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 753183517}
Expand Down Expand Up @@ -360,33 +360,13 @@ GameObject:
serializedVersion: 5
m_Component:
- component: {fileID: 753183517}
- component: {fileID: 753183518}
- component: {fileID: 753183516}
m_Layer: 0
m_Name: IncomingStreams
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &753183516
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 753183515}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 87163fb44bc059c4d99f26b875930ecf, type: 3}
m_Name:
m_EditorClassIdentifier:
moment: 0
StreamName: RandomSpehricalData_B
StreamType: 3DCoord
targetTransform: {fileID: 2059534476}
useX: 0
useY: 0
useZ: 0
--- !u!4 &753183517
Transform:
m_ObjectHideFlags: 0
Expand All @@ -398,28 +378,9 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 193850115}
- {fileID: 2059534476}
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &753183518
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 753183515}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 87163fb44bc059c4d99f26b875930ecf, type: 3}
m_Name:
m_EditorClassIdentifier:
moment: 0
StreamName: RandomSpehricalData_A
StreamType: 3DCoord
targetTransform: {fileID: 193850115}
useX: 0
useY: 0
useZ: 0
--- !u!1 &1295183507
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -483,103 +444,3 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &2059534475
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 2059534476}
- component: {fileID: 2059534479}
- component: {fileID: 2059534478}
- component: {fileID: 2059534477}
- component: {fileID: 2059534480}
m_Layer: 0
m_Name: B
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2059534476
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2059534475}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 753183517}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &2059534477
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2059534475}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!136 &2059534478
CapsuleCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2059534475}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 0.5
m_Height: 2
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &2059534479
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2059534475}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &2059534480
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2059534475}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5ba4ed7276e95054fb35c620c2207e28, type: 3}
m_Name:
m_EditorClassIdentifier:
StreamName: RandomSpehricalData_B
StreamType: 3DCoord
targetTransform: {fileID: 2059534476}
useX: 0
useY: 1
useZ: 0
30 changes: 28 additions & 2 deletions Scripts/BaseInlet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using LSL;
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;

namespace Assets.LSL4Unity.Scripts.AbstractInlets
{
Expand All @@ -14,6 +16,26 @@ public abstract class ABaseInlet : MonoBehaviour

protected int expectedChannels;

protected Resolver resolver;

/// <summary>
/// Call this method when your inlet implementation got created at runtime
/// </summary>
protected virtual void registerAndLookUpStream()
{
resolver = FindObjectOfType<Resolver>();

resolver.onStreamFound.AddListener(new UnityAction<LSLStreamInfoWrapper>(AStreamIsFound));

resolver.onStreamLost.AddListener(new UnityAction<LSLStreamInfoWrapper>(AStreamGotLost));

if (resolver.knownStreams.Any(isTheExpected))
{
var stream = resolver.knownStreams.First(isTheExpected);
AStreamIsFound(stream);
}
}

/// <summary>
/// Callback method for the Resolver gets called each time the resolver found a stream
/// </summary>
Expand Down Expand Up @@ -43,9 +65,12 @@ public virtual void AStreamGotLost(LSLStreamInfoWrapper stream)
this.enabled = false;
}

private bool isTheExpected(LSLStreamInfoWrapper stream)
protected virtual bool isTheExpected(LSLStreamInfoWrapper stream)
{
return StreamName.Equals(stream.Name);
bool predicate = StreamName.Equals(stream.Name);
predicate &= StreamType.Equals(stream.Type);

return predicate;
}

protected abstract void pullSamples();
Expand All @@ -55,6 +80,7 @@ protected virtual void OnStreamAvailable()
// base implementation may not decide what happens when the stream gets available
throw new NotImplementedException("Please override this method in a derived class!");
}

}

public abstract class InletFloatSamples : ABaseInlet
Expand Down
21 changes: 21 additions & 0 deletions Scripts/Examples/DemoInletForFloatSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,29 @@ public class DemoInletForFloatSamples : InletFloatSamples
public bool useY;
public bool useZ;


void Start()
{
// [optional] call this only, if your gameobject hosting this component
// got instantiated during runtime

// registerAndLookUpStream();
}

protected override bool isTheExpected(LSLStreamInfoWrapper stream)
{
// the base implementation just checks for stream name and type
var predicate = base.isTheExpected(stream);
// add a more specific description for your stream here specifying hostname etc.
//predicate &= stream.HostName.Equals("Expected Hostname");
return predicate;
}

/// <summary>
/// Override this method to implement whatever should happen with the samples...
/// IMPORTANT: Avoid heavy processing logic within this method, update a state and use
/// coroutines for more complexe processing tasks to distribute processing time over
/// several frames
/// </summary>
/// <param name="newSample"></param>
/// <param name="timeStamp"></param>
Expand Down

0 comments on commit a2b966f

Please sign in to comment.