Unity Compatibility
This commit is contained in:
parent
062aafd19a
commit
4044b86a9d
@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Passer.LinearAlgebra;
|
using Passer.LinearAlgebra;
|
||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
using Vector3Float = UnityEngine.Vector3;
|
||||||
|
#endif
|
||||||
|
|
||||||
public readonly struct Slice {
|
public readonly struct Slice {
|
||||||
public int start { get; }
|
public int start { get; }
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
using Vector3Float = UnityEngine.Vector3;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Passer.LinearAlgebra {
|
namespace Passer.LinearAlgebra {
|
||||||
public class Spherical {
|
public class Spherical {
|
||||||
public float distance;
|
public float distance;
|
||||||
|
@ -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 {
|
namespace Passer.LinearAlgebra {
|
||||||
|
|
||||||
public class Vector3Of<T> {
|
public class Vector3Of<T> {
|
||||||
public T x;
|
public T x;
|
||||||
public T y;
|
public T y;
|
||||||
|
@ -24,7 +24,7 @@ namespace Passer.Control.Core {
|
|||||||
public CustomMsg(byte networkId, Thing thing) : base() {
|
public CustomMsg(byte networkId, Thing thing) : base() {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thing.id;
|
this.thingId = thing.id;
|
||||||
this.bytes = [];
|
this.bytes = new byte[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte Serialize(ref byte[] buffer) {
|
public override byte Serialize(ref byte[] buffer) {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Passer.Control.Core {
|
namespace Passer.Control.Core {
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Passer.Control.Core {
|
namespace Passer.Control.Core {
|
||||||
|
|
||||||
public class InvestigateMsg : IMessage {
|
public class InvestigateMsg : IMessage {
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Passer.Control.Core {
|
namespace Passer.Control.Core {
|
||||||
|
|
||||||
public class IMessage {
|
public class IMessage {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Passer.LinearAlgebra;
|
using Passer.LinearAlgebra;
|
||||||
|
|
||||||
namespace Passer.Control.Core {
|
namespace Passer.Control.Core {
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Passer.Control.Core {
|
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 const byte Id = 0xB0;
|
||||||
public string text = "";
|
public string text = "";
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ namespace Passer.Control.Core {
|
|||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected readonly List<Thing> things = [];
|
protected readonly List<Thing> things = new();
|
||||||
|
|
||||||
public Thing? Get(byte networkId, byte thingId) {
|
public Thing? Get(byte networkId, byte thingId) {
|
||||||
Thing? thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
|
Thing? thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
|
||||||
|
@ -2,9 +2,11 @@ using System;
|
|||||||
|
|
||||||
namespace Passer.Control.Core {
|
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 float temp = 0;
|
||||||
|
|
||||||
|
public TemperatureSensor(Participant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) {}
|
||||||
|
|
||||||
public override void ProcessBinary(byte[] bytes) {
|
public override void ProcessBinary(byte[] bytes) {
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
this.temp = LowLevelMessages.ReceiveFloat16(bytes, ref ix);
|
this.temp = LowLevelMessages.ReceiveFloat16(bytes, ref ix);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
5
Thing.cs
5
Thing.cs
@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Passer.LinearAlgebra;
|
using Passer.LinearAlgebra;
|
||||||
@ -128,7 +129,7 @@ namespace Passer.Control.Core {
|
|||||||
|
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public Unity.Thing component;
|
public Unity.Thing? component = null;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endregion Properties
|
#endregion Properties
|
||||||
@ -188,7 +189,7 @@ namespace Passer.Control.Core {
|
|||||||
|
|
||||||
//---------- All Things
|
//---------- All Things
|
||||||
|
|
||||||
private static readonly List<Thing> allThings = [];
|
// private static readonly List<Thing> allThings = new();
|
||||||
|
|
||||||
public delegate void ThingHandler(Thing t);
|
public delegate void ThingHandler(Thing t);
|
||||||
public static event ThingHandler OnNewThing = delegate {};
|
public static event ThingHandler OnNewThing = delegate {};
|
||||||
|
@ -12,8 +12,10 @@ namespace Passer.Control.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Start() {
|
protected virtual void Start() {
|
||||||
if (core == null)
|
if (core == null) {
|
||||||
SetCoreThing(new Core.DistanceSensor());
|
SiteServer siteServer = FindAnyObjectByType<SiteServer>();
|
||||||
|
SetCoreThing(new Core.DistanceSensor(siteServer.site));
|
||||||
|
}
|
||||||
|
|
||||||
StartCoroutine(MeasureDistance());
|
StartCoroutine(MeasureDistance());
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,10 @@ namespace Passer.Control.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Start() {
|
protected virtual void Start() {
|
||||||
if (core == null)
|
if (core == null) {
|
||||||
SetCoreThing(new Core.TouchSensor());
|
SiteServer siteServer = FindAnyObjectByType<SiteServer>();
|
||||||
|
SetCoreThing(new Core.TouchSensor(siteServer.site));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user