#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 RoboidControl.SiteServer site => this.coreParticipant as RoboidControl.SiteServer; //public Queue thingQueue = new(); protected virtual void Awake() { Console.SetOut(new UnityLogWriter()); this.coreParticipant = new RoboidControl.SiteServer(port); } void OnApplicationQuit() { if (site != null) site.Close(); } protected override void Update() { if (site == null) return; while (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: HandleThingEvent(e); break; } } } } #endif