#if UNITY_5_3_OR_NEWER using System; using System.Collections.Generic; using UnityEngine; namespace RoboidControl.Unity { public class SiteServer : Participant { public RoboidControl.SiteServer site; public Queue thingQueue = new(); protected virtual void Awake() { Console.SetOut(new UnityLogWriter()); site = new RoboidControl.SiteServer(port); } void OnApplicationQuit() { if (site != null) site.Close(); } protected override void Update() { if (site == null) return; if (site.updateQueue.TryDequeue(out RoboidControl.Participant.UpdateEvent e)) HandleUpdateEvent(e); site.Update((ulong)(Time.time * 1000)); while (thingQueue.TryDequeue(out RoboidControl.Thing thing)) thing.CreateComponent(); } private void HandleUpdateEvent(RoboidControl.Participant.UpdateEvent e) { switch (e.messageId) { case ParticipantMsg.Id: GameObject remoteParticipant = new GameObject("RemoteParticipant"); Participant participant = remoteParticipant.AddComponent(); participant.coreParticipant = e.participant; break; case ThingMsg.id: e.thing.CreateComponent(); break; } } } } #endif