From cd9b4a1e9e7e322b1dfbb09ede120c95dae3a52e Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 19 Feb 2025 17:01:00 +0100 Subject: [PATCH] namespace change, added doc --- Sensors/DistanceSensor.cs | 2 +- SiteServer.cs | 1 - Unity/DistanceSensor.cs | 24 +++++++++++++++++++++--- Unity/TouchSensor.cs | 14 ++++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Sensors/DistanceSensor.cs b/Sensors/DistanceSensor.cs index 2c1db64..3967ae5 100644 --- a/Sensors/DistanceSensor.cs +++ b/Sensors/DistanceSensor.cs @@ -26,7 +26,7 @@ namespace Passer.RoboidControl { #if UNITY_5_3_OR_NEWER /// @copydoc Passer::RoboidControl::Thing::CreateComponent public override void CreateComponent() { - this.component = Unity.DistanceSensor.Create(this.parent); + this.component = Unity.DistanceSensor.Create(this); this.component.core = this; } #endif diff --git a/SiteServer.cs b/SiteServer.cs index 2154c12..868aacf 100644 --- a/SiteServer.cs +++ b/SiteServer.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Net; using System.Net.Sockets; diff --git a/Unity/DistanceSensor.cs b/Unity/DistanceSensor.cs index 8a9af74..f8cc98a 100644 --- a/Unity/DistanceSensor.cs +++ b/Unity/DistanceSensor.cs @@ -4,13 +4,22 @@ using UnityEngine; namespace Passer.RoboidControl.Unity { + /// + /// The Unity representation of a distance sensor + /// public class DistanceSensor : Thing { + /// + /// The core distance sensor + /// public new RoboidControl.DistanceSensor core { get => (RoboidControl.DistanceSensor)base.core; set => base.core = value; } + /// + /// Start the Unity representation + /// protected virtual void Start() { if (core == null) { SiteServer siteServer = FindAnyObjectByType(); @@ -20,15 +29,24 @@ namespace Passer.RoboidControl.Unity { StartCoroutine(MeasureDistance()); } - public static DistanceSensor Create(RoboidControl.Thing parent) { + /// + /// Create the Unity representation of the distance sensor + /// + /// The parent of the core distance sensor + /// The Unity representation of the distance sensor + public static DistanceSensor Create(RoboidControl.DistanceSensor core) { GameObject distanceObj = new("Distance sensor"); DistanceSensor component = distanceObj.AddComponent(); - if (parent != null && parent.component != null) - distanceObj.transform.SetParent(parent.component.transform, false); + if (core.parent != null && core.parent.component != null) + distanceObj.transform.SetParent(core.parent.component.transform, false); return component; } + /// + /// Periodically measure the distance + /// + /// IEnumerator MeasureDistance() { while (Application.isPlaying) { if (Physics.Raycast(this.transform.position, this.transform.forward, out RaycastHit hitInfo, 2.0f)) { diff --git a/Unity/TouchSensor.cs b/Unity/TouchSensor.cs index 0655f9f..31dd50a 100644 --- a/Unity/TouchSensor.cs +++ b/Unity/TouchSensor.cs @@ -8,18 +8,28 @@ namespace Passer.RoboidControl.Unity { /// public class TouchSensor : Thing { + /// + /// The core touch sensor + /// public RoboidControl.TouchSensor coreSensor { get => (RoboidControl.TouchSensor)base.core; } + /// + /// Start the Unity represention + /// protected virtual void Start() { if (core == null) { SiteServer siteServer = FindAnyObjectByType(); SetCoreThing(new RoboidControl.TouchSensor(siteServer.site)); } - } + /// + /// Create the Unity representation + /// + /// The core touch sensor + /// The Unity representation of the touch sensor public static TouchSensor Create(RoboidControl.TouchSensor core) { GameObject gameObj = core.name != null ? new(core.name) : @@ -48,7 +58,7 @@ namespace Passer.RoboidControl.Unity { if (this.transform.root == other.transform.root) return; - Debug.Log($"touched {other.gameObject.name}"); + // Debug.Log($"touched {other.gameObject.name}"); this.coreSensor.touchedSomething = true; } private void OnTriggerExit(Collider other) {