ServerLauncher - jimdroberts/FishMMO GitHub Wiki

Description

Launches the server by preloading required scenes and handling addressable asset events. Supports command-line arguments for selecting server type and manages the initial loading of server scenes in the FishMMO infrastructure.


API Access

Fields

  • public string[] BootList

    List of default server scenes to boot if no command-line argument is provided.

Methods

  • public override void OnPreload()

    Called before the main load process. Sets up addressable asset event handlers and determines which scenes to load based on command-line arguments or BootList.

  • private void Close()

    Closes the server if an unknown server type is provided via command-line argument.

  • public override void OnDestroying()

    Called when the object is being destroyed. Unsubscribes from addressable asset events.

  • public void AddressableLoadProcessor_OnAddressableLoaded(Object addressable)

    Event handler called when an addressable asset is loaded. Adds the loaded object to the cache if it implements ICachedObject. addressable: Object - The loaded addressable Unity object.

  • public void AddressableLoadProcessor_OnAddressableUnloaded(Object addressable)

    Event handler called when an addressable asset is unloaded. Removes the object from the cache if it implements ICachedObject. addressable: Object - The unloaded addressable Unity object.


Basic Usage

Setup

  1. Attach ServerLauncher to a GameObject in the server bootstrap scene.
  2. Configure the BootList field to specify which server scenes should be loaded by default.
  3. The system will automatically handle addressable asset events and load the appropriate scenes based on command-line arguments or BootList.
  4. No manual scene loading is required; the launcher manages the process at startup.

Example

// Example 1: Configuring ServerLauncher
serverLauncher.BootList = new string[] { "LoginServer", "WorldServer" };

// Example 2: Handling addressable asset events
// The system automatically subscribes and unsubscribes from addressable asset events.

// Example 3: Command-line argument usage
// Launch the server with a specific type:
//   myserver.exe World

Best Practices

  • Use command-line arguments to control which server type is launched in production environments.
  • Keep the BootList up to date with all valid server scene names for your project.
  • Ensure addressable asset event handlers are unsubscribed in OnDestroying to prevent memory leaks.
  • Handle unknown server types gracefully by calling Close to shut down the server cleanly.
⚠️ **GitHub.com Fallback** ⚠️