Handle name msg

This commit is contained in:
Pascal Serrarens 2025-04-22 09:39:42 +02:00
parent 62cc00b694
commit 97fdd74950
6 changed files with 34 additions and 18 deletions

View File

@ -19,10 +19,6 @@ namespace RoboidControl.Unity {
private string modelUrl = null;
// protected virtual void Awake() {
// core.OnPoseChanged += PoseChanged;
// }
/// <summary>
/// Set the core C# thing
/// </summary>
@ -37,6 +33,7 @@ namespace RoboidControl.Unity {
}
siteServer.site.Add(thing);
core.OnPoseChanged += PoseChanged;
//core.OnNameChanged += NameChanged;
}
public static Thing Create(RoboidControl.Thing core) {
@ -56,6 +53,7 @@ namespace RoboidControl.Unity {
gameObj.transform.localRotation = core.orientation.ToQuaternion();
core.OnPoseChanged += component.PoseChanged;
//core.OnNameChanged += component.NameChanged;
return component;
}
@ -90,6 +88,12 @@ namespace RoboidControl.Unity {
this.modelUrl = core.modelUrl;
}
if (core.nameChanged) {
if (this.gameObject.name != core.name)
this.gameObject.name = core.name;
core.nameChanged = false;
}
}
private void PoseChanged() {
@ -100,6 +104,12 @@ namespace RoboidControl.Unity {
this.transform.localRotation = core.orientation.ToQuaternion();
}
private void NameChanged() {
Debug.Log($"{this} name changed");
if (this.gameObject.name != core.name)
this.gameObject.name = core.name;
}
private IEnumerator LoadJPG() {
UnityWebRequest request = UnityWebRequestTexture.GetTexture(core.modelUrl);
yield return request.SendWebRequest();

View File

@ -61,7 +61,7 @@ namespace RoboidControl {
return 0;
#if DEBUG
System.Console.WriteLine($"Send BinaryMsg [{this.networkId}/{this.thingId}] {this.dataLength}");
// System.Console.WriteLine($"Send BinaryMsg [{this.networkId}/{this.thingId}] {this.dataLength}");
#endif
byte ix = 0;
buffer[ix++] = BinaryMsg.Id;

View File

@ -139,6 +139,11 @@ namespace RoboidControl {
/// @copydoc Passer::RoboidControl::IMessage::Serialize
public override byte Serialize(ref byte[] buffer) {
#if DEBUG
// System.Console.WriteLine($"Send PoseMsg [{this.networkId}/{this.thingId}] {this.poseType}");
#endif
byte ix = 0;
buffer[ix++] = PoseMsg.Id;
buffer[ix++] = this.networkId;

View File

@ -95,7 +95,7 @@ namespace RoboidControl {
#region Update
protected void ReceiveUDP(IAsyncResult result) {
UnityEngine.Debug.Log("received");
// UnityEngine.Debug.Log("received");
if (this.udpClient == null) // || this.endPoint == null)
return;
@ -315,9 +315,9 @@ namespace RoboidControl {
}
protected virtual void Process(Participant sender, PoseMsg msg) {
#if DEBUG
Console.WriteLine($"Participant: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
#endif
// #if DEBUG
// Console.WriteLine($"Participant: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
// #endif
Thing thing = sender.Get(msg.networkId, msg.thingId);
if (thing != null) {
if ((msg.poseType & PoseMsg.Pose_Position) != 0)
@ -332,9 +332,9 @@ namespace RoboidControl {
}
protected virtual void Process(Participant sender, BinaryMsg msg) {
#if DEBUG
Console.WriteLine($"Participant: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
#endif
// #if DEBUG
// Console.WriteLine($"Participant: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
// #endif
Thing thing = sender.Get(msg.networkId, msg.thingId);
thing?.ProcessBinary(msg.data);
}

View File

@ -225,7 +225,6 @@ namespace RoboidControl {
[NonSerialized]
protected List<Thing> children = new();
private string _name = "";
/// <summary>
/// The name of the thing
@ -235,6 +234,7 @@ namespace RoboidControl {
set {
if (_name != value) {
_name = value;
nameChanged = true;
OnNameChanged?.Invoke();
}
}
@ -243,6 +243,7 @@ namespace RoboidControl {
/// Event which is triggered when the name changes
/// </summary>
public event ChangeHandler OnNameChanged = delegate { };
public bool nameChanged = false;
/// <summary>
/// An URL pointing to the location where a model of the thing can be found

View File

@ -48,7 +48,7 @@ namespace RoboidControl {
#if UNITY_5_3_OR_NEWER
/// @copydoc Passer::RoboidControl::Thing::CreateComponent
public override void CreateComponent() {
System.Console.Write("Create touch sensor component");
// System.Console.Write("Create touch sensor component");
this.component = Unity.TouchSensor.Create(this);
this.component.core = this;
}