Skip to content

jyswee/ainpc-unity-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AINPCEngine Unity Demo

A polished demo showing AI-powered NPCs in Unity 2022.3+ using the AINPCEngine SDK. Walk around a medieval village square and have natural conversations with 3 intelligent NPCs who remember you, trade goods, and offer quests.

Features

  • Procedural 3D village — scene builds at runtime from primitives (no imported assets needed)
  • 3 AI NPCs with distinct personalities:
    • Elara (Merchant, gold) — shrewd trader, haggle for potions and weapons
    • Theron (Guard, blue) — stoic veteran, suspicious of strangers
    • Old Miriam (Quest Giver, green) — cryptic seer, speaks in riddles
  • Natural language dialogue — say anything, NPCs respond intelligently
  • Persistent memory — NPCs remember your conversations
  • Dynamic emotions — glowing emotion orbs above NPCs change color in real-time
  • Trade & quest systems — context-aware buttons for each NPC type
  • Typewriter text effect — dialogue reveals character by character

Prerequisites

Quick Start

1. Start AINPCEngine

git clone https://github.com/jyswee/AINPCEngine.git
cd AINPCEngine
docker compose up -d

2. Clone this demo

git clone https://github.com/jyswee/ainpc-unity-demo.git

3. Configure

Edit Assets/Scripts/Config/DemoConfig.cs and set your API key:

public const string API_URL = "http://localhost:16745";   // Default docker-compose port
public const string API_KEY = "dev-api-key-change-me";     // Default dev key
public const string GAME_ID = "ainpc-unity-demo";

Note: The default docker-compose.yml exposes port 16745. If you deployed via Portainer, the port is typically 18542.

4. Open & Play

  1. Open Unity Hub and add this project
  2. Open with Unity 2022.3+
  3. The scene builds itself procedurally — just press Play
  4. Walk with WASD, look with mouse
  5. Approach an NPC and press E to interact
  6. Type your message and press Enter or click Send
  7. Press Escape to close dialogue

Project Structure

ainpc-unity-demo/
├── Assets/
│   ├── Plugins/AINPCEngine/       # AINPCEngine SDK (REST + WebSocket)
│   │   ├── AINPCEngine.cs
│   │   ├── Models.cs
│   │   └── NPCWebSocket.cs
│   └── Scripts/
│       ├── Config/DemoConfig.cs           # API configuration (edit this)
│       ├── Setup/SceneBootstrap.cs        # Procedural scene builder
│       ├── Managers/GameManager.cs        # Singleton: API client & NPC registry
│       ├── Player/PlayerController.cs     # WASD movement, mouse look, interact
│       ├── NPC/
│       │   ├── NPCBehaviour.cs            # NPC personality, emotions, API registration
│       │   ├── NPCTrigger.cs              # Proximity detection
│       │   └── BillboardLabel.cs          # Name labels face camera
│       └── UI/
│           ├── DialogueUI.cs              # Dialogue box with typewriter effect
│           ├── InteractionPromptUI.cs     # "Press E" proximity prompt
│           └── ConnectionStatusUI.cs      # API connection indicator
├── Packages/manifest.json                 # URP + TextMeshPro
└── ProjectSettings/                       # Unity project settings

How It Works

  1. On Play, SceneBootstrap procedurally creates the entire village, player, NPCs, and UI from code
  2. GameManager connects to the AINPCEngine API and registers all 3 NPCs with their personalities
  3. Walking near an NPC triggers a prompt. Press E to send a player_approached event
  4. The NPC responds with AI-generated dialogue, emotion, and optional actions
  5. Type anything — your message is sent as a player_dialogue event
  6. Emotion orbs glow with colors matching the NPC's current emotion
  7. Trade with Elara or accept quests from Miriam using context buttons

License

MIT License — Tyga.Cloud Ltd

About

AI-powered NPC demo for Unity 2022.3+ — walk around a village and talk to intelligent NPCs using AINPCEngine SDK

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages