diff --git a/Runtime/HumanoidControl/Scripts/Networking/Roboid/ControlCore/Messages.cs b/Runtime/HumanoidControl/Scripts/Networking/Roboid/ControlCore/Messages.cs index ecf47f9..fece487 100644 --- a/Runtime/HumanoidControl/Scripts/Networking/Roboid/ControlCore/Messages.cs +++ b/Runtime/HumanoidControl/Scripts/Networking/Roboid/ControlCore/Messages.cs @@ -168,8 +168,8 @@ namespace Passer.Control { this.thingId = buffer[ix++]; } - public static bool Send(Client client, byte thingId) { - InvestigateMsg msg = new(client.networkId, thingId); + public static bool Send(Client client, byte networkId, byte thingId) { + InvestigateMsg msg = new(networkId, thingId); return SendMsg(client, msg); } public static async Task Receive(Stream dataStream, Client client, byte packetSize) { @@ -406,7 +406,6 @@ namespace Passer.Control { return SendMsg(client, msg); } public static async Task Receive(Stream dataStream, Client client, byte packetSize) { - UnityEngine.Debug.Log("Receive pose"); if (packetSize != length) return false; diff --git a/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs b/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs index c9d3d88..8ab4d0b 100644 --- a/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs +++ b/Runtime/HumanoidControl/Scripts/Networking/Roboid/HumanoidPlayerRoboid.cs @@ -128,6 +128,7 @@ namespace Passer.Humanoid { public class HumanoidClient : Client { readonly HumanoidPlayer player; + public List allThings = new(); public HumanoidClient(UdpClient udpClient, string ipAddress, int port, HumanoidPlayer player) : base(udpClient, port) { this.player = player; @@ -141,7 +142,12 @@ namespace Passer.Humanoid { player.ProcessNetworkId(this, msg); } + protected override void ProcessName(NameMsg msg) { + Debug.Log($"Name [{msg.networkId}/{msg.thingId} {msg.name}]"); + } + protected override void ProcessModelUrl(ModelUrlMsg msg) { + Debug.Log($"Model [{msg.networkId}/{msg.thingId} {msg.url}]"); int ix = msg.url.LastIndexOf("."); if (ix < 0) return; @@ -153,6 +159,16 @@ namespace Passer.Humanoid { player.ProcessGltfModel(msg); } } + + protected override void ProcessPose(PoseMsg msg) { + Debug.Log($"Pose [{msg.networkId}/{msg.thingId}]"); + Thing thing = allThings.Find(thing => thing.networkId == msg.networkId && thing.thingId == msg.thingId); + if (thing == null) { + Debug.Log($"Unknown thing [{msg.networkId}/{msg.thingId}]"); + thing = Thing.Create(player.gameObject, this, msg.thingId, 0); + InvestigateMsg.Send(this, msg.networkId, msg.thingId); + } + } } protected virtual void Awake() { diff --git a/Runtime/HumanoidControl/Scripts/Networking/Roboid/Thing.cs b/Runtime/HumanoidControl/Scripts/Networking/Roboid/Thing.cs new file mode 100644 index 0000000..7cf3c7d --- /dev/null +++ b/Runtime/HumanoidControl/Scripts/Networking/Roboid/Thing.cs @@ -0,0 +1,44 @@ +using UnityEngine; +using Passer.Control; + +public class Thing : MonoBehaviour { + public Client client; + public byte networkId; + public byte thingId; + public byte objectType; + //protected Sensor sensor; + + protected virtual void Init() { + //if (this.objectType == 2) { + // sensor = this.gameObject.AddComponent(); + // sensor.thing = this; + //} + } + + public static Thing Create(GameObject obj, Client client, byte objId, byte objType) { + Thing thing = obj.AddComponent(); + thing.client = client; + thing.thingId = objId; + thing.objectType = objType; + thing.networkId = client.networkId; + thing.Init(); + + return thing; + } + + public virtual Thing CopyTo(GameObject obj) { + //Debug.Log($"copy {obj}"); + Thing foundThing = Thing.Create(obj, this.client, this.thingId, this.objectType); + Destroy(this.gameObject); + return foundThing; + } + + //public void ProcessBytes(byte[] bytes) { + // if (sensor != null) + // sensor.ProcessBytes(bytes); + //} + //public void Update() { + // if (objectId == 0) + // Debug.Log(this.transform.eulerAngles); + //} +} diff --git a/Runtime/HumanoidControl/Scripts/Networking/Roboid/Thing.cs.meta b/Runtime/HumanoidControl/Scripts/Networking/Roboid/Thing.cs.meta new file mode 100644 index 0000000..2abfee7 --- /dev/null +++ b/Runtime/HumanoidControl/Scripts/Networking/Roboid/Thing.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: dbfb00fc659e2d8489a48aafec5ddfc5 \ No newline at end of file