namespace Passer.RoboidControl { /// /// A sensor which can detect touches /// public class TouchSensor : Thing { /// /// Value which is true when the sensor is touching something, false otherwise /// //public bool touchedSomething = false; private bool _touchedSomething = false; public bool touchedSomething { get { return _touchedSomething; } set { _touchedSomething = value; //SendBinary(); } } /// /// Create a touch sensor /// /// The participant for with the sensor is needed /// True when the creation should trigger an event public TouchSensor(RemoteParticipant participant, bool invokeEvent = true) : base(participant, invokeEvent) { touchedSomething = false; } public TouchSensor(RemoteParticipant participant, byte networkId, byte thingId) : base(participant, networkId, thingId) { touchedSomething = false; } #if UNITY_5_3_OR_NEWER /// @copydoc Passer::RoboidControl::Thing::CreateComponent public override void CreateComponent() { System.Console.Write("Create touch sensor component"); this.component = Unity.TouchSensor.Create(this); this.component.core = this; } #endif public override byte[] GenerateBinary() { byte[] buffer = new byte[1]; buffer[0] = (byte)(touchedSomething ? 1 : 0); return buffer; } } }