f31ffe910b
Netcode frontend pattern: UITK main menu / pause / settings (MenuUi + controllers), on-demand world lifecycle (WorldLauncher/SessionRunner), GameBootstrap menu branch; Graphics/Audio settings (SettingsService/GameVolume); single-slot save foundation (SaveData/SaveService, born-correct load at director spawn, autosave on Siege->Calm + quit); RuntimePanelSettings + theme; BuildTool menu; 10 EditMode tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
2.7 KiB
C#
55 lines
2.7 KiB
C#
using Unity.Entities;
|
|
using Unity.NetCode;
|
|
using UnityEngine.Scripting;
|
|
|
|
namespace ProjectM.Simulation
|
|
{
|
|
/// <summary>
|
|
/// Custom Netcode for Entities bootstrap. Subclassing <see cref="ClientServerBootstrap"/> gives an
|
|
/// explicit hook to customize world creation, tick rate, and connection.
|
|
/// <para>
|
|
/// M4 (LAN co-op): auto-connect is DISABLED (<see cref="ClientServerBootstrap.AutoConnectPort"/> = 0).
|
|
/// Listening/connecting is driven explicitly via the <see cref="ConnectionConfig"/> singleton and the
|
|
/// per-world ConnectionControlSystems — from the UITK frontend menu (<c>MainMenuController</c> → <c>WorldLauncher</c>, Host / Join + IP) in player builds,
|
|
/// or from the editor-only <c>EditorAutoHostSystem</c>, 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.
|
|
/// </para>
|
|
/// </summary>
|
|
[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
|
|
}
|
|
}
|
|
}
|