From d88d3a879de3056144056fc60c122e0adb1c8407 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 17 Feb 2025 08:59:22 +0100 Subject: [PATCH 1/4] Fix merge error --- Unity/DistanceSensor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Unity/DistanceSensor.cs b/Unity/DistanceSensor.cs index b7a8d0d..ac74b78 100644 --- a/Unity/DistanceSensor.cs +++ b/Unity/DistanceSensor.cs @@ -7,7 +7,6 @@ namespace Passer.Control.Unity { public class DistanceSensor : Thing { public new Core.DistanceSensor core { - get => (Core.DistanceSensor)base.core; get => (Core.DistanceSensor)base.core; set => base.core = value; } From 6551c653c3fefffc82912c5891b90268d8453d51 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 17 Feb 2025 12:56:39 +0100 Subject: [PATCH 2/4] Touch & smell sensors --- Sensors/TouchSensor.cs | 16 ++++++++++++ Unity/TouchSensor.cs | 57 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Sensors/TouchSensor.cs create mode 100644 Unity/TouchSensor.cs diff --git a/Sensors/TouchSensor.cs b/Sensors/TouchSensor.cs new file mode 100644 index 0000000..ac2a660 --- /dev/null +++ b/Sensors/TouchSensor.cs @@ -0,0 +1,16 @@ + +namespace Passer.Control.Core { + public class TouchSensor : Thing { + public Thing touchedThing = null; + + public TouchSensor(bool invokeEvent = true) : base(invokeEvent) { + } + +#if UNITY_5_3_OR_NEWER + public override void CreateComponent() { + this.component = Unity.TouchSensor.Create(this); + this.component.core = this; + } +#endif + } +} \ No newline at end of file diff --git a/Unity/TouchSensor.cs b/Unity/TouchSensor.cs new file mode 100644 index 0000000..b2aac45 --- /dev/null +++ b/Unity/TouchSensor.cs @@ -0,0 +1,57 @@ +#if UNITY_5_3_OR_NEWER +using System.Collections; +using UnityEngine; + +namespace Passer.Control.Unity { + + public class TouchSensor : Thing { + + public Core.TouchSensor coreSensor { + get => (Core.TouchSensor)base.core; + } + + protected virtual void Start() { + if (core == null) + SetCoreThing(new Core.TouchSensor()); + + //StartCoroutine(MeasureDistance()); + } + bool update = false; + + protected override void Update() { + base.Update(); + this.update= false; + } + + public static TouchSensor Create(Core.TouchSensor core) { + GameObject gameObj = core.name != null ? + new(core.name) : + new("Touch Sensor"); + TouchSensor component = gameObj.AddComponent(); + Rigidbody rb = gameObj.AddComponent(); + rb.isKinematic = true; + + SphereCollider collider = gameObj.AddComponent(); + collider.radius = 0.01F; + collider.isTrigger = true; + + component.core = core; + if (core.parent != null && core.parent.component != null) + gameObj.transform.SetParent(core.parent.component.transform, false); + + if (core.position != null) + gameObj.transform.localPosition = core.position.ToVector3(); + + return component; + } + + private void OnTriggerEnter(Collider other) { + Debug.Log("Touch!"); + this.coreSensor.touchedThing = other.transform.GetComponentInParent().core; + } + private void OnTriggerExit(Collider other) { + this.coreSensor.touchedThing = null; + } + } +} +#endif \ No newline at end of file From 923cb317af593c1f7a3157e6fa7c6299c67351e5 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 17 Feb 2025 16:02:29 +0100 Subject: [PATCH 3/4] Grabbing food --- Sensors/TouchSensor.cs | 3 ++- Unity/TouchSensor.cs | 21 +++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Sensors/TouchSensor.cs b/Sensors/TouchSensor.cs index ac2a660..1553ee8 100644 --- a/Sensors/TouchSensor.cs +++ b/Sensors/TouchSensor.cs @@ -1,7 +1,8 @@ namespace Passer.Control.Core { public class TouchSensor : Thing { - public Thing touchedThing = null; + //public Thing touchedThing = null; + public bool touchedSomething = false; public TouchSensor(bool invokeEvent = true) : base(invokeEvent) { } diff --git a/Unity/TouchSensor.cs b/Unity/TouchSensor.cs index b2aac45..4cf41b8 100644 --- a/Unity/TouchSensor.cs +++ b/Unity/TouchSensor.cs @@ -1,5 +1,4 @@ #if UNITY_5_3_OR_NEWER -using System.Collections; using UnityEngine; namespace Passer.Control.Unity { @@ -14,13 +13,6 @@ namespace Passer.Control.Unity { if (core == null) SetCoreThing(new Core.TouchSensor()); - //StartCoroutine(MeasureDistance()); - } - bool update = false; - - protected override void Update() { - base.Update(); - this.update= false; } public static TouchSensor Create(Core.TouchSensor core) { @@ -30,7 +22,7 @@ namespace Passer.Control.Unity { TouchSensor component = gameObj.AddComponent(); Rigidbody rb = gameObj.AddComponent(); rb.isKinematic = true; - + SphereCollider collider = gameObj.AddComponent(); collider.radius = 0.01F; collider.isTrigger = true; @@ -46,11 +38,16 @@ namespace Passer.Control.Unity { } private void OnTriggerEnter(Collider other) { - Debug.Log("Touch!"); - this.coreSensor.touchedThing = other.transform.GetComponentInParent().core; + if (other.isTrigger) + return; + + this.coreSensor.touchedSomething = true; } private void OnTriggerExit(Collider other) { - this.coreSensor.touchedThing = null; + if (other.isTrigger) + return; + + this.coreSensor.touchedSomething = false; } } } From 86ff02a1100cc0f5f4dd2d335716e0f6678caf96 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 18 Feb 2025 15:05:07 +0100 Subject: [PATCH 4/4] Working ants --- Unity/SiteServer.cs | 5 ++--- Unity/TouchSensor.cs | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Unity/SiteServer.cs b/Unity/SiteServer.cs index 6431eb3..f809360 100644 --- a/Unity/SiteServer.cs +++ b/Unity/SiteServer.cs @@ -28,9 +28,8 @@ namespace Passer.Control.Unity { protected virtual void Update() { site.Update((ulong)(Time.time * 1000)); - if (thingQueue.TryDequeue(out Core.Thing thing)) { - thing.CreateComponent(); - } + while (thingQueue.TryDequeue(out Core.Thing thing)) + thing.CreateComponent(); } } diff --git a/Unity/TouchSensor.cs b/Unity/TouchSensor.cs index 4cf41b8..a666f6b 100644 --- a/Unity/TouchSensor.cs +++ b/Unity/TouchSensor.cs @@ -40,7 +40,10 @@ namespace Passer.Control.Unity { private void OnTriggerEnter(Collider other) { if (other.isTrigger) return; - + if (this.transform.root == other.transform.root) + return; + + Debug.Log($"touched {other.gameObject.name}"); this.coreSensor.touchedSomething = true; } private void OnTriggerExit(Collider other) {