namespace change, added doc

This commit is contained in:
Pascal Serrarens 2025-02-19 17:01:00 +01:00
parent 4eb65f1312
commit cd9b4a1e9e
4 changed files with 34 additions and 7 deletions

View File

@ -26,7 +26,7 @@ namespace Passer.RoboidControl {
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
/// @copydoc Passer::RoboidControl::Thing::CreateComponent /// @copydoc Passer::RoboidControl::Thing::CreateComponent
public override void CreateComponent() { public override void CreateComponent() {
this.component = Unity.DistanceSensor.Create(this.parent); this.component = Unity.DistanceSensor.Create(this);
this.component.core = this; this.component.core = this;
} }
#endif #endif

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;

View File

@ -4,13 +4,22 @@ using UnityEngine;
namespace Passer.RoboidControl.Unity { namespace Passer.RoboidControl.Unity {
/// <summary>
/// The Unity representation of a distance sensor
/// </summary>
public class DistanceSensor : Thing { public class DistanceSensor : Thing {
/// <summary>
/// The core distance sensor
/// </summary>
public new RoboidControl.DistanceSensor core { public new RoboidControl.DistanceSensor core {
get => (RoboidControl.DistanceSensor)base.core; get => (RoboidControl.DistanceSensor)base.core;
set => base.core = value; set => base.core = value;
} }
/// <summary>
/// Start the Unity representation
/// </summary>
protected virtual void Start() { protected virtual void Start() {
if (core == null) { if (core == null) {
SiteServer siteServer = FindAnyObjectByType<SiteServer>(); SiteServer siteServer = FindAnyObjectByType<SiteServer>();
@ -20,15 +29,24 @@ namespace Passer.RoboidControl.Unity {
StartCoroutine(MeasureDistance()); StartCoroutine(MeasureDistance());
} }
public static DistanceSensor Create(RoboidControl.Thing parent) { /// <summary>
/// Create the Unity representation of the distance sensor
/// </summary>
/// <param name="parent">The parent of the core distance sensor</param>
/// <returns>The Unity representation of the distance sensor</returns>
public static DistanceSensor Create(RoboidControl.DistanceSensor core) {
GameObject distanceObj = new("Distance sensor"); GameObject distanceObj = new("Distance sensor");
DistanceSensor component = distanceObj.AddComponent<DistanceSensor>(); DistanceSensor component = distanceObj.AddComponent<DistanceSensor>();
if (parent != null && parent.component != null) if (core.parent != null && core.parent.component != null)
distanceObj.transform.SetParent(parent.component.transform, false); distanceObj.transform.SetParent(core.parent.component.transform, false);
return component; return component;
} }
/// <summary>
/// Periodically measure the distance
/// </summary>
/// <returns></returns>
IEnumerator MeasureDistance() { IEnumerator MeasureDistance() {
while (Application.isPlaying) { while (Application.isPlaying) {
if (Physics.Raycast(this.transform.position, this.transform.forward, out RaycastHit hitInfo, 2.0f)) { if (Physics.Raycast(this.transform.position, this.transform.forward, out RaycastHit hitInfo, 2.0f)) {

View File

@ -8,18 +8,28 @@ namespace Passer.RoboidControl.Unity {
/// </summary> /// </summary>
public class TouchSensor : Thing { public class TouchSensor : Thing {
/// <summary>
/// The core touch sensor
/// </summary>
public RoboidControl.TouchSensor coreSensor { public RoboidControl.TouchSensor coreSensor {
get => (RoboidControl.TouchSensor)base.core; get => (RoboidControl.TouchSensor)base.core;
} }
/// <summary>
/// Start the Unity represention
/// </summary>
protected virtual void Start() { protected virtual void Start() {
if (core == null) { if (core == null) {
SiteServer siteServer = FindAnyObjectByType<SiteServer>(); SiteServer siteServer = FindAnyObjectByType<SiteServer>();
SetCoreThing(new RoboidControl.TouchSensor(siteServer.site)); SetCoreThing(new RoboidControl.TouchSensor(siteServer.site));
} }
} }
/// <summary>
/// Create the Unity representation
/// </summary>
/// <param name="core">The core touch sensor</param>
/// <returns>The Unity representation of the touch sensor</returns>
public static TouchSensor Create(RoboidControl.TouchSensor core) { public static TouchSensor Create(RoboidControl.TouchSensor core) {
GameObject gameObj = core.name != null ? GameObject gameObj = core.name != null ?
new(core.name) : new(core.name) :
@ -48,7 +58,7 @@ namespace Passer.RoboidControl.Unity {
if (this.transform.root == other.transform.root) if (this.transform.root == other.transform.root)
return; return;
Debug.Log($"touched {other.gameObject.name}"); // Debug.Log($"touched {other.gameObject.name}");
this.coreSensor.touchedSomething = true; this.coreSensor.touchedSomething = true;
} }
private void OnTriggerExit(Collider other) { private void OnTriggerExit(Collider other) {