How playroomkit/unity works
Project’s Main Purpose
• The SDK is a Unity package that wraps around the PlayroomKit JavaScript SDK.
• It is meant to facilitate multiplayer interactions for WebGL games built in Unity.
• The README emphasizes that the API mirrors the JavaScript version and that most examples are found in the “Examples” subdirectory.
Break Down the File Structure to Determine Key Components
• Assets/PlayroomKit: This is the central folder containing core SDK logic. Within it, you have its own subdirectories:
– Editor: Contains editor scripts (e.g., PlayroomDevEditor.cs) that enhance Unity’s editor experience.
– Examples: Contains sample projects (like “2d-platformer”, “discord-activity”, and “package-showcase”) which illustrate how the SDK is used in real scenarios.
– Modules: Hosts various functional modules such as Helpers, Interfaces, MockMode, Options, Player, RPC, and others—these are the building blocks of the SDK’s functionality.
– Dependencies: A large collection of external libraries (e.g., Castle.Core, NSubstitute, ParrelSync, UnityBrowserBridge, PowerConsole, SimpleJSON, etc.) that are either used at runtime or for development/testing.
– src folder and configuration files (e.g., vite.config.js): Likely handle the coupling with the underlying JavaScript code (the PlayroomKit JS) and browser-side interactions.
• Other top-level folders (e.g., Assets, ProjectSettings, Packages) follow standard Unity project structure.
• .github folder: Contains CI/CD workflows (for packaging, testing, releases, etc.), which are important for understanding the development process but less critical for the runtime architecture.
Identifying and Labeling Main Components
A. Core SDK Modules:
• Modules (Helpers, Interfaces, Options, Player, RPC etc.)
• The “PlayroomBuildService” and “PlayroomkitDevManager” that help configure and manage the SDK behavior.
• Communication interfaces (e.g., IRPC, IPlayerBase) that define how game objects interact with the multiplayer backend.
B. Editor Tools:
– Editor Scripts (in Assets/PlayroomKit/Editor) that provide in-editor support such as development consoles and settings panels.
C. External Dependencies:
– A “Dependency Layer” block that shows libraries like Castle.Core, ParrelSync, PowerConsole, SimpleJSON, and UnityBrowserBridge. Indicate that these are used to support features such as command handling, logging, cloning (for parallel testing), network/browser bridging, etc.
D. JavaScript/WebGL Bridge:
– A separate “PlayroomKit JS/WebGL” block, representing the external JavaScript SDK. This is what the Unity SDK wraps around.
– Indicate the role of Files found in Assets/PlayroomKit/src (frameworks.js, index.js) and how they enable communication between Unity and the PlayroomKit JavaScript layer when the game is exported as WebGL.
E. Examples and Testing:
– An “Examples” block (Assets/PlayroomKit/Examples) to demonstrate typical use cases.
– “Tests” folder contents also show that unit tests are available for development validation (Assets/PlayroomKit/Tests).
Relationships and Data Flow
• That the Core SDK communicates with the external PlayroomKit JS/WebGL component for actual multiplayer functionality.
• From the Editor Tools, show how they facilitate configuration and debugging in the Unity Editor environment.
• Dependencies layer with the core modules to highlight that external libraries provide additional functionality (e.g., for RPC calls or command parsing).
Architectural Patterns and Design Principles
• Modularization: The clear separation into Modules (Helpers, Interfaces, Options, etc.) points to a design that favors separation of concerns and modularity.
• Wrapper/Adapter Pattern: The SDK serves as a wrapper for the JavaScript SDK, so it acts as an adapter between Unity-specific code (C#) and web-based technology.
• MVC or similar separation: While not strictly MVC, there’s a separation between frontend (game assets prefabs, scenes), business logic (SDK modules/Services), and infrastructure (external JS/WebGL and Dependencies).