Fix issue with things from different participants
This commit is contained in:
parent
ac11382479
commit
80c4983b34
@ -48,7 +48,11 @@ namespace RoboidControl.Unity {
|
|||||||
if (coreThing.component == null) {
|
if (coreThing.component == null) {
|
||||||
Thing[] things = FindObjectsByType<Thing>(FindObjectsSortMode.None);
|
Thing[] things = FindObjectsByType<Thing>(FindObjectsSortMode.None);
|
||||||
// Debug.Log(things.Length);
|
// Debug.Log(things.Length);
|
||||||
Thing thing = things.FirstOrDefault(t => t.core != null && t.core.id == coreThing.id);
|
Thing thing = things.FirstOrDefault(t =>
|
||||||
|
t.core != null &&
|
||||||
|
t.core.owner.networkId == coreThing.owner.networkId &&
|
||||||
|
t.core.id == coreThing.id
|
||||||
|
);
|
||||||
if (thing == null)
|
if (thing == null)
|
||||||
thing = Thing.Create(coreThing);
|
thing = Thing.Create(coreThing);
|
||||||
coreThing.component = thing;
|
coreThing.component = thing;
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace RoboidControl.Unity {
|
namespace RoboidControl.Unity {
|
||||||
|
|
||||||
public class SiteServer : Participant {
|
public class SiteServer : Participant {
|
||||||
|
|
||||||
//public RoboidControl.SiteServer site;
|
|
||||||
public RoboidControl.SiteServer site => this.coreParticipant as RoboidControl.SiteServer;
|
public RoboidControl.SiteServer site => this.coreParticipant as RoboidControl.SiteServer;
|
||||||
|
public string modelURL;
|
||||||
//public Queue<RoboidControl.Thing> thingQueue = new();
|
private RoboidControl.Thing model;
|
||||||
|
|
||||||
protected virtual void Awake() {
|
protected virtual void Awake() {
|
||||||
#if RC_DEBUG
|
#if RC_DEBUG
|
||||||
@ -18,11 +16,20 @@ namespace RoboidControl.Unity {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
this.coreParticipant = new RoboidControl.SiteServer(port);
|
this.coreParticipant = new RoboidControl.SiteServer(port);
|
||||||
|
|
||||||
|
#if GLTF
|
||||||
|
if (!string.IsNullOrEmpty(modelURL)) {
|
||||||
|
model = new() {
|
||||||
|
name = "Model",
|
||||||
|
modelUrl = this.modelURL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnApplicationQuit() {
|
void OnApplicationQuit() {
|
||||||
if (site != null)
|
if (site != null)
|
||||||
site.Close();
|
site.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update() {
|
protected override void Update() {
|
||||||
@ -33,8 +40,6 @@ namespace RoboidControl.Unity {
|
|||||||
HandleUpdateEvent(e);
|
HandleUpdateEvent(e);
|
||||||
|
|
||||||
site.Update();
|
site.Update();
|
||||||
// while (thingQueue.TryDequeue(out RoboidControl.Thing thing))
|
|
||||||
// thing.CreateComponent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleUpdateEvent(RoboidControl.Participant.UpdateEvent e) {
|
private void HandleUpdateEvent(RoboidControl.Participant.UpdateEvent e) {
|
||||||
@ -46,6 +51,10 @@ namespace RoboidControl.Unity {
|
|||||||
participant.coreParticipant.component = participant;
|
participant.coreParticipant.component = participant;
|
||||||
participant.ipAddress = e.participant.ipAddress;
|
participant.ipAddress = e.participant.ipAddress;
|
||||||
participant.port = e.participant.port;
|
participant.port = e.participant.port;
|
||||||
|
|
||||||
|
foreach (RoboidControl.Thing thing in this.site.things)
|
||||||
|
participant.coreParticipant.SendThingInfo(thing);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ThingMsg.id:
|
case ThingMsg.id:
|
||||||
HandleThingEvent(e);
|
HandleThingEvent(e);
|
||||||
|
@ -191,6 +191,14 @@ namespace RoboidControl {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendThingInfo(Thing thing) {
|
||||||
|
this.Send(new ThingMsg(thing.owner.networkId, thing));
|
||||||
|
this.Send(new NameMsg(thing.owner.networkId, thing));
|
||||||
|
this.Send(new ModelUrlMsg(thing.owner.networkId, thing));
|
||||||
|
this.Send(new PoseMsg(thing.owner.networkId, thing));
|
||||||
|
this.Send(new BinaryMsg(thing.owner.networkId, thing));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Send
|
#endregion Send
|
||||||
|
|
||||||
#region Participant Registry
|
#region Participant Registry
|
||||||
|
@ -232,14 +232,6 @@ namespace RoboidControl {
|
|||||||
|
|
||||||
#region Send
|
#region Send
|
||||||
|
|
||||||
public void SendThingInfo(Participant owner, Thing thing) {
|
|
||||||
owner.Send(new ThingMsg(this.networkId, thing));
|
|
||||||
owner.Send(new NameMsg(this.networkId, thing));
|
|
||||||
owner.Send(new ModelUrlMsg(this.networkId, thing));
|
|
||||||
owner.Send(new PoseMsg(this.networkId, thing));
|
|
||||||
owner.Send(new BinaryMsg(this.networkId, thing));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PublishThingInfo(Thing thing) {
|
public void PublishThingInfo(Thing thing) {
|
||||||
// Console.WriteLine("Publish thing info");
|
// Console.WriteLine("Publish thing info");
|
||||||
this.Publish(new ThingMsg(this.networkId, thing));
|
this.Publish(new ThingMsg(this.networkId, thing));
|
||||||
@ -386,7 +378,7 @@ namespace RoboidControl {
|
|||||||
if (this.networkId != msg.networkId) {
|
if (this.networkId != msg.networkId) {
|
||||||
this.networkId = msg.networkId;
|
this.networkId = msg.networkId;
|
||||||
foreach (Thing thing in this.things) //Thing.GetAllThings())
|
foreach (Thing thing in this.things) //Thing.GetAllThings())
|
||||||
this.SendThingInfo(sender, thing);
|
sender.SendThingInfo(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user