RoboidControl-csharp/Unity/SiteServer.cs
2025-02-11 17:56:01 +01:00

38 lines
864 B
C#

#if UNITY_5_3_OR_NEWER
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Passer.Control.Unity {
public class SiteServer : MonoBehaviour {
public Core.SiteServer site;
public Queue<Core.Thing> thingQueue = new();
protected virtual void Awake() {
Console.SetOut(new UnityLogWriter());
site = new(7681);
Core.Thing.OnNewThing += HandleNewThing;
}
void OnApplicationQuit() {
site.Close();
}
public void HandleNewThing(Core.Thing thing) {
thingQueue.Enqueue(thing);
}
protected virtual void Update() {
site.Update((ulong)(Time.time * 1000));
if (thingQueue.TryDequeue(out Core.Thing thing)) {
thing.CreateComponent();
}
}
}
}
#endif