Var newMessage = new Message ", MessageType.Bot) public void AddMessage(string messageText, MessageType messageType)ĭestroy() Next we'll add a AddMessage() method to the script that will add Text object instances to the Content element of the Viewport with the user or bot's text message and will also control the number of Text objects in memory. :video videos/unity-attach-game-manager.mp4 Add Message to Panel OscovaBot MainBot Īs in Unity the public fields can be assigned visually, we will now go back to our unity project by closing the Visual Studio project and focusing on Unity. In the GameManager class add the following fields before the void Start() method. We'll now add a couple of fields to the code to connect Content of viewport, Text prefab, Input Field and the send Button. In the code below we create a Message class that will hold information like the user or bot message, message type and the associated Text UI object. Start is called before the first frame updateĪbove the GameManager class code add the following code. The current code should look something like the following. This should open a Visual Studio project. Click on Add Component in Inspector windowĭouble click on the GameManager script Project Assets window.Right click on Scene Hierarchy and select Create Empty.In order to create our bot and bind it with the UI we will go ahead and create a GameManager that will have a Script component attached to it. We have now successfully created the UI part and have imported the Syn.Bot Unity Package to the Unity project. :video videos/unity-import-bot.mp4 Bot Interface Make sure all items are selected and choose Import.Select the file that you've downloaded.Choose Import Package and select Custom Package.In your unity project right click in Project If you have not downloaded the Syn.Bot Demo Unity Package you can download the package from the link below. We are now done with the UI part of our Unity bot. :video videos/unity-input-field.mp4 Buttonįinally our Chat UI will now contain a Send Button to send the user message to the bot for processing.Īdjust the button placement as shown below. Add a Input Field to the Canvas UI element and place it below the Scroll View as shown below.To talk to the bot we will need to add a text Input Field which will take the user input and pass to the bot for processing. :video videos/unity-content-text.mp4 Input Field For that text to be visible and aligned within the viewport we will now create a Text prefab. When you type a message to the bot and a response is generated by the bot we will need to save those text values within the Content of the Viewport. We'll do so by adding a Content Size Filter and Vertical Layout Group component. We'll now change a few configuration of the Content element of the Viewport so that the text that will be added into the viewport content aligns properly. This will contain the chats between the user and the bot. Let's add a Canvas and then a Scroll View. We will now add a couple of visual elements to create a chat interface within Unity. Your Unity project should now be created and the Unity studio should now be visible as follows:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |