From 56edf36785a8674a2d51918fac34da7a6bd1a612 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Thu, 24 Apr 2025 15:38:56 +0200 Subject: [PATCH] Merge commit '3d2374436c10bab43a85c2177f174fb530f751c4' --- Unity/Thing.cs | 4 ++-- Unity/TouchSensor.cs | 22 ++++++++++++++++++++-- src/Participants/SiteServer.cs | 6 ++++-- src/Thing.cs | 2 +- src/Things/TouchSensor.cs | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Unity/Thing.cs b/Unity/Thing.cs index 306e021..1067e64 100644 --- a/Unity/Thing.cs +++ b/Unity/Thing.cs @@ -65,7 +65,7 @@ namespace RoboidControl.Unity { /// protected virtual void Update() { if (core == null) { - Debug.Log("Core thing is gone, self destruct in 0 seconds..."); + // Debug.Log("Core thing is gone, self destruct in 0 seconds..."); Destroy(this); return; } @@ -94,7 +94,7 @@ namespace RoboidControl.Unity { core.nameChanged = false; } if (core.hierarchyChanged) { - Debug.Log("Parent changed"); + // Debug.Log("Parent changed"); if (core.parent == null) this.transform.SetParent(null, true); else diff --git a/Unity/TouchSensor.cs b/Unity/TouchSensor.cs index 9814bee..5c72771 100644 --- a/Unity/TouchSensor.cs +++ b/Unity/TouchSensor.cs @@ -16,6 +16,8 @@ namespace RoboidControl.Unity { get => (RoboidControl.TouchSensor)base.core; } + SphereCollider collider = null; + /// /// Start the Unity represention /// @@ -24,6 +26,7 @@ namespace RoboidControl.Unity { participant = FindAnyObjectByType(); SetCoreThing(new RoboidControl.TouchSensor(participant.site)); } + collider = GetComponent(); } /// @@ -53,11 +56,26 @@ namespace RoboidControl.Unity { return component; } + protected override void Update() { + base.Update(); + if (collider.radius == 0.01f && + this.transform.parent != null && this.transform.localPosition.magnitude > 0 + ) { + collider.radius = Vector3.Distance(this.transform.position, this.transform.parent.position) / 2; + this.transform.position = (this.transform.position + this.transform.parent.position) / 2; + } + } + private void OnTriggerEnter(Collider other) { - if (other.isTrigger) + Debug.Log("Touch?"); + if (other.isTrigger) { + Debug.Log($" was trigger {other.name}"); return; - if (this.transform.root == other.transform.root) + } + if (this.transform.root == other.transform.root) { + Debug.Log($" was myself {other.name}"); return; + } Debug.Log($"*** {this} Touch"); this.coreSensor.touchedSomething = true; diff --git a/src/Participants/SiteServer.cs b/src/Participants/SiteServer.cs index 0e39d83..a52f894 100644 --- a/src/Participants/SiteServer.cs +++ b/src/Participants/SiteServer.cs @@ -73,7 +73,9 @@ namespace RoboidControl { if (this.isIsolated == false) { // Send to all other participants - foreach (Participant participant in Participant.participants) { + //foreach (Participant participant in Participant.participants) { + for (int participantIx = 0; participantIx < Participant.participants.Count; participantIx++) { + Participant participant = Participant.participants[participantIx]; if (participant == null || participant == this) continue; @@ -112,7 +114,7 @@ namespace RoboidControl { Console.WriteLine($"Could not find parent [{msg.networkId}/{msg.parentId}]"); } else { - Console.Write($"Dropped {thing.id}"); + // Console.Write($"Dropped {thing.id}"); thing.parent = null; } } diff --git a/src/Thing.cs b/src/Thing.cs index 7e4ae16..b6d145a 100644 --- a/src/Thing.cs +++ b/src/Thing.cs @@ -90,7 +90,7 @@ namespace RoboidControl { this.id = thingId; this.type = thingType; this.networkId = networkId; - Console.Write($"New thing added to {owner}"); + // Console.Write($"New thing added to {owner}"); this.owner.Add(this); InvokeNewThing(this); } diff --git a/src/Things/TouchSensor.cs b/src/Things/TouchSensor.cs index 88cb88d..93c7536 100644 --- a/src/Things/TouchSensor.cs +++ b/src/Things/TouchSensor.cs @@ -37,9 +37,9 @@ namespace RoboidControl { get { return _touchedSomething; } set { if (_touchedSomething != value) { - touchUpdated = true; _touchedSomething = value; } + touchUpdated = true; } } private bool touchUpdated = false;