From 4044b86a9d0f76c48106324b0a2a7f3c924a5caa Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 19 Feb 2025 11:04:56 +0100 Subject: [PATCH] Unity Compatibility --- LinearAlgebra/Matrix.cs | 3 +++ LinearAlgebra/Spherical.cs | 5 +++++ LinearAlgebra/Vector3.cs | 5 +---- Messages/CustomMsg.cs | 2 +- Messages/DestroyMsg.cs | 2 ++ Messages/InvestigateMsg.cs | 3 +++ Messages/Messages.cs | 3 +++ Messages/PoseMsg.cs | 2 ++ Messages/TextMsg.cs | 6 +++++- RemoteParticipant.cs | 3 ++- Sensors/TemperatureSensor.cs | 4 +++- SiteServer.cs | 1 + Thing.cs | 5 +++-- Unity/DistanceSensor.cs | 6 ++++-- Unity/TouchSensor.cs | 6 ++++-- 15 files changed, 42 insertions(+), 14 deletions(-) diff --git a/LinearAlgebra/Matrix.cs b/LinearAlgebra/Matrix.cs index 9603048..95978be 100644 --- a/LinearAlgebra/Matrix.cs +++ b/LinearAlgebra/Matrix.cs @@ -1,6 +1,9 @@ using System; using System.Diagnostics; using Passer.LinearAlgebra; +#if UNITY_5_3_OR_NEWER +using Vector3Float = UnityEngine.Vector3; +#endif public readonly struct Slice { public int start { get; } diff --git a/LinearAlgebra/Spherical.cs b/LinearAlgebra/Spherical.cs index 2b86a66..5670c6b 100644 --- a/LinearAlgebra/Spherical.cs +++ b/LinearAlgebra/Spherical.cs @@ -1,3 +1,8 @@ +using System; +#if UNITY_5_3_OR_NEWER +using Vector3Float = UnityEngine.Vector3; +#endif + namespace Passer.LinearAlgebra { public class Spherical { public float distance; diff --git a/LinearAlgebra/Vector3.cs b/LinearAlgebra/Vector3.cs index c7ab61a..4b629ac 100644 --- a/LinearAlgebra/Vector3.cs +++ b/LinearAlgebra/Vector3.cs @@ -1,9 +1,6 @@ -#if UNITY_5_3_OR_NEWER -using Passer.LinearAlgebra.Vector3Float = UnityEngine.Vector3 -#else +#if !UNITY_5_3_OR_NEWER namespace Passer.LinearAlgebra { - public class Vector3Of { public T x; public T y; diff --git a/Messages/CustomMsg.cs b/Messages/CustomMsg.cs index e3c7acb..d089b73 100644 --- a/Messages/CustomMsg.cs +++ b/Messages/CustomMsg.cs @@ -24,7 +24,7 @@ namespace Passer.Control.Core { public CustomMsg(byte networkId, Thing thing) : base() { this.networkId = networkId; this.thingId = thing.id; - this.bytes = []; + this.bytes = new byte[0]; } public override byte Serialize(ref byte[] buffer) { diff --git a/Messages/DestroyMsg.cs b/Messages/DestroyMsg.cs index 1701a53..1298113 100644 --- a/Messages/DestroyMsg.cs +++ b/Messages/DestroyMsg.cs @@ -1,3 +1,5 @@ +using System.IO; +using System.Threading.Tasks; namespace Passer.Control.Core { diff --git a/Messages/InvestigateMsg.cs b/Messages/InvestigateMsg.cs index 7c6af47..39d4c2b 100644 --- a/Messages/InvestigateMsg.cs +++ b/Messages/InvestigateMsg.cs @@ -1,3 +1,6 @@ +using System.IO; +using System.Threading.Tasks; + namespace Passer.Control.Core { public class InvestigateMsg : IMessage { diff --git a/Messages/Messages.cs b/Messages/Messages.cs index c07368e..fe160cf 100644 --- a/Messages/Messages.cs +++ b/Messages/Messages.cs @@ -1,3 +1,6 @@ +using System.Threading.Tasks; +using System.IO; + namespace Passer.Control.Core { public class IMessage { diff --git a/Messages/PoseMsg.cs b/Messages/PoseMsg.cs index 9ea0748..6cdcb0c 100644 --- a/Messages/PoseMsg.cs +++ b/Messages/PoseMsg.cs @@ -1,3 +1,5 @@ +using System.IO; +using System.Threading.Tasks; using Passer.LinearAlgebra; namespace Passer.Control.Core { diff --git a/Messages/TextMsg.cs b/Messages/TextMsg.cs index 10f14c6..b28ac57 100644 --- a/Messages/TextMsg.cs +++ b/Messages/TextMsg.cs @@ -1,6 +1,10 @@ +using System.IO; +using System.Threading.Tasks; + namespace Passer.Control.Core { - public class TextMsg(byte[] buffer) : IMessage(buffer) { + public class TextMsg : IMessage { + public TextMsg(byte[] buffer) : base(buffer) {} public const byte Id = 0xB0; public string text = ""; diff --git a/RemoteParticipant.cs b/RemoteParticipant.cs index 7dce8da..8d8341f 100644 --- a/RemoteParticipant.cs +++ b/RemoteParticipant.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; @@ -17,7 +18,7 @@ namespace Passer.Control.Core { this.port = port; } - protected readonly List things = []; + protected readonly List things = new(); public Thing? Get(byte networkId, byte thingId) { Thing? thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId)); diff --git a/Sensors/TemperatureSensor.cs b/Sensors/TemperatureSensor.cs index 4617d47..bb8ed1e 100644 --- a/Sensors/TemperatureSensor.cs +++ b/Sensors/TemperatureSensor.cs @@ -2,9 +2,11 @@ using System; namespace Passer.Control.Core { - public class TemperatureSensor(Participant participant, byte networkId, byte thingId) : Thing(participant, networkId, thingId, (byte)Type.TemperatureSensor) { + public class TemperatureSensor : Thing { public float temp = 0; + public TemperatureSensor(Participant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) {} + public override void ProcessBinary(byte[] bytes) { byte ix = 0; this.temp = LowLevelMessages.ReceiveFloat16(bytes, ref ix); diff --git a/SiteServer.cs b/SiteServer.cs index 0fbc4a4..8c80049 100644 --- a/SiteServer.cs +++ b/SiteServer.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Net; diff --git a/Thing.cs b/Thing.cs index 34e61a5..3570382 100644 --- a/Thing.cs +++ b/Thing.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using Passer.LinearAlgebra; @@ -128,7 +129,7 @@ namespace Passer.Control.Core { #if UNITY_5_3_OR_NEWER [NonSerialized] - public Unity.Thing component; + public Unity.Thing? component = null; #endif #endregion Properties @@ -188,7 +189,7 @@ namespace Passer.Control.Core { //---------- All Things - private static readonly List allThings = []; + // private static readonly List allThings = new(); public delegate void ThingHandler(Thing t); public static event ThingHandler OnNewThing = delegate {}; diff --git a/Unity/DistanceSensor.cs b/Unity/DistanceSensor.cs index ac74b78..b28340d 100644 --- a/Unity/DistanceSensor.cs +++ b/Unity/DistanceSensor.cs @@ -12,8 +12,10 @@ namespace Passer.Control.Unity { } protected virtual void Start() { - if (core == null) - SetCoreThing(new Core.DistanceSensor()); + if (core == null) { + SiteServer siteServer = FindAnyObjectByType(); + SetCoreThing(new Core.DistanceSensor(siteServer.site)); + } StartCoroutine(MeasureDistance()); } diff --git a/Unity/TouchSensor.cs b/Unity/TouchSensor.cs index a666f6b..fe31b1b 100644 --- a/Unity/TouchSensor.cs +++ b/Unity/TouchSensor.cs @@ -10,8 +10,10 @@ namespace Passer.Control.Unity { } protected virtual void Start() { - if (core == null) - SetCoreThing(new Core.TouchSensor()); + if (core == null) { + SiteServer siteServer = FindAnyObjectByType(); + SetCoreThing(new Core.TouchSensor(siteServer.site)); + } }