diff --git a/Unity/Thing.cs b/Unity/Thing.cs index 129f34b..4aeb8bd 100644 --- a/Unity/Thing.cs +++ b/Unity/Thing.cs @@ -19,10 +19,6 @@ namespace RoboidControl.Unity { private string modelUrl = null; - // protected virtual void Awake() { - // core.OnPoseChanged += PoseChanged; - // } - /// /// Set the core C# thing /// @@ -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(); diff --git a/src/Messages/BinaryMsg.cs b/src/Messages/BinaryMsg.cs index d9ab9f2..676ed41 100644 --- a/src/Messages/BinaryMsg.cs +++ b/src/Messages/BinaryMsg.cs @@ -21,8 +21,8 @@ namespace RoboidControl { /// The ID of the thing /// public byte thingId; - - public Thing thing; + + public Thing thing; /// /// The length of the data /// @@ -56,12 +56,12 @@ namespace RoboidControl { } /// @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) 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; diff --git a/src/Messages/PoseMsg.cs b/src/Messages/PoseMsg.cs index 1a1e5f2..09eb5cd 100644 --- a/src/Messages/PoseMsg.cs +++ b/src/Messages/PoseMsg.cs @@ -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; diff --git a/src/ParticipantUDP.cs b/src/ParticipantUDP.cs index 7d8b27b..e670ad7 100644 --- a/src/ParticipantUDP.cs +++ b/src/ParticipantUDP.cs @@ -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); } diff --git a/src/Thing.cs b/src/Thing.cs index 00a2020..5f06818 100644 --- a/src/Thing.cs +++ b/src/Thing.cs @@ -225,7 +225,6 @@ namespace RoboidControl { [NonSerialized] protected List children = new(); - private string _name = ""; /// /// 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 /// public event ChangeHandler OnNameChanged = delegate { }; + public bool nameChanged = false; /// /// An URL pointing to the location where a model of the thing can be found diff --git a/src/Things/TouchSensor.cs b/src/Things/TouchSensor.cs index c1a7fd0..7fac61b 100644 --- a/src/Things/TouchSensor.cs +++ b/src/Things/TouchSensor.cs @@ -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; }