Skip to main content

Signal Processor

Signal Processors provide a way to filter and change the Signals produced by a Sensor. Every Sensor has a list of Signal Processors that are executed in sequence on its detections. A processor may change the Strength or Shape of a signal, map it to a different GameObject or filter it from the detections completely.

If you are using your own tag system and you want the sensors to filter on that, then Signal Processors are an ideal way to implement it.


The RangeSensor is using a MapStrengthByDistance processor. This will interpolate the signal strength of its detections by distance from the sensor. The processor has defined a minimum signal strength of 0.2, which is filtering out the furthest box from the detections list.

There's a handful of SignalProcessors included in the toolkit, and it's straightforward to create your own by extending the base class SignalProcessor. Here is how you might write a processor that filters on a custom tag system.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Micosmo.SensorToolkit;

// You should extend SignalProcessor, which itself extends MonoBehaviour.
public class FilterExampleTagProcessor : SignalProcessor {

public string[] AllowedTags;

// Implement the Process function, the first parameter is the input signal, and the second
// is the Sensor the signal originated from. The signal parameter is a 'ref', if you want
// to change the signals properties then modify this parameter directly.
public override bool Process(ref Signal signal, Sensor sensor) {
var tag = signal.Object.GetComponent<ExampleTag>();
if (tag != null) {
foreach (var allowedTag in AllowedTags) {
if (tag.Tag == allowedTag) {
return true; // Return true if you intend the signal to be detected
}
}
}
return false; // Return false if you intend the signal to be filtered out
}
}

I recommend examining the included Signal Processors to better understand how to write your own.