Events Manager Architecture Technical
The Events Manager is a distributed system designed to handle real-time game events, leaderboards, and goal tracking. It operates on a client-server model where Unity clients communicate with a PHP/MySQL backend.
System Components
- Client Runtime (Singleton):
bl_GameEventManagerhandles data synchronization, polling, and state management in the game. - Admin/Editor Manager:
bl_EventManagerallows developers/admins to create and manage events from the Unity Editor or a dedicated Admin build. - Configuration:
bl_EventManagerSettings(ScriptableObject) centralizes connection settings, timeouts, and logging policies. - Backend:
bl_EventManager.phpacts as the API gateway, interfacing with the MySQL database.
Data Flow
- Initialization: Client connects to the PHP backend using the URL defined in
bl_LoginProDataBaseor manual configuration. - Polling:
bl_GameEventManagerperiodically polls for active events (default: 30s). - Event State: When an event is active, the client receives
EventDetails(Goals, XP Boosts, End Time). - Interaction: Player actions (Kills/Wins) are sent to the server to update the live leaderboard.
Installation & Setup
1. Server-Side Setup
Upload the PHP files to your web server.
├── bl_Common.php (Required dependency)
├── bl_EventManager.php
└── ...
bl_game_events table on the first API call if it doesn't exist. Ensure your database user has CREATE TABLE permissions.
2. Unity Setup
- Import the EventsManager package into your project.
- Locate the EventManagerSettings asset in
Resources/EventManagerSettings.asset. - Ensure TextMeshPro is installed in your project.
Configuration
The system is configured primarily through the bl_EventManagerSettings ScriptableObject.
Settings Asset
| Setting | Type | Description | Default |
|---|---|---|---|
| Connection Timeout | Float | Max time (seconds) to wait for server response. | 5.0 |
| Max Retries | Int | Number of retry attempts for failed requests. | 3 |
| Update Interval | Float | Frequency (seconds) of event data polling. | 30.0 |
| Enable Logs | Bool | Master switch for internal logging system. | True |
| Log Categories | Struct | Fine-grained control over log types (Network, UI, etc.). | All True |
PHP Host Configuration
The system resolves the PHP URL in two ways:
- With ULSP (Login Pro): Automatically uses
bl_LoginProDataBase.Instance.PhpHostPath. - Standalone: You must manually set the path in
bl_EventManager.csor ensure your custom implementation provides it.
Server API Reference
The bl_EventManager.php script handles all requests. It expects a POST or GET request with an action parameter.
Database Schema (bl_game_events)
API Actions
CreateEvent: Initializes a new event entry.geteventlist: Returns all events (paginated).LoadEventDetails: Fetches full data for a specific event ID.UpdateLeaderboard: Updates player stats within the JSON blob.updatestatus: Changes event state (e.g., to Close/End).
Scripting API
bl_GameEventManager (Singleton)
The primary entry point for gameplay logic.
Fetches the current active event data and populates the provided UI component.
Requests the specific leaderboard JSON for the active event and updates the UI list.
Data Structures
EventDetails
LeaderboardEntry
UI System Architecture
Admin Panel (bl_EventManagerUI)
Located in the Admin scene or prefab. It allows authorized users to manage events.
- Features: Pagination, Filtering, Server Region selection, Event Creation Wizard.
- Prefab:
Event [ADMIN PANEL]
Player Dashboard (bl_GameEventUI)
The in-game display for players.
- Features: Shows active event, progress bar, and "Top Players" list.
- Dynamic Filtering: Automatically switches leaderboard columns based on Goal Type (Kills vs Wins) via
_GoalTypeenum. - Prefab:
Controlled Event
Creating Events
Follow these steps to launch a new event:
- Open the Admin Panel scene/UI.
- Navigate to the "Create Event" tab.
- Event Name: Unique identifier for the event.
- Mode: Select the game mode (must match your GameMode keys).
- Server: Choose "Global" for all regions or a specific region code (e.g., 'us', 'eu').
- XP Boost: Set the multiplier (e.g., 2x, 3x).
- Goal:
- Kills: Race to specific kill count.
- Wins: Race to specific win count.
- Duration: Set the event length (Days/Hours).
- Click Create Event. The system will sync with the PHP backend.
Troubleshooting
Connection Failed
Symptom: "Connection failed" error in console.
Fix: Check bl_EventManagerSettings. Ensure the PHP URL is reachable from your browser. Verify bl_LoginProDataBase path if using ULSP.
Leaderboard Not Updating
Symptom: Players get kills but leaderboard stays empty.
Fix:
1. Ensure the event status is "Open".
2. Check if the player is in the correct event_mode.
3. Verify the PHP script has write permissions to the JSON column in MySQL.
Debug Logs
Enable "Debug" level logging in EventManagerSettings to see raw JSON responses from the server. This is critical for identifying PHP errors.