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

@ -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

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

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

@ -8,18 +8,28 @@ namespace Passer.RoboidControl.Unity {
/// </summary>
public class TouchSensor : Thing {
/// <summary>
/// The core touch sensor
/// </summary>
public RoboidControl.TouchSensor coreSensor {
get => (RoboidControl.TouchSensor)base.core;
}
/// <summary>
/// Start the Unity represention
/// </summary>
protected virtual void Start() {
if (core == null) {
SiteServer siteServer = FindAnyObjectByType<SiteServer>();
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) {
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) {