#if UNITY_EDITOR
using Unity.Entities;
using Unity.NetCode;
namespace ProjectM.Simulation
{
///
/// EDITOR-ONLY dev convenience for the M4 LAN flow. With auto-connect disabled in GameBootstrap,
/// this seeds a in each world on its first update so entering Play "just
/// works" multi-client: the server world hosts on loopback and every client / thin-client world joins
/// it — reproducing the old single-key playflow but for N players. Runs once per world then disables
/// itself, and skips seeding if a already exists (e.g. set by
/// ConnectionUI). Does not exist in player builds.
///
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation | WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial struct EditorAutoHostSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
state.Enabled = false; // run exactly once per world
if (SystemAPI.HasSingleton())
return;
const ushort port = 7979;
var cfg = state.WorldUnmanaged.IsServer()
? new ConnectionConfig { Mode = ConnectionMode.Host, Address = "127.0.0.1", Port = port, Requested = true }
: new ConnectionConfig { Mode = ConnectionMode.Join, Address = "127.0.0.1", Port = port, Requested = true };
var e = state.EntityManager.CreateEntity();
state.EntityManager.AddComponentData(e, cfg);
}
}
}
#endif