Skip to main content

Event Manager

1. Overview

The EventManager handles all real-time synchronization of scene interactions, physics, and custom gameplay messages between clients in a session. While the Session Manager handles "who is in the room", the Event Manager handles "what are they doing".


2. EventManagerController (High-Level API)

The EventManagerController is a Singleton that manages strongly-typed message forwarding.

2.1. Strongly-Typed Message System

To avoid manually parsing strings everywhere in the codebase, the Controller uses a MessageForwarderManager.

  • Developers define custom C# classes inheriting from BaseMessage (e.g., RigidbodySyncMessage).
  • RegisterEventType(MessageTypeID, Type) binds an ID to the class.
  • Subscribe<T>(Action<T>) allows any script to listen for specific strongly-typed messages seamlessly.

2.2. Sending Data

  • SendSceneEventToAll<T>(T _data): Serializes a BaseMessage into JSON and broadcasts it to every user in the room.
  • SendSceneEventToMaster<T>(T _data): Sends the event exclusively to the Session Master, useful for authoritative validation (like the ).

3. EventManagerWrapper (Low-Level Transport Layer)

The EventManagerWrapper maintains the Socket.IO connection to the /events/{sessionId} namespace.

3.1. SceneEvent Structure

Instead of managing hundreds of custom Socket.IO event names, HoloMIT wraps all general gameplay logic inside a universal SceneEvent socket message:

  • SceneEvent (Socket Name): The master socket event.
    • TypeId (int): Determines which C# struct the payload belongs to.
    • Data (string): The serialized JSON payload of the actual message.

3.2. High-Frequency Data

It also handles dedicated, highly-optimized pipelines for high-frequency data, such as:

  • PlayerTransformSyncData: Specifically structured for sending rapid player movement updates without the overhead of standard scene events.

4. Integration Example

// 1. Define Message
public class MyCustomMessage : BaseMessage { public string Text; }

// 2. Register (usually on Awake)
EventManagerController.Instance.RegisterEventType(MessageTypeID.CustomEvent, typeof(MyCustomMessage));

// 3. Send
EventManagerController.Instance.SendSceneEventToAll(new MyCustomMessage { Text = "Hello" });