Skip to main content

Demo: 2D

This demo is under Assets > Inworld > Inworld.Assets > Scenes, and is also included in the core package inworld-unity .

⚠️ Note: By default, the contents under Packages in a Unity project are read-only. If your project references InworldAI.Lite solely through the Package Manager, please copy the Packages/Inworld.AI/Runtime/Scenes/Sample2D.unity to your Assets folder.

1. Connecting and selecting a character

After the application has loaded, press the Connect button to initiate the session. Once the session is established, the characters present in the scene will be loaded.

To interact with a character, click on its thumbnail. This action will activate the Send and Record buttons, allowing you to interact with the selected character.

Sample2D1

2. Typing to the character

You can type sentences, and press the "Enter" or Send button, to send message to the character.

Sample2D2

3. Sending Narrative Actions

You can send narrative actions by starting your text input with a *.

NarrativeAction2D

4. Speech to Text

Alternatively, you can hold down the Record button, speak your message, and then release Record to send a voice message.

Sample2D3

5. Using Your Own Character

To integrate your custom character, ensure that you have prepared all the necessary assets. If you are unsure about the required data, please refer to the Prerequisite Page for detailed guidance.

Next, navigate to your Scenes page in the browser, copy the scene's full name, and paste it into the Scene Full Name field in the InworldController.

Sample2D2

Additionally, visit your Integrations page, copy the API key and API secret, and paste them into the corresponding fields in the InworldController.

Sample2D2

Sample2D2

Once you click Play, your characters will appear in your custom scene, allowing you to interact with them.

Sample2D2

6. Description

The 2D scene is straightforward, comprising only two GameObjects: PlayerController2D and InworldController.

PlayerController2D

PlayerController2D is derived from PlayerController and overrides the OnCharacterJoined and OnCharacterLeft events. This modification enables the tracking of character selection and activates the interactive features for the UI buttons.

ConnectPanel

Within PlayerController2D, there's a child gameObject named ConnectPanel, which contains the CharacterSelectorPanel script. Upon establishing a session, this panel retrieves the character thumbnails and generates buttons, allowing you to select a character.

ChatPanel

Another child gameObject, ChatPanel, is responsible for displaying the conversation. It also handles the functionality of the Send and Record buttons, facilitating interaction within the scene.

Player2D

InworldController

The InworldController serves as the central hub, coordinating interactions through its three primary scripts.

InworldClient

This script manages server-client connections and interactions, facilitating the sending and receiving of data.

CharacterHandler

Operating on the client side, this script manages character events, such as when a character enters or exits the chat group or is selected for interaction.

AudioCapture

This script is responsible for sampling microphone input and transmitting the audio data to the server.

Controller2D

⚠️ Note:: The InworldController persists across scenes, so there's no need to instantiate it in each scene.

In this sample 2D scene, characters are not pre-loaded; instead, a character is instantiated on-demand when its selector button is clicked. If the character does not already exist, it will be created and then selected for interaction.

Consequently, if you want to monitor the character's events, you must add listeners in your code to track these events.

Controller2D