Skip to content

Latest commit

ย 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ฌ UnityLink Chat

Production-grade, WhatsApp-style real-time chat for Unity

Unity 2021.3+ Firebase MIT License Version Platforms


Drop-in chat plugin 1-to-1 messaging, groups, media, reactions, E2E encryption. Built on Firebase. Works on Android, iOS, and Desktop.


โœจ Features

๐Ÿ’ฌ Core Messaging

  • 1-to-1 chat with persistent history
  • Real-time sync via Firestore listeners
  • Delivery & read receipts (โœ“ / โœ“โœ“ / ๐Ÿ”ต)
  • Typing indicators with animated dots
  • Offline-first with auto sync
  • Push notifications via FCM
  • Unread badges & pagination

๐Ÿ“Ž Media Support

  • Image messages with thumbnails & tap-to-enlarge
  • File attachments with download progress
  • Voice notes โ€” record, play, seek
  • Upload progress bar with cancel
  • Media picker โ€” gallery, camera, file browser

๐Ÿ‘ฅ Group Chat

  • Create groups with name, description & members
  • Role system โ€” Owner / Admin / Member
  • Member management โ€” add, remove, promote
  • @mention and @everyone with priority push
  • System messages for join/leave/promote events

โšก Advanced Features

  • ๐Ÿ˜€ Emoji reactions with quick-picker
  • Long-press context menu (Reply ยท Copy ยท Edit ยท Delete ยท Forward)
  • Edit & delete messages (for everyone or self)
  • Forward messages to any conversation
  • Debounced chat search with context snippets

๐Ÿ”’ End-to-End Encryption

AES-256-CBC + HMAC-SHA256 ยท Per-conversation keys ยท Secure key exchange ยท Firebase Storage & Firestore security rules


๐Ÿš€ Quick Start

1. Install Firebase SDK

Import these packages from the Firebase Unity SDK:

Package Purpose
FirebaseAuth User authentication
FirebaseFirestore Real-time database
FirebaseMessaging Push notifications
FirebaseStorage Media uploads

2. Import UnityLink Chat

# Option A โ€” Package Manager
Window โ†’ Package Manager โ†’ + โ†’ Add package from disk โ†’ select package.json

# Option B โ€” Manual
Copy this folder into your project's Packages/ directory

3. Set Up Your Scene

Use the Setup Wizard: UnityLink โ†’ Chat Setup Wizard in the menu bar.

Or manually:

  1. Create a ChatManager GameObject โ†’ add the ChatManager component
  2. Create a ChatTheme: Assets โ†’ Create โ†’ UnityLink โ†’ Chat Theme
  3. Wire up UI panels โ€” ChatListView, MessageWindow, etc.

4. Deploy Cloud Functions

cd CloudFunctions
npm install -g firebase-tools
firebase login
firebase init         # Select Functions, Firestore, Storage
npm install
firebase deploy       # Deploys functions + rules

5. Run the Demo

๐Ÿ’ก Try the built-in demo scene to see everything in action!

UnityLink โ†’ Testing โ†’ Create Dual Chat Scene โ†’ Press Play

Two test users (Alice & Bob) will sign in automatically and chat side-by-side.
See Demo Scene below for details.


๐ŸŽฎ Demo Scene

The plugin includes a fully self-contained dual-user chat demo in Samples~/DemoScene/.

File Description
DualChatTest.unity Pre-built scene โ€” just press Play
ChatManager.prefab Reference prefab with default settings
DefaultChatTheme.asset WhatsApp-style theme configuration

How to Use

Option A โ€” Import via Package Manager:

Window โ†’ Package Manager โ†’ UnityLink Chat โ†’ Samples โ†’ Import "Demo Scene"

Option B โ€” Generate a fresh scene:

UnityLink โ†’ Testing โ†’ Create Dual Chat Scene

The DualChatTest component builds the entire UI at runtime โ€” no prefabs or manual wiring needed:

  • Creates a split-screen with two chat panels
  • Signs in Alice & Bob via Firebase Auth
  • Both can send/receive messages in real-time

โš ๏ธ Note: Ensure Firebase is configured before running. See SETUP_GUIDE.md for detailed instructions.


๐Ÿ—๏ธ Architecture

UnityLink Chat/
โ”‚
โ”œโ”€โ”€ Runtime/
โ”‚   โ”œโ”€โ”€ Core/           โ†’ ChatManager orchestrator
โ”‚   โ”œโ”€โ”€ Models/         โ†’ UserData, ConversationData, MessageData, GroupData
โ”‚   โ”œโ”€โ”€ Services/       โ†’ FirebaseChatService, GroupChatService, StorageService
โ”‚   โ”œโ”€โ”€ Sync/           โ†’ ChatSyncEngine, ConversationRepository
โ”‚   โ”œโ”€โ”€ Events/         โ†’ Static ChatEvents hub
โ”‚   โ”œโ”€โ”€ UI/             โ†’ MessageBubble, MediaPicker, ReactionView, SearchView...
โ”‚   โ”œโ”€โ”€ Theme/          โ†’ ChatTheme ScriptableObject
โ”‚   โ””โ”€โ”€ Testing/        โ†’ DualChatTest (self-contained demo)
โ”‚
โ”œโ”€โ”€ Editor/             โ†’ Custom inspectors, Setup Wizard, Scene Generator
โ”œโ”€โ”€ CloudFunctions/     โ†’ Firebase Cloud Functions + Security Rules
โ”œโ”€โ”€ Samples~/           โ†’ Importable demo scene & assets
โ””โ”€โ”€ package.json

๐Ÿ“– API Reference

Authentication

await ChatManager.Instance.SignIn("email", "password");
await ChatManager.Instance.CreateAccount("email", "password", "Display Name");
await ChatManager.Instance.SignOut();

Conversations & Messaging

// Start a 1-to-1 chat
await ChatManager.Instance.StartConversation("otherUserId");

// Create a group
var group = await ChatManager.Instance.CreateGroup("Team Chat", "description", memberIds);

// Send media
await ChatManager.Instance.SendMediaMessage(convoId, filePath, MessageType.Image, "caption");

// Edit, Delete & Forward
await ChatManager.Instance.EditMessage(convoId, msgId, "updated text");
await ChatManager.Instance.DeleteMessage(convoId, msgId, forEveryone: true);
var results = await ChatManager.Instance.SearchMessages("query");

Events (Reactive UI)

ChatEvents.OnMessageReceived      += (convoId, msg)  => { /* new message      */ };
ChatEvents.OnConversationsUpdated += (conversations)  => { /* list changed     */ };
ChatEvents.OnTypingStateChanged   += (convoId, uid, t)=> { /* typing indicator */ };
ChatEvents.OnConnectionStateChanged += (state)        => { /* online / offline */ };
ChatEvents.OnUnreadCountChanged   += (convoId, uid, n)=> { /* badge count      */ };

Services

// Group management
ChatManager.Instance.GroupService.AddMember(groupId, adminId, newMemberId);
ChatManager.Instance.GroupService.PromoteMember(groupId, adminId, targetId, MemberRole.Admin);

// Media
ChatManager.Instance.StorageService.UploadImage(convoId, userId, path, onProgress);
ChatManager.Instance.StorageService.DownloadFile(url, localPath, onProgress);

// Encryption
ChatManager.Instance.EncryptionService.Encrypt("hello", convoId);
ChatManager.Instance.EncryptionService.Decrypt(ciphertext, convoId);

๐ŸŽจ Customization

Area How
Colors & Fonts Edit the ChatTheme ScriptableObject
Custom Backend Implement IChatService for your own server
Custom UI Extend or replace any UI MonoBehaviour
Encryption Toggle _enableEncryption on ChatManager

๐Ÿ”ง Troubleshooting

Issue Solution
Scripts don't compile Import all 4 Firebase packages (Auth, Firestore, Messaging, Storage)
FirebaseApp not initialized Verify google-services.json / GoogleService-Info.plist in Assets/
Push notifications not working Check FCM token in user document & Cloud Functions logs
Messages not syncing Deploy Firestore rules; check Console for permission errors
Media upload fails Enable Firebase Storage & deploy storage.rules
Group creation fails Ensure Firestore rules allow isGroup documents

๐Ÿ“‹ Requirements

Requirement Version
Unity 2021.3+
Firebase Unity SDK 11.x+
Node.js 18+ (for Cloud Functions)
Platforms Android ยท iOS ยท Desktop

Built with โค๏ธ by UnityLink

About

Drop-in chat plugin 1-to-1 messaging, groups, media, reactions, E2E encryption. Built on Firebase. Works on Android, iOS, and Desktop.

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages