diff --git a/Unity/SiteServer.cs b/Unity/SiteServer.cs index 3226edc..c067844 100644 --- a/Unity/SiteServer.cs +++ b/Unity/SiteServer.cs @@ -41,6 +41,7 @@ namespace RoboidControl.Unity { GameObject remoteParticipant = new GameObject("RemoteParticipant"); Participant participant = remoteParticipant.AddComponent(); participant.coreParticipant = e.participant; + participant.coreParticipant.component = participant; break; case ThingMsg.id: HandleThingEvent(e); diff --git a/Unity/Thing.cs b/Unity/Thing.cs index 8947915..03ac532 100644 --- a/Unity/Thing.cs +++ b/Unity/Thing.cs @@ -46,13 +46,18 @@ namespace RoboidControl.Unity { protected void Init(RoboidControl.Thing core) { this.core = core; this.core.component = this; - this.owner = FindAnyObjectByType(); - core.owner = this.owner.coreParticipant; + // This is wrong, it should get the owner, which is not the siteserver + // this.owner = FindAnyObjectByType(); + // core.owner = this.owner.coreParticipant; + this.owner = core.owner.component; if (core.parent != null && core.parent.component != null) { this.transform.SetParent(core.parent.component.transform, false); this.transform.localPosition = Vector3.zero; } + else { + this.transform.SetParent(core.owner.component.transform, false); + } if (core.position != null) this.transform.localPosition = core.position.ToVector3(); @@ -108,7 +113,7 @@ namespace RoboidControl.Unity { case ThingMsg.id: Debug.Log($"{this.core.id} Handle Thing"); if (core.parent == null) - this.transform.SetParent(null, true); + this.transform.SetParent(core.owner.component.transform, true); else if (core.parent.component != null) this.transform.SetParent(core.parent.component.transform, true); break; diff --git a/src/Participant.cs b/src/Participant.cs index 3276855..d1588e9 100644 --- a/src/Participant.cs +++ b/src/Participant.cs @@ -52,6 +52,14 @@ namespace RoboidControl { /// public int port = 0; +#if UNITY_5_3_OR_NEWER + /// + /// A reference to the representation of the thing in Unity + /// + [NonSerialized] + public Unity.Participant component = null; +#endif + public UdpClient udpClient = null; ///