Files
breakpilot-lehrer/website/components/admin/system-info-configs/unity-bridge-config.ts
Benjamin Boenisch 5a31f52310 Initial commit: breakpilot-lehrer - Lehrer KI Platform
Services: Admin-Lehrer, Backend-Lehrer, Studio v2, Website,
Klausur-Service, School-Service, Voice-Service, Geo-Service,
BreakPilot Drive, Agent-Core

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 23:47:26 +01:00

234 lines
9.5 KiB
TypeScript

import type { SystemInfoConfig } from './types'
export const unityBridgeConfig: SystemInfoConfig = {
title: 'Unity Bridge System-Info',
description: 'Kommunikationsschicht zwischen Web-App und Unity WebGL.',
version: '1.0',
architecture: {
layers: [
{ title: 'Web Interface', components: ['Message Bus', 'Event Handlers', 'State Sync'], color: '#3b82f6' },
{ title: 'Bridge Layer', components: ['jslib Interface', 'Message Queue', 'Serialization'], color: '#8b5cf6' },
{ title: 'Unity Side', components: ['C# Handlers', 'Event System', 'Data Models'], color: '#000000' },
{ title: 'Shared', components: ['Protocol Buffers', 'Type Definitions', 'Validation'], color: '#f59e0b' },
],
},
features: [
{ name: 'Bidirektionale Kommunikation', status: 'active', description: 'Web <-> Unity Messaging' },
{ name: 'State Synchronisation', status: 'active', description: 'Zustandsabgleich' },
{ name: 'Event System', status: 'active', description: 'Event-basierte Kommunikation' },
{ name: 'Type Safety', status: 'planned', description: 'Typsichere Schnittstelle' },
],
roadmap: [
{ phase: 'Phase 1: Stability (Q1)', priority: 'high', items: ['Error Handling', 'Reconnection Logic', 'Message Validation', 'Logging'] },
{ phase: 'Phase 2: Performance (Q2)', priority: 'medium', items: ['Message Batching', 'Compression', 'Lazy Loading', 'Memory Management'] },
{ phase: 'Phase 3: Features (Q3)', priority: 'low', items: ['Binary Protocol', 'Streaming', 'Debugging Tools', 'Hot Reload'] },
],
technicalDetails: [
{ component: 'Web', technology: 'TypeScript', description: 'Type-safe JS' },
{ component: 'Bridge', technology: 'jslib', description: 'Unity Plugin' },
{ component: 'Unity', technology: 'C#', description: 'Game Logic' },
{ component: 'Protocol', technology: 'JSON/Binary', description: 'Message Format' },
],
auditInfo: [
{
category: 'Bridge Status',
items: [
{ label: 'Connection', value: 'Aktiv', status: 'ok' },
{ label: 'Message Queue', value: 'Stabil', status: 'ok' },
{ label: 'Error Rate', value: '< 0.1%', status: 'ok' },
{ label: 'Latency', value: '< 10ms', status: 'ok' },
],
},
{
category: 'Protokoll',
items: [
{ label: 'Serialization', value: 'JSON', status: 'ok' },
{ label: 'Validation', value: 'Aktiv', status: 'ok' },
{ label: 'Compression', value: 'Geplant', status: 'warning' },
{ label: 'Binary Mode', value: 'Geplant', status: 'warning' },
],
},
{
category: 'Debugging',
items: [
{ label: 'Message Logging', value: 'Optional', status: 'ok' },
{ label: 'Performance Monitor', value: 'Aktiv', status: 'ok' },
{ label: 'Error Tracking', value: 'Sentry', status: 'ok' },
{ label: 'Dev Tools', value: 'In Entwicklung', status: 'warning' },
],
},
],
fullDocumentation: `
<h2>Unity Bridge - Web-Unity Kommunikation</h2>
<h3>1. Uebersicht</h3>
<p>Die Unity Bridge ermoeglicht bidirektionale Kommunikation zwischen der Web-Anwendung (JavaScript/TypeScript) und Unity WebGL (C#). Sie abstrahiert die jslib-Schnittstelle.</p>
<h3>2. Architektur</h3>
<pre>
┌─────────────────────────────────────────────────────────────────┐
│ Web Application │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ UnityBridge (TypeScript) │ │
│ │ ├── MessageBus │ │
│ │ ├── EventEmitter │ │
│ │ ├── StateSync │ │
│ │ └── ErrorHandler │ │
│ └────────────────────────────────────────────────────────────┘ │
│ │ │
│ │ SendMessage / Callback │
│ │ │
└──────────────────────────────┼───────────────────────────────────┘
┌──────────────────────────────┼───────────────────────────────────┐
│ Unity WebGL │
│ │ │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ BridgeManager (C#) │ │
│ │ ├── MessageReceiver │ │
│ │ ├── EventDispatcher │ │
│ │ ├── StateManager │ │
│ │ └── ExternalInterface (jslib) │ │
│ └────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
</pre>
<h3>3. Message-Protokoll</h3>
<pre>
{
"type": "event" | "command" | "query" | "response",
"id": "msg-uuid",
"timestamp": 1705234800000,
"channel": "game" | "ui" | "system",
"payload": {
"action": "player_score",
"data": {
"score": 100,
"level": 5
}
}
}
</pre>
<h3>4. JavaScript API</h3>
<pre>
// Bridge initialisieren
const bridge = new UnityBridge({
unityInstance: unityRef,
gameObjectName: "BridgeManager"
});
// Event an Unity senden
bridge.send("player.action", {
action: "jump",
force: 10
});
// Event von Unity empfangen
bridge.on("game.score", (data) => {
console.log("Score:", data.score);
});
// Query mit Response
const result = await bridge.query("game.state");
console.log("Current level:", result.level);
</pre>
<h3>5. C# API</h3>
<pre>
// BridgeManager.cs
public class BridgeManager : MonoBehaviour
{
// Von JavaScript empfangen
public void OnBridgeMessage(string json)
{
var message = JsonUtility.FromJson<BridgeMessage>(json);
HandleMessage(message);
}
// An JavaScript senden
public void SendToWeb(string channel, object data)
{
var json = JsonUtility.ToJson(data);
WebBridge.SendMessage(channel, json);
}
}
</pre>
<h3>6. Event-Kanaele</h3>
<table>
<tr><th>Kanal</th><th>Richtung</th><th>Beschreibung</th></tr>
<tr><td>game.*</td><td>Unity → Web</td><td>Game Events</td></tr>
<tr><td>player.*</td><td>Bidirektional</td><td>Player Actions</td></tr>
<tr><td>ui.*</td><td>Web → Unity</td><td>UI Commands</td></tr>
<tr><td>system.*</td><td>Bidirektional</td><td>System Events</td></tr>
<tr><td>auth.*</td><td>Web → Unity</td><td>Auth State</td></tr>
</table>
<h3>7. State Synchronisation</h3>
<pre>
Web State Unity State
│ │
│ ┌────────────────┐ │
├───>│ State Sync │<───┤
│ │ (Bidirectional) │
│ └────────────────┘ │
│ │
v v
┌─────────┐ ┌─────────┐
│ React │ │ Unity │
│ Store │ │ State │
└─────────┘ └─────────┘
Sync Events:
├── Initial Sync (Game Load)
├── Delta Sync (Changes only)
└── Full Sync (Recovery)
</pre>
<h3>8. Error Handling</h3>
<pre>
Error Types:
├── ConnectionError: Bridge nicht verbunden
├── TimeoutError: Keine Antwort
├── ParseError: JSON ungueltig
├── ValidationError: Schema-Fehler
└── UnityError: C#-Exception
Recovery:
├── Auto-Reconnect (3 Versuche)
├── Message Queue (bis reconnect)
└── Fallback UI (bei Dauerfehler)
</pre>
<h3>9. Performance</h3>
<table>
<tr><th>Metrik</th><th>Ziel</th><th>Messung</th></tr>
<tr><td>Latency</td><td>< 10ms</td><td>Per-Message</td></tr>
<tr><td>Throughput</td><td>1000 msg/s</td><td>Batch Test</td></tr>
<tr><td>Memory</td><td>< 1MB Queue</td><td>Monitoring</td></tr>
<tr><td>CPU</td><td>< 1%</td><td>Profiler</td></tr>
</table>
<h3>10. Debugging</h3>
<pre>
// Debug Mode aktivieren
bridge.setDebug(true);
// Message Inspector
bridge.onAny((channel, data) => {
console.log(\`[\${channel}]\`, data);
});
// Performance Monitor
bridge.getMetrics();
// {
// messagesSent: 1234,
// messagesReceived: 5678,
// avgLatency: 5.2,
// errors: 2
// }
</pre>
`,
}