RoboidControl-csharp/Unity/SiteServer.cs
Pascal Serrarens 86ff02a110 Working ants
2025-02-18 15:05:07 +01:00

37 lines
898 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) {
site.Add(thing, false);
thingQueue.Enqueue(thing);
}
protected virtual void Update() {
site.Update((ulong)(Time.time * 1000));
while (thingQueue.TryDequeue(out Core.Thing thing))
thing.CreateComponent();
}
}
}
#endif