Overview of Systems
General explanations for all systems will be written soon.
Room Manager
Introduction
The system is designed to facilitate dynamic room creation, management, and interactions within multiplayer games.
Core Purpose
The Room Management System is designed to provide game developers with the ability to dynamically create and manage rooms in multiplayer games. The system supports fundamental features such as room creation, player joining, network connection management, and in-room interactions.
Key Features
1. Room Creation and Joining
Room Creation: The system allows for the creation of a specific game room with parameters such as room name and maximum player count.
Room Joining: Players can join existing rooms based on specific criteria, such as room name.
2. Network Management
Using Mirror: The Mirror library is employed to manage network connections and facilitate multiplayer interactions.
3. Synchronization and Interaction
Player Synchronization: Synchronization among players within a game room is managed over the network.
Interaction Management: The system enables player interactions with each other and the game world.
4. Security and Error Handling
Error Handling: The system addresses error scenarios during room creation or joining and provides user feedback.
Security Measures: Anti-cheat and security measures are implemented by the system.
5. Room Management
Room Deletion: Rooms can be deleted under certain conditions, either by the room owner or as defined by the system.
Updating Room Status: Room status, such as the number of players, is continuously updated by the system.
Usage
Game developers can utilize this system to create flexible and dynamic room structures in their multiplayer games.
Example Usage
Conclusion
This room management system, aims to provide Mirror users with effective room management capabilities for multiplayer games. With its core features, developers can create more flexible and dynamic multiplayer experiences in their games.
Room Container
The Room Container System is designed to streamline the management of singleton instances and event listeners within specific rooms in a multiplayer game. It ensures unique singleton instances per room and facilitates event communication. Here's a concise overview:
Purpose:
Singleton Management:
Ensures only one instance of a specific type exists in a room.
Provides methods to add, remove, and retrieve singleton instances.
Listener Management:
Enables registration and unregistration of event listeners for room-specific events.
Enhances communication within a room.
How to Use:
Singleton Management with
RoomContainerHelper
:Add Singleton:
AddSingleton<T>(value)
- Adds a singleton instance of type T to the Room Container.Remove Singleton:
RemoveSingleton<T>()
- Removes a singleton instance of type T from the Room Container.Get Singleton:
GetSingleton<T>()
- Retrieves a singleton instance of type T from the Room Container.
Listener Management with
RoomContainerHelper
:Register Listener:
RegisterListener<T>(listener)
- Registers a listener to receive updates from a room.Unregister Listener:
UnregisterListener<T>(listener)
- Unregisters a listener from a room.
Example Usage:
Benefits:
Organization: Keeps singleton instances organized per room.
Communication: Enhances communication by facilitating listener registration for room-specific events.
Singleton Integrity: Ensures singleton uniqueness within each room.
Conclusion
The Room Container System simplifies multiplayer game development by providing a structured approach to manage resources and events within specific game rooms.
Room Loader
The Room Loader System facilitates the loading and unloading of game rooms. It offers flexibility through different loading strategies. Here's a brief summary of its components:
IRoomLoader
Interface:Load Room: Loads a specified room using room information.
Unload Room: Unloads a specified room.
RoomLoaderType
Enum:NoneScene: No scene loading required.
SingleScene: Loads a single scene for the room.
AdditiveScene: Loads additional scenes for the room.
SceneRoomLoader
Class:Purpose: Loads a room by loading its associated scene.
How to Use:
Create an instance.
Call
LoadRoom
to load a room with specified info.Call
UnLoadRoom
to unload the room.
NoneSceneRoomLoader
Class:Purpose: Represents a loader where no scene loading is required.
How to Use:
Create an instance.
Call
LoadRoom
for any loading actions.Call
UnLoadRoom
for any unloading actions.
Benefits:
Abstraction: Hides scene loading details.
Flexibility: Supports different loading strategies.
Usage Examples:
Using SceneRoomLoader
for loading a room:
Using NoneSceneRoomLoader
for a room without scene loading:
The Room Loader System simplifies room transitions, offering a clear interface and flexibility in loading strategies.
Services
RoomServer
RoomServer
is a static class acting as a service, facilitating server-side operations related to game rooms. It abstracts and simplifies the interaction with the underlying RoomManagerBase
for managing rooms and scenes.
Key Features:
Room Transactions:
Create Room: Creates a room with specified information (name, scene, max players, custom data).
Join Room: Allows a client to join a room.
Exit Room: Handles a client exiting a room, considering disconnection status.
Remove Room: Removes a specific room or all rooms forcibly if needed.
Scene Operations:
Change Scene: Changes the scene for a specified room, providing an option to keep client objects.
How to Use:
Create a Room:
Call
CreateRoom
with necessary parameters.Optionally, specify a
NetworkConnectionToClient
if applicable.
Join a Room:
Call
JoinRoom
with the room name.Optionally, provide a
NetworkConnectionToClient
if needed.
Exit a Room:
Call
ExitRoom
with aNetworkConnectionToClient
and disconnection status.
Remove a Room:
Call
RemoveRoom
with the room name and specify if removal is forced.
Remove All Rooms:
Call
RemoveAllRoom
and specify if removal is forced.
Change Scene:
Call
ChangeScene
with the room name and the new scene name.Optionally, provide a
Room
instance for more control.
Example Usage:
Creating a room and joining:
Changing the scene for a room:
RoomServer
simplifies room management on the server, offering a convenient and clear API for common operations.
Room Client
RoomClient
is a static class serving as a client-side service for room-related operations. It encapsulates functionality provided by the underlying RoomManagerBase
for ease of use.
Key Features:
Room Transactions:
Create Room: Initiates a request to create a room with specified parameters.
Join Room: Initiates a request to join a room by its name.
Exit Room: Initiates a request to exit the current room.
Data Methods:
Get Room Custom Data: Retrieves custom data associated with the current room.
How to Use:
Create a Room:
Call
CreateRoom
with the necessary parameters (name, scene, max players).Optionally, specify custom data or privacy settings.
Join a Room:
Call
JoinRoom
with the name of the room to join.
Exit a Room:
Call
ExitRoom
to leave the current room.Optionally, provide a parameter indicating if the exit is due to disconnection.
Retrieve Room Custom Data:
Call
GetRoomCustomData
with the desired custom data name.Returns the value associated with the specified custom data name.
Example Usage:
Creating a room and joining:
Exiting a room:
Retrieving room custom data:
RoomClient
simplifies client-side interactions with rooms, providing a straightforward API for common operations such as creating, joining, and exiting rooms.
Scene Manager
ReflectiveSceneManager
is a static class designed to manage scene-related operations in a flexible and event-driven manner.
How to Use:
Load a Scene:
Call
LoadScene
with the name of the scene to load.Optionally, provide a callback function to be executed upon completion.
Subscribe to
OnSceneLoaded
event to be notified when the scene has finished loading.
Unload a Scene:
Call
UnLoadScene
with the scene to unload.Optionally, provide a callback function to be executed upon completion.
Subscribe to
OnSceneUnloaded
event to be notified when the scene has finished unloading.
Initialization:
The class automatically initializes the
SceneProcessor
based on the configuredRoomLoaderType
during runtime.
Example Usage:
Loading a scene:
Unloading a scene:
ReflectiveSceneManager
simplifies the process of loading and unloading scenes in Unity, providing an event-driven approach for handling completion events and allowing customization of the scene loading strategy.
Scene Processor
The Scene Processor system is responsible for managing scene loading and unloading operations in Unity. It utilizes the Factory pattern to create different processors based on the specified room loader type. The processors, implemented as SceneProcessor
classes, handle the actual loading and unloading tasks.
How to Use:
Scene Processor Factory:
Call
SceneProcessorFactory.Create
with the desiredRoomLoaderType
to get an instance ofSceneProcessor
.
Scene Loading/Unloading:
Call
LoadScene
orUnLoadScene
on the obtainedSceneProcessor
instance.Optionally provide a callback function to execute upon completion.
Subscribe to
ReflectiveSceneManager.OnSceneLoaded
orReflectiveSceneManager.OnSceneUnloaded
events for additional notifications.
Processing Scenes:
Call the
Process
method on theSceneProcessor
instance to start processing scene loading tasks.Use the
GetLoadingState
method to check the loading state.
Example Usage:
Creating a Scene Processor:
Loading a Scene:
Unloading a Scene:
Processing Scenes:
The Scene Processor system provides a modular and extensible solution for handling scene-related operations in Unity, accommodating different loading strategies based on the room loader type.
Scene Loader
The Scene Loader system provides a simplified interface for initiating scene loading and unloading operations in Unity. It utilizes a MonoBehaviourHook
to start coroutines for processing scene-related tasks.
How to Use:
Initialization:
The
SceneLoader
initializes by creating aMonoBehaviourHook
if not already present.
Loading a Scene:
Call the
LoadScene
method to initiate the loading process.The method checks if the scene processor is already loading a scene.
If not, it starts the coroutine to process scene-related tasks asynchronously.
Unloading a Scene:
Call the
UnloadScene
method to initiate the unloading process.The method checks if the scene processor is already loading a scene.
If not, it starts the coroutine to process scene-related tasks asynchronously.
Example Usage:
Loading a Scene:
Unloading a Scene:
Benefits:
Provides a centralized interface for scene loading and unloading.
Simplifies the initiation of scene-related tasks.
Ensures that scene loading is not triggered while another loading operation is in progress.
Considerations:
Developers need to ensure that the
ReflectiveSceneManager.Processor
is set before using theSceneLoader
.Initialization occurs automatically when using the
LoadScene
orUnloadScene
methods.
The Scene Loader system abstracts the complexities of starting coroutines and managing the initialization of required components, offering a straightforward approach to scene-related operations in Unity.
Physic Simulator
The Physics Simulator system provides a flexible and modular approach to handling physics simulations in Unity. It consists of a PhysicSimulator
component and a set of simulator classes for 2D and 3D physics. The system is designed to be network-aware, allowing for server-only or client-only physics simulations.
How to Use:
PhysicSimulator Component:
Attach the
PhysicSimulator
component to a GameObject in the scene.Configure the component in the Inspector, setting the
_isOnlyServer
flag if needed.
Initialization:
The
PhysicSimulator
component automatically initializes based on the physics mode and network context.The factory class creates the appropriate
Simulator
instance.
Physics Updates:
The
FixedUpdate
method of the associatedSimulator
is automatically called during the FixedUpdate phase.Physics simulations are executed based on the selected physics mode (2D or 3D).
Example Usage:
Benefits:
Modular design allows easy extension for different physics modes.
Network-aware, enabling server-only or client-only physics simulations.
Centralized factory class simplifies the creation of simulator instances.
Considerations:
Developers need to ensure that the physics scene is appropriately set up in Unity.
The
_isOnlyServer
flag can be used to enable physics simulations only on the server or client.
The Physics Simulator system provides a convenient way to handle physics simulations in Unity, offering flexibility for different physics modes and network contexts.
Utilities
Network Spawn Utilities
The NetworkSpawnUtilities
class provides a set of utility methods for spawning networked GameObjects in Unity using the Unity Networking system. These methods simplify the process of instantiating and synchronizing objects across the network, and they also include functionality for spawning objects in specific scenes.
How to Use:
SpawnObject Methods:
Call one of the
SpawnObject
methods to instantiate and spawn a networked GameObject.Pass the GameObject prefab to be spawned and optional parameters such as parent, position, rotation, and network connection.
SpawnObjectForScene Methods:
Similar to
SpawnObject
but also moves the spawned object to a specified scene.
GetSpawnablePrefabs:
Call
GetSpawnablePrefabs
to retrieve a collection of spawnable prefabs from the "SpawnablePrefabs" resource folder.Useful for dynamically loading available prefabs for spawning.
Example Usage:
Benefits:
Simplifies the process of spawning networked objects in Unity.
Handles the synchronization of spawned objects across the network.
Provides a convenient way to organize and retrieve spawnable prefabs.
Considerations:
Ensure that the NetworkManager is set up and running in the scene.
The "SpawnablePrefabs" resource folder should contain prefabs that can be instantiated across the network.
The NetworkSpawnUtilities
class streamlines the spawning of networked GameObjects, contributing to a more efficient and organized Unity networking workflow.
Room List Utilities
The RoomListUtility
class provides utility methods for managing and updating a list of rooms in a networked multiplayer game. These methods focus on converting room information, updating, adding, and removing rooms from a list, and sending corresponding messages to notify clients about room changes.
How to Use:
ConvertToRoomList:
Call
ConvertToRoomList
to convert aRoom
object to aRoomInfo
object.
UpdateRoomToList:
Call
UpdateRoomToList
to update an existing room in the list with new information.
AddRoomToList:
Call
AddRoomToList
to add a new room to the list.
RemoveRoomToList:
Call
RemoveRoomToList
to remove a room from the list.
Example Usage:
Benefits:
Simplifies the process of managing and updating a list of rooms in a multiplayer game.
Provides a standardized way to convert room information for communication with clients.
Considerations:
Ensure that the
RoomMessageUtility
class is appropriately implemented to handle room update messages.
The RoomListUtility
class facilitates the management of room lists in a networked game, making it easier to handle updates, additions, and removals of rooms, and ensuring proper communication with connected clients.
Room Message Utilities
The RoomMessageUtility
class provides utility methods for sending room-related messages in a networked multiplayer game. It includes methods to send room update messages to all connected clients and to send specific room messages to individual clients.
How to Use:
SendRoomUpdateMessage:
Call
SendRoomUpdateMessage
when you want to notify all connected clients about a change in the room list.Provide the
RoomInfo
representing the updated room and theRoomMessageState
indicating the type of change (add, update, remove).
SendRoomMessage:
Call
SendRoomMessage
when you want to send a specific room-related message to an individual client.Provide the
NetworkConnection
of the target client and theClientRoomState
representing the specific state.
Example Usage:
Benefits:
Provides a centralized utility for sending room-related messages, promoting consistency in message construction and delivery.
Simplifies the process of notifying clients about changes in the room list or sending specific room-related messages.
Considerations:
Ensure that the
RoomListChangeMessage
andClientRoomMessage
classes are correctly implemented and that the message types align with the expected behavior in the client application.The implementation assumes the usage of the Unity Networking framework (
NetworkServer
andNetworkConnection
). Adjustments may be needed based on the networking library in use.
The RoomMessageUtility
class serves as a convenient tool for handling room-related communication in a networked multiplayer game, offering methods to broadcast room updates to all clients or send specific messages to individual clients.
Last updated