using Unity.Entities; using Unity.NetCode; using UnityEngine.Scripting; namespace ProjectM.Simulation { /// /// Custom Netcode for Entities bootstrap. Subclassing gives an /// explicit hook to customize world creation, tick rate, and connection. /// /// M4 (LAN co-op): auto-connect is DISABLED ( = 0). /// Listening/connecting is driven explicitly via the singleton and the /// per-world ConnectionControlSystems — from the UITK frontend menu (MainMenuControllerWorldLauncher, Host / Join + IP) in player builds, /// or from the editor-only EditorAutoHostSystem, which auto-hosts on loopback and connects the /// in-proc client plus any Multiplayer-PlayMode-Tools thin clients. Direct IP/LAN only for now; Unity /// Relay is deferred to a later pass. /// /// [Preserve] public class GameBootstrap : ClientServerBootstrap { public override bool Initialize(string defaultWorldName) { // No auto-connect: the menu (or, in the editor, the auto-host system) owns listen/connect. AutoConnectPort = 0; #if UNITY_EDITOR // Editor: keep today's instant-into-game + MPPM loop by DEFAULT. Only the MAIN editor // (ClientAndServer) with the "Boot Into Menu (Editor)" toggle ON takes the frontend path, so MPPM // virtual players (Client) never boot to the menu. Open MainMenu.unity + Play to test the menu. bool bootMenu = UnityEditor.EditorPrefs.GetBool("ProjectM.BootIntoMenu", false) && RequestedPlayType == PlayType.ClientAndServer; if (!bootMenu) { CreateDefaultClientServerWorlds(); return true; } return false; // Frontend: Entities makes a single default "menu" world; MainMenuController drives sessions. #else // Player build: a dedicated/headless server auto-hosts; everyone else boots the front-end menu. if (RequestedPlayType == PlayType.Server) { var server = CreateServerWorld("ServerWorld"); World.DefaultGameObjectInjectionWorld = server; var em = server.EntityManager; var e = em.CreateEntity(); em.AddComponentData(e, new ConnectionConfig { Mode = ConnectionMode.Host, Address = "0.0.0.0", Port = 7979, Requested = true }); return true; } return false; // Frontend menu (MainMenu.unity is build index 0). #endif } } }