You can of course create your own Dialogue UI for your game. All you need to do is creating a UI Controller class which receives all relevant method calls from the DialogueController to control your dialogue UI.
To do this, create an empty class and implement the IDialogueUIControlinterface.
It is also recommended to have a look at the existing Theme scripts.
Here's a very simple barebone custom dialogue class which you can use and create your own theme based on this.
usingUnityEngine;usingUnityEngine.UI;usingTMPro;usingDatabrain.Dialogue;publicclassMyDialogueUI:MonoBehaviour,IDialogueUIControl{ // Define your dialogue references such as // choices button, dialogue text (TextMeshUI) etc.publicTextMeshProUGUI dialogueText;publicGameObject choiceButtonPrefab;publicGameObject optionButtonsContainer;privateDialogueController dialogueController; /// <summary> /// Called by the dialogue controller in the scene, which passes a reference to the dialogue controller to your dialogue ui script.
/// </summary> publicvoidSetDialogueController(DialogueController dialogueController) {this.dialogueController= dialogueController; } /// <summary> /// Called the first time a dialogue starts /// </summary>publicvoidOnDialogueStart() { // show the dialogue UI. // Clear old choice buttonsfor (int j =0; j <existingChoiceButtons.Count; j++) {if (existingChoiceButtons[j] !=null) {Destroy(existingChoiceButtons[j].gameObject); } } } /// <summary> /// Called every time a new dialogue text is requested /// </summary> /// <paramname="dialogueEventData"></param>publicvoidShowNextDialogueText(DialogueEventData dialogueEventData) { // Update dialogue text. Get the localized text by passing in the selected language from the dialogue controller
dialogueText.text = dialogueEventData.dialogueText.GetLocalizedText(dialogueController.GetSelectedLanguage());
} /// <summary> /// Called when choices are requested /// </summary> /// <paramname="dialogueEventData"></param>publicvoidShowChoices(DialogueEventData dialogueEventData) { // Build choices buttons // Clear old buttons firstfor (int j =0; j <existingChoiceButtons.Count; j++) {if (existingChoiceButtons[j] !=null) {Destroy(existingChoiceButtons[j].gameObject); } }for (int i =0; i <dialogueEventData.choices.Count; i++) { // Skip choices which are not connected in the dialouge graphif (dialogueEventData.choices[i] ==null) {continue; } // Instantiate the choice button prefabvar _choiceInstance =Instantiate(choiceButtonPrefab); // Get the TextMeshProUGUI component from the button and assign the localized text _choiceInstance .GetComponentInChildren<TextMeshProUGUI>().text = dialogueEventData.choices[i].GetLocalizedText(dialogueController.GetSelectedLanguage());
// Get the Button component and assign an action to the OnClick event.var _button =_choiceInstance .GetComponent<Button>();_button.onClick.AddListener(() => { // Select choice with index + 1 because 0 = default choice when timers updialogueController.SelectChoice(_index +1); }); // Add the choice button instance to the options UI container_choiceInstance.transform.SetParent(optionButtonsContainer.transform,false); // Add the button instance to the list so we can destroy them laterexistingChoiceButtons.Add(_choiceInstance.gameObject); } } /// <summary> /// Constantly called by DialogueController to update the timer UI /// </summary> /// <paramname="_remainingTime"></param> /// <paramname="_totalTime"></param>publicvoidUpdateTimer(float _remainingTime,float _totalTime){} /// <summary> /// Called when dialogue is finished, by the OnExitDialogue node. /// </summary>publicvoidOnDialogueExit() { // Hide dialouge UI }}
The best way to use this script would be on the root object of your Dialouge UI. This root GameObject can then be assigned to the Dialouge Theme field on the DialougeController component in the scene.