Scripts Reference

Detailed documentation of the core RPG Character Generator scripts.

CharacterConfigurator.cs

Purpose: The bridge between the character creation UI and the generation logic. Collects user parameters and passes them to the Prompt script.

Key Components

  • UI ElementsTMP_InputField, TMP_Dropdown, and Toggle elements for character name, race, class, universe, alignment, level, context, and portrait description
  • Inference Dropdown — Selects between LlamaCPP, Ollama, or OpenAI backends
  • Image Inference Dropdown — Selects the image generation backend (Automatic1111, OpenAI)
  • Portrait Toggle — When off, hides portrait description input and image inference dropdown
  • Dependencies — Requires references to Prompt and SceneManager scripts

Methods

| Method | Description | |--------|-------------| | TriggerGeneration() | Gathers UI inputs, handles randomization, and initiates character generation | | ShowConfiguration() | Resets UI fields and returns to the configuration view | | OnPortraitToggleChanged(bool isOn) | Shows/hides portrait description and image inference UI | | ShowLoadingIndicator() / HideLoadingIndicator() | Toggles the loading animation via SceneManager |


Prompt.cs

Purpose: The central orchestrator for character generation. Constructs LLM prompts, handles all three inference backends, parses responses, and triggers portrait generation.

Key Components

  • LLM ComponentsLLMConfig (LlamaCPP), ollamaConfig (Ollama), OpenAIConfig (unified OpenAI-compatible API), and automaticImageGenerator (Automatic1111)
  • Prompt TemplatescharacterPrompt, portraitStylePrefix, and negativePrompt

Methods

| Method | Description | |--------|-------------| | StartCharacterGeneration(...) | Main entry point. Builds prompts, calls LLM, parses results, triggers image generation | | GenerateWithOllama(string prompt) | Handles streaming generation via the Ollama backend | | GenerateWithOpenAI(string prompt) | Handles streaming generation via the unified OpenAI-compatible backend | | BuildComprehensiveImagePrompt(...) | Creates a detailed Automatic1111 prompt from the character description | | DisplayCharacterPortrait(Texture2D) | Callback that applies the generated portrait texture to the UI | | CancelRequest() | Stops ongoing requests and resets UI state |


RPGCharacter.cs

Purpose: Manages the interactive roleplay chat after character generation. Maintains conversation context and supports all three backends.

Key Components

  • LLMConfig — LlamaCPP component for chat responses
  • ollamaConfig — Ollama configuration for local inference
  • OpenAIConfig — Unified OpenAI-compatible configuration
  • chatHistory — Stores the conversation log

Methods

| Method | Description | |--------|-------------| | SetCharacterContext(...) | Initializes the chat with the character's details and triggers an opening remark | | onInputFieldSubmit(string message) | Sends player messages to the LLM and displays the streamed response | | SetAIText(string text) | Updates the chat display during response streaming | | ChatWithOllama(string prompt) | Handles streaming chat via Ollama | | ChatWithOpenAI(string prompt) | Handles streaming chat via the unified OpenAI-compatible API |


SceneManager.cs

Purpose: A simple UI state machine that manages panel visibility for different application states.

Key Components

  • UI PanelsconfigurationPanel, backgroundPanel, chatPanel, loadingIndicator
  • SceneState EnumConfiguration, Background, Chat

Methods

| Method | Description | |--------|-------------| | SwitchToScene(SceneState newState) | Activates the appropriate panels for the given state | | ShowLoadingIndicator(bool show) | Toggles the loading indicator visibility | | UpdateCurrentSituation(string text) | Updates the "Current Situation" text on the background panel | | ResetToConfiguration() | Returns the UI to the initial configuration state |