OpenDialogue: Difference between revisions
Tayfunwiki (talk | contribs) (Created page with "== <code>OpenDialogue</code> Method in DialogueManager Class == === Overview === The <code>OpenDialogue</code> method in the DialogueManager class is responsible for initiating a dialogue with specified parameters. It is essential for creating dynamic and interactive dialogues within the game. === Description === * Parameters: ** <code>title</code> (string): The title of the dialogue. ** <code>content</code> (string): The content or body of the dialogue. ** <code>time...") |
Tayfunwiki (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
[[File:Dialogue Node.png|thumb|You can also start a dialog with the Dialogue Node.]] | |||
== <code>OpenDialogue</code> Method in DialogueManager Class == | == <code>OpenDialogue</code> Method in DialogueManager Class == | ||
Latest revision as of 12:31, 4 January 2024
OpenDialogue
Method in DialogueManager Class
Overview
The OpenDialogue
method in the DialogueManager class is responsible for initiating a dialogue with specified parameters. It is essential for creating dynamic and interactive dialogues within the game.
Description
- Parameters:
title
(string): The title of the dialogue.content
(string): The content or body of the dialogue.time
(float, optional): The duration for which the dialogue window remains open. The window automatically closes after this time elapses.onUpdate
(Action<float>, optional): An optional callback that is invoked with the remaining time.isSchemeDialog
(bool, optional): Indicates whether the dialogue is part of a node flow or standalone.
- Return Type:
Dialogue
- Returns the newly opened dialogue instance.
- Functionality:
- Creates a new
DialoguePanel
instance for displaying the dialogue. - Configures the panel with the provided title, content, and other parameters.
- Manages the visibility and duration of the dialogue panel.
- Creates a new
Usage
This method is used to open dialogues in various scenarios within the game, such as character interactions, narrative progression, or player choices. The method's flexibility allows for a wide range of dialogue presentations.
Example of Usage
public class DialogueTrigger : MonoBehaviour {
public void TriggerDialogue() {
// Open a dialogue with a title and content
var dialogue = DialogueManager.OpenDialogue(
"Greetings",
"Welcome to the realm of Eldoria!",
10f); // Dialogue with a 10-second duration
// Add choices to the dialogue
dialogue.AddChoice("Explore", ExploreEldoria)
.AddChoice("Leave", LeaveEldoria);
// Subscribe to the onTimeout event
dialogue.onTimeout += () => Debug.Log("Dialogue timed out.");
}
private void ExploreEldoria() {
Debug.Log("Chose to explore Eldoria.");
// Additional logic for exploring Eldoria
}
private void LeaveEldoria() {
Debug.Log("Chose to leave Eldoria.");
// Additional logic for leaving Eldoria
}
}
Description:
- OpenDialogue: Initiates a dialogue with the title "Greetings" and the message "Welcome to the realm of Eldoria!".
- AddChoice: Two choices are added to the dialogue:
- "Explore": Calls the
ExploreEldoria
method when selected. - "Leave": Calls the
LeaveEldoria
method when selected.
- "Explore": Calls the
- onTimeout Event: An event handler is added to log a message when the dialogue times out after 10 seconds.
Remarks
- This example shows how to create a dialogue with choices, allowing players to interact and make selections.
- The
onTimeout
event ensures that actions can be taken if the dialogue closes automatically after a certain duration. - This approach is effective for creating engaging and interactive dialogues in the game, providing players with choices that can lead to different outcomes or actions.
Dialogue
Class
Overview
The Dialogue
class represents an individual dialogue with various functionalities, including adding choices and managing its visibility.
Description
- Functionalities:
- Show/Hide/Close: Controls the visibility of the dialogue.
- AddChoice: Adds interactive choices to the dialogue with various configurations.
- Event Handling: Includes events like
onTimeout
for handling dialogue-specific actions.
Usage
Used to manage individual dialogues, the Dialogue
class allows for intricate control over the dialogue's presentation and interactivity within the game.
Example of Adding Choices
Dialogue dialogue = DialogueManager.OpenDialogue("Question", "What will you do?");
dialogue.AddChoice("Accept", () => Debug.Log("Accepted"))
.AddChoice("Decline", () => Debug.Log("Declined"));
In this example, a new dialogue is created with two choices, each triggering a different action when selected. This allows for interactive and dynamic dialogue experiences.
Remarks
- The
Dialogue
class is integral for creating rich and engaging dialogue interactions in the game. - Its ability to handle different dialogue configurations makes it adaptable for various narrative and gameplay scenarios.