How maria-shchurova/ai-lifesim works
Project Type and Purpose
• This is a Unity-based full-stack game project (“ai-lifesim”).
• Purpose: A dialogue-based simulation where NPCs use the OpenAI API to generate character speech and behaviors at runtime.
File Structure Analysis
• Top-level directories:
• Assets – contains all game assets: 3D models, animations, materials, scripts, scenes, UI, plugins, editor extensions.
• Packages – NuGet/.NET dependencies and Unity package manifest.
• ProjectSettings – Unity project configuration.
• UserSettings – local Unity editor layouts/settings.
• Key subfolders under Assets:
• Scripts – core game logic, NPC behavior, AI controllers, menus, scene controls.
• Plugins/x64/OpenAI_API – C# client wrappers for OpenAI endpoints (Chat, Completions, Embeddings, Images, Files, Models, Moderation).
• Editor – Unity editor extensions: AICommandWindow, Roslyn compiler integration, OpenAIUtil.
• StreamingAssets – persona and chatHistory JSON for each NPC (Alice, Ernest, Kathie, Trenton).
• Scenes – Unity .unity scene files and NavMesh assets.
• UI – prefabs for Canvas/menu screens.
• Unity-Roslyn – Roslyn compiler integration assembly.
• Configuration files: manifest.json, packages-lock.json, ProjectSettings/…
• Dependencies: TextMesh Pro, Unity-Roslyn, Microsoft.CodeAnalysis, System.*
README Insights
• Describes using OpenAI Unity integration for characters at runtime.
• References Roslyn to compile C# code in Unity.
• Credits 3D asset sources.
a. Main Components
1. Unity Engine
– Scene & Game Loop
– Asset Pipeline (3D models, animations, materials).
2. Presentation Layer
– UI Canvas & Menus (MainMenu, PauseMenu).
– TextMeshPro for text rendering.
3. Game Logic Layer
– Scripts (GameStateManager, PlayerInteractions, NPC, Messenger, SceneControls).
– NPC Subsystem: NPCMemory, NPC_Persona, NPCtoNPC, DynamicRelationships, Schedule.
– Animation controllers (Assets/Character topdown, Assets/NPC/*/Animations).
4. AI Integration Layer
– OpenAIController & Messenger (wrapper orchestrating requests).
– Plugins/OpenAI_API endpoints (Chat, Completion, Embedding, etc.).
– Editor/OpenAIUtil for testing in Editor.
5. Data Layer
– StreamingAssets/persona.txt & chatHistory.json (persistent per-NPC context).
6. External Service
– OpenAI REST API (hosted externally).
7. Tooling/Editor Extensions
– Unity-Roslyn for runtime C# compilation.
– Editor scripts (AICommandWindow) for dev workflows.
b. Relationships & Data Flows
• Player → PlayerInteractions → GameStateManager
• When player talks to NPC:
• GameLogic → OpenAIController → Plugins/OpenAI_API → HTTP request → OpenAI Service
• Receive JSON response → Messenger → NPCMemory updates → NPCtoNPC events
• NPCMemory & schedule drive animation state (Animator controllers) and dialogue UI.
• StreamingAssets store persona and conversation history; read/write by OpenAIController.
• Editor tools (Roslyn, OpenAIUtil) enable testing/compiling commands during development.
c. Architectural Patterns & Principles
• Layered architecture: Presentation → Game Logic → AI Integration → Data → External.
• Separation of concerns:
• UI components isolated in Assets/UI.
• Core game logic in Scripts/.
• External API calls encapsulated in Plugins/OpenAI_API.
• Data persistency via StreamingAssets.
• Dependency injection pattern: Messenger class for callbacks.
d. Technologies & Frameworks
• Unity 2021.x
• C# 8/.NET 6.0 (via Unity-Roslyn)
• OpenAI .NET client (Plugins/OpenAI_API)
• TextMesh Pro for text rendering
• NavMesh for NPC pathfinding
Detail Level
• Essential elements: Assets → Scripts → Plugins → External API → Data.
• Do not overcrowd: group similar animation assets or NPC folders into single “NPC Assets” node.
• Data flows (persona/chatHistory) are shown distinctly.