July 4, 2019

Unity UI dialogue system

You can see the reult below!

https://youtu.be/od8aNcjijqs

Our dialogue window is based on Scroll View option. For text fieldswe will use UI buttons.

First check this link for a code source: https://null-code.ru/scripts/136-kvestovaya-sistema-dialogov.html

We need a button script first (first code box):

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class ButtonComponent : MonoBehaviour

{

public Button button;

public Text text;

public RectTransform rect;

}

We are serialising main button elements:

Button - the button as unity object

Text - the text in button

RectTransform- transform of the button

After we need to choose how many answers well be able for player during WHOLE game. If its 5, we need to create 6 (1 for NPC text).

Fill Scroll view with buttont. Attach button script to every button in here.

Next attach controlling script to a canvas. (warning, its giant so check the second code box in the original)

Here magick hapens. This manager works only with link with a script manager.

Every script is unique so u have to make connection with it via manager. We tell him quest name and some parameter and in the manager by itself searching by a name and directly appealing to it.

Quest manager listed below: (3rd code box)

Dialogue file have to be placed ta folder listed in dialogue manager, "Russian" for example. So we can use different languagesonly changing folder name, but all of the folders have to be placed in Resources.

XML dialogur file

<dialogue name="Example">
  <node id="0" npcText="Greetengs!">
    <answer text="howdy?" toNode="1" />
    <answer text="Have to go" exit="True" />
  </node>
  <node id="1" npcText="FIne...">
    <answer text="Gotcha." toNode="0" />
    <answer text="Have a work todo, bye" exit="True" />
  </node>
</dialogue>

Tag node is for NPC text showing

It must to have an id which is node identification and npcText Which is the NPC text

Tag answer is for player answer

Atributes:

toNode - redirectioning to another dialogue node (Cant be used with exit in one answer)

exit - Closes dialogue window (cant be used with toNode)

questName

- имя квеста с который нужно взаимодействовать,

это обязательный атрибут, если указаны ниже следующие.

questValue - Dialogue answer can be shown only in preassigned quest state (Cant be used with questValueGreater )

questValueGreater

- dialogue answer will be only shown if quest state is equal or higher than preassigned value (Cant be used with questValue )

questStatus - sending to a quest manager current state of a pointed quest. (take quest - 1; Decline quest - 2; done quest - 3, Inactive - 0.