namespace Passer.RoboidControl { /// /// A sensor measuring the distance in the forward direction /// public class DistanceSensor : Thing { /// /// The current measured distance /// public float distance = 0; /// /// Constructor for a new distance sensor /// /// The participant for which the sensor is needed public DistanceSensor(RemoteParticipant participant) : base(participant, true) { } /// /// Create a distance sensor with the given ID /// /// The participant for with the sensor is needed /// The network ID of the sensor /// The ID of the thing public DistanceSensor(RemoteParticipant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) { } #if UNITY_5_3_OR_NEWER /// @copydoc Passer::RoboidControl::Thing::CreateComponent public override void CreateComponent() { this.component = Unity.DistanceSensor.Create(this); this.component.core = this; } #endif /// /// Function to extract the distance received in the binary message /// /// The byte array public override void ProcessBinary(byte[] bytes) { byte ix = 0; this.distance = LowLevelMessages.ReceiveFloat16(bytes, ref ix); } } }