Handle name msg
This commit is contained in:
parent
62cc00b694
commit
97fdd74950
@ -19,10 +19,6 @@ namespace RoboidControl.Unity {
|
|||||||
|
|
||||||
private string modelUrl = null;
|
private string modelUrl = null;
|
||||||
|
|
||||||
// protected virtual void Awake() {
|
|
||||||
// core.OnPoseChanged += PoseChanged;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the core C# thing
|
/// Set the core C# thing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,6 +33,7 @@ namespace RoboidControl.Unity {
|
|||||||
}
|
}
|
||||||
siteServer.site.Add(thing);
|
siteServer.site.Add(thing);
|
||||||
core.OnPoseChanged += PoseChanged;
|
core.OnPoseChanged += PoseChanged;
|
||||||
|
//core.OnNameChanged += NameChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Thing Create(RoboidControl.Thing core) {
|
public static Thing Create(RoboidControl.Thing core) {
|
||||||
@ -56,6 +53,7 @@ namespace RoboidControl.Unity {
|
|||||||
gameObj.transform.localRotation = core.orientation.ToQuaternion();
|
gameObj.transform.localRotation = core.orientation.ToQuaternion();
|
||||||
|
|
||||||
core.OnPoseChanged += component.PoseChanged;
|
core.OnPoseChanged += component.PoseChanged;
|
||||||
|
//core.OnNameChanged += component.NameChanged;
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +88,12 @@ namespace RoboidControl.Unity {
|
|||||||
|
|
||||||
this.modelUrl = core.modelUrl;
|
this.modelUrl = core.modelUrl;
|
||||||
}
|
}
|
||||||
|
if (core.nameChanged) {
|
||||||
|
if (this.gameObject.name != core.name)
|
||||||
|
this.gameObject.name = core.name;
|
||||||
|
core.nameChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PoseChanged() {
|
private void PoseChanged() {
|
||||||
@ -100,6 +104,12 @@ namespace RoboidControl.Unity {
|
|||||||
this.transform.localRotation = core.orientation.ToQuaternion();
|
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() {
|
private IEnumerator LoadJPG() {
|
||||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(core.modelUrl);
|
UnityWebRequest request = UnityWebRequestTexture.GetTexture(core.modelUrl);
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
|
@ -21,8 +21,8 @@ namespace RoboidControl {
|
|||||||
/// The ID of the thing
|
/// The ID of the thing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
|
|
||||||
public Thing thing;
|
public Thing thing;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The length of the data
|
/// The length of the data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -56,12 +56,12 @@ namespace RoboidControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
||||||
public override byte Serialize(ref byte[] buffer) {
|
public override byte Serialize(ref byte[] buffer) {
|
||||||
if (buffer.Length < BinaryMsg.length + this.data.Length || this.data.Length == 0)
|
if (buffer.Length < BinaryMsg.length + this.data.Length || this.data.Length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#if DEBUG
|
#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
|
#endif
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = BinaryMsg.Id;
|
buffer[ix++] = BinaryMsg.Id;
|
||||||
|
@ -139,6 +139,11 @@ namespace RoboidControl {
|
|||||||
|
|
||||||
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
||||||
public override byte Serialize(ref byte[] buffer) {
|
public override byte Serialize(ref byte[] buffer) {
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
// System.Console.WriteLine($"Send PoseMsg [{this.networkId}/{this.thingId}] {this.poseType}");
|
||||||
|
#endif
|
||||||
|
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = PoseMsg.Id;
|
buffer[ix++] = PoseMsg.Id;
|
||||||
buffer[ix++] = this.networkId;
|
buffer[ix++] = this.networkId;
|
||||||
|
@ -95,7 +95,7 @@ namespace RoboidControl {
|
|||||||
#region Update
|
#region Update
|
||||||
|
|
||||||
protected void ReceiveUDP(IAsyncResult result) {
|
protected void ReceiveUDP(IAsyncResult result) {
|
||||||
UnityEngine.Debug.Log("received");
|
// UnityEngine.Debug.Log("received");
|
||||||
if (this.udpClient == null) // || this.endPoint == null)
|
if (this.udpClient == null) // || this.endPoint == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -315,9 +315,9 @@ namespace RoboidControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, PoseMsg msg) {
|
protected virtual void Process(Participant sender, PoseMsg msg) {
|
||||||
#if DEBUG
|
// #if DEBUG
|
||||||
Console.WriteLine($"Participant: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
|
// Console.WriteLine($"Participant: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
|
||||||
#endif
|
// #endif
|
||||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
if (thing != null) {
|
if (thing != null) {
|
||||||
if ((msg.poseType & PoseMsg.Pose_Position) != 0)
|
if ((msg.poseType & PoseMsg.Pose_Position) != 0)
|
||||||
@ -332,9 +332,9 @@ namespace RoboidControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, BinaryMsg msg) {
|
protected virtual void Process(Participant sender, BinaryMsg msg) {
|
||||||
#if DEBUG
|
// #if DEBUG
|
||||||
Console.WriteLine($"Participant: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
// Console.WriteLine($"Participant: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
||||||
#endif
|
// #endif
|
||||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
thing?.ProcessBinary(msg.data);
|
thing?.ProcessBinary(msg.data);
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,6 @@ namespace RoboidControl {
|
|||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
protected List<Thing> children = new();
|
protected List<Thing> children = new();
|
||||||
|
|
||||||
|
|
||||||
private string _name = "";
|
private string _name = "";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the thing
|
/// The name of the thing
|
||||||
@ -235,6 +234,7 @@ namespace RoboidControl {
|
|||||||
set {
|
set {
|
||||||
if (_name != value) {
|
if (_name != value) {
|
||||||
_name = value;
|
_name = value;
|
||||||
|
nameChanged = true;
|
||||||
OnNameChanged?.Invoke();
|
OnNameChanged?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,6 +243,7 @@ namespace RoboidControl {
|
|||||||
/// Event which is triggered when the name changes
|
/// Event which is triggered when the name changes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event ChangeHandler OnNameChanged = delegate { };
|
public event ChangeHandler OnNameChanged = delegate { };
|
||||||
|
public bool nameChanged = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An URL pointing to the location where a model of the thing can be found
|
/// An URL pointing to the location where a model of the thing can be found
|
||||||
|
@ -48,7 +48,7 @@ namespace 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() {
|
||||||
System.Console.Write("Create touch sensor component");
|
// System.Console.Write("Create touch sensor component");
|
||||||
this.component = Unity.TouchSensor.Create(this);
|
this.component = Unity.TouchSensor.Create(this);
|
||||||
this.component.core = this;
|
this.component.core = this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user