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: `
Die Unity Bridge ermoeglicht bidirektionale Kommunikation zwischen der Web-Anwendung (JavaScript/TypeScript) und Unity WebGL (C#). Sie abstrahiert die jslib-Schnittstelle.
┌─────────────────────────────────────────────────────────────────┐
│ Web Application │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ UnityBridge (TypeScript) │ │
│ │ ├── MessageBus │ │
│ │ ├── EventEmitter │ │
│ │ ├── StateSync │ │
│ │ └── ErrorHandler │ │
│ └────────────────────────────────────────────────────────────┘ │
│ │ │
│ │ SendMessage / Callback │
│ │ │
└──────────────────────────────┼───────────────────────────────────┘
│
┌──────────────────────────────┼───────────────────────────────────┐
│ Unity WebGL │
│ │ │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ BridgeManager (C#) │ │
│ │ ├── MessageReceiver │ │
│ │ ├── EventDispatcher │ │
│ │ ├── StateManager │ │
│ │ └── ExternalInterface (jslib) │ │
│ └────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
{
"type": "event" | "command" | "query" | "response",
"id": "msg-uuid",
"timestamp": 1705234800000,
"channel": "game" | "ui" | "system",
"payload": {
"action": "player_score",
"data": {
"score": 100,
"level": 5
}
}
}
// 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);
// BridgeManager.cs
public class BridgeManager : MonoBehaviour
{
// Von JavaScript empfangen
public void OnBridgeMessage(string json)
{
var message = JsonUtility.FromJson(json);
HandleMessage(message);
}
// An JavaScript senden
public void SendToWeb(string channel, object data)
{
var json = JsonUtility.ToJson(data);
WebBridge.SendMessage(channel, json);
}
}
| Kanal | Richtung | Beschreibung |
|---|---|---|
| game.* | Unity → Web | Game Events |
| player.* | Bidirektional | Player Actions |
| ui.* | Web → Unity | UI Commands |
| system.* | Bidirektional | System Events |
| auth.* | Web → Unity | Auth State |
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)
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)
| Metrik | Ziel | Messung |
|---|---|---|
| Latency | < 10ms | Per-Message |
| Throughput | 1000 msg/s | Batch Test |
| Memory | < 1MB Queue | Monitoring |
| CPU | < 1% | Profiler |
// 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
// }
`,
}