Game Framework
Examples

Examples & Templates

Learn Game Framework through hands-on examples and production-ready templates. From simple demos to advanced patterns, these examples will help you master Unity-Flutter integration.

Getting Started with Examples

Unity Template Scripts

Game Framework includes Unity template scripts that demonstrate key patterns and features. Sync them to your Unity project:

# Sync core scripts only
game sync scripts

# Include template examples
game sync scripts --templates

Flutter Example App

The framework includes a complete Flutter example application:

# Clone the repository
git clone https://github.com/xraph/gameframework.git

# Navigate to example
cd gameframework/example

# Run the example
flutter run

All examples include both Unity and Flutter code, so you can see the complete integration!

Available Examples

What You'll Learn

Beginner Examples

Perfect for getting started:

  • Rotating Cube - Bidirectional communication basics
  • Messaging Patterns - Different ways to send messages
  • Flutter Example App - Complete integration walkthrough

Intermediate Examples

Build on the basics:

  • Binary Data Transfer - Working with images and files
  • Scene Management - Managing Unity scenes from Flutter
  • State Synchronization - Keep Flutter and Unity in sync

Advanced Examples

Performance and optimization:

  • High-Frequency Messaging - Optimize for high throughput
  • State Synchronization - Delta compression and efficient updates

Example Structure

Each example includes:

  • Unity Script: Complete C# implementation
  • Flutter Code: Dart integration code
  • Setup Instructions: Step-by-step guide
  • What You'll Learn: Key concepts covered
  • Code Walkthrough: Detailed explanations

Quick Start

1. Sync Template Scripts

cd your_flutter_project
game sync scripts --templates

2. Open Unity

Add the scripts to your Unity scene:

  1. Open Unity Editor
  2. Create a new GameObject
  3. Attach the example script (e.g., GameFrameworkDemo.cs)
  4. Press Play to test in Unity

3. Integrate with Flutter

Use the Flutter code snippets from each example to communicate with Unity.

Template Scripts Overview

GameFrameworkDemo.cs

Interactive rotating cube with bidirectional communication. Perfect first example.

Key Features:

  • Touch-based rotation controls
  • Speed adjustment from Flutter
  • Color customization
  • Real-time feedback

What You'll Learn: Basic messaging, parameter updates, event handling

MessagingExample.cs

Comprehensive messaging patterns demonstration.

Key Features:

  • String messages
  • JSON/typed messages
  • Request-response pattern
  • Event broadcasting

What You'll Learn: All message types, type safety, async patterns

BinaryDataExample.cs

Binary data transfer for images and files.

Key Features:

  • Image upload to Unity
  • Screenshot capture from Unity
  • Chunked transfers
  • Compression

What You'll Learn: Binary protocol, performance optimization

HighFrequencyDemo.cs

Performance testing and optimization.

Key Features:

  • Throughput measurement
  • Latency tracking
  • Batching effectiveness
  • Throttling

What You'll Learn: Performance optimization, profiling

StateManager.cs

State synchronization patterns.

Key Features:

  • Full state sync
  • Delta compression
  • Periodic updates
  • Versioning

What You'll Learn: Efficient state management

SceneController.cs

Unity scene management from Flutter.

Key Features:

  • Load/unload scenes
  • Async loading
  • Progress tracking
  • Multi-scene support

What You'll Learn: Scene lifecycle, async operations

Example Projects

Basic Integration

Start with the rotating cube:

# Sync templates
game sync scripts --templates

# Run Flutter app
flutter run

Complete Demo App

Run the full example application:

git clone https://github.com/xraph/gameframework.git
cd gameframework/example
flutter run

Learning Path

Step 1: Rotating Cube

Start here to learn basic communication.

Step 2: Messaging Patterns

Explore different message types.

Step 3: Binary Data

Learn to transfer images and files.

Step 4: Scene Management

Control Unity scenes from Flutter.

Step 5: State Synchronization

Implement efficient state updates.

Step 6: Performance Testing

Optimize for production use.

Follow the examples in order for the best learning experience. Each builds on concepts from previous examples.

Getting Help

Example Issues

If you encounter problems with examples:

  1. Check the Troubleshooting Guide
  2. Review Unity Setup
  3. See FAQ

Community

Next Steps

Ready to dive in?

  1. Start with the Rotating Cube - Your first interactive example
  2. Explore Messaging Patterns - Learn communication methods
  3. Run the Flutter Example - See a complete integration

All template scripts are production-ready and can be used as starting points for your own projects!