How kbengine/kbengine_unity3d_plugins works
Project type and purpose
• This is a Unity3D client‐side plugin library (C#) for KBEngine, a distributed MMO server framework.
• It provides an API, networking layer, event system, and entity model so Unity games can connect to KBEngine servers (loginapp/baseapp/cellapp), send/receive messages, synchronize entity state, and handle callbacks.
File structure
• All source files are at the root of the package and form a single C# assembly (no separate “Frontend/Backend” folders).
• Core namespaces and classes:
• KBEngine.cs & KBEMain.cs – entry point & lifecycle hooks
• NetworkInterface.cs, PacketSender/PacketReceiver.cs, MessageReader.cs, Bundle.cs, MemoryStream.cs – low‐level networking & serialization
• Entity.cs, EntityDef.cs, EntityCall.cs, Method.cs, Property.cs, Event.cs – entity‐model & RPC abstractions
• ScriptModule.cs – script binding & module loader
• DataTypes.cs, Message.cs, KBEngineArgs.cs – message definitions & argument wrappers
• No build scripts in repo; the assembly is imported by Unity, which uses Mono to compile and link it.
README for additional insights
• The README shows how Unity code subclasses KBEMain to launch the plugin, how client‐side entities subclass KBEngine.Entity, how to register and fire events in/out of the plugin, and which server messages and entity events are exposed.
• It outlines an event‐driven architecture: “fireIn” for Unity→KBEngine, “fireOut” for KBEngine→Unity.
Main components and relationships
a. Components
• Unity Game Code (MonoBehaviour scripts, UI classes)
• KBEngine Unity3D Plugin (C# assembly)
• Networking Layer (NetworkInterface, PacketSender, PacketReceiver, MessageReader, MemoryStream, Bundle)
• Entity & RPC Layer (Entity, EntityCall, EntityDef, Method, Property)
• Event System (Event.registerOut, Event.fireIn)
• External KBEngine Servers (Loginapp, Baseapp, Cellapp)
• Optional DataStore/Third‐Party Account System
b. Relationships & Data Flows
1. Unity Game Code calls Plugin APIs (KBEMain.Start(), Entity.baseCall()/cellCall(), Event.fireIn).
2. Plugin serializes calls into Bundles via Message, KBEngineArgs, DataTypes.
3. PacketSender sends serialized payload over socket via NetworkInterface.
4. KBEngine Server processes RPC, updates entity state, and sends messages back.
5. PacketReceiver receives raw bytes; MessageReader parses them into high‐level events.
6. Event.fireOut invokes registered Unity callbacks (onEnterWorld, onConnectionState, etc.).
7. Unity UI/Game Code handles events, updates game world, triggers new RPCs.
c. Architectural patterns & design principles
• Event‐Driven / Observer pattern for cross‐layer notifications
• Adapter/Facade pattern wrapping raw sockets and byte streams into high‐level C# APIs
• Entity‐Component pattern: client entity classes mirror server‐side definitions
• Separation of concerns: Networking layer isolated from entity logic and Unity callbacks
d. Key technologies/frameworks/libraries
• Unity3D engine and Mono scripting runtime
• KBEngine distributed server framework (Loginapp, Baseapp, Cellapp)
• C# .NET standard library for streams, collections, events