Dialogue System for Unity use (1) Basic settings and function introduction


foreword

This Dialogue System dialogue system is used to solve the complex dialogue logic in the game, support multiple languages, save, visualize the process and other functions. If it is a general single-line story, there is no need to use this, just write it yourself.

In addition, this system can help developers who do not know how to code can also create multi-branch and complex story processes (integration functions such as visualization, multiple collision buttons, etc.), and I will introduce the process below as a first-time contact with this plug-in The way to go in-depth (the facts are similar), that is to say, I will put in the thinking process of taking over and cutting into a new plug-in.

I am planning to use this plugin for my own independent game, and I have already started it. If you have any related questions, please leave a message and be happy to discuss with each other.

1. Installation

​Import
the plug-in and find that it contains three parts:
1. The Editor Default Resources folder contains the default resources used by the editor script.

2. The Gizmos folder stores texture and icon resources used by the Gizmos.DrawIcon method.

3, body
insert image description here

​​​​Then there will be a pop-up window, you can check it according to your own needs, I chose TMP (TextMeshPro) here

4. There are documents under the directory, but some of the content in it is an old version and it should not be updated in time. Documentation includes:

Text_Table_Manual - Text Table Manual

Save_System_Manual - save system manual

Input_Device_Manager_Manual - Input Device Manager Manual

2. Functional analysis

1. Official basic function guide

Find the Demo scene and click on the boot function on the script with the same name on the Dialogue Manager object
insert image description here

2. Data foundation

It is to choose your own dialogue data resource, the Create New button can create a new resource, that is to say, the manager can be unique, but the content and story in it can preset multiple resources and switch back and forth. (So ​​far it looks like this)
insert image description here

3. Dialogue UI prefabrication

A dialog UI can be assigned here. You can find pre-built UI at Plugins/Pixel Crushers/Dialogue System/Prefabs/Standard Ul Prefabs. You can also specify a UI scene object. The literal meaning is to specify a UI prefab, we can open this UI prefab, change the dialog icon and run the demo, and find that all the dialog boxes have changed, which is really amazing.
insert image description here

4. Localized language

insert image description here
For the multilingual text form, please refer to the document mentioned in the first part, and the specific usage is as follows:

Create a text form as shown in the figure
insert image description here
Double-click to open the form, there are two lists, language list and field list; let’s fill in the drop-down menu of the field list
insert image description here
insert image description here
By the way, the form here can be exported to CSV format, for those who do not understand It is used for planning, and then imported; just kidding, it is actually for the convenience of multi-language management for the planning of excel tables.
insert image description here
​Then
we drag the form into it, we can write the language we just set in the initial language, and switch it during the game, and then we found that the corresponding dialogue management control system also added a text form, which shows that this guide is very convenient to use, Very comfortable.
insert image description here

Click on the localization system, and find that the Dialogue Manager of the scene is prefabricated with more management scripts, and the specific settings are clear. You can click or drag what fonts and forms are required. Additonal is an additional meaning. If the game has branches in different regions, I feel that this is still necessary.
insert image description here
Finally, what should we do if we want to use code to obtain these things in many cases? Figure 1 below shows that when only text tables are used, the corresponding text can be obtained by entering the field mark.

Figure 2 shows the use of the official Manager. What is filled in the initial language will display the corresponding marked field in the text table. If you want to change it, you can use UILocalizationManager.instance.currentLanguage. Use this API and it will be cached. Click Clear in the management script. The language can be initialized to the default one. For more usage methods, just look at the source code of this localization system, which is very simple.
​`using PixelCrushers;

public TextTable textTable;

void Start()
{
    string str = textTable.GetFieldTextForLanguage("问候语", "EN");
    Debug.Log(str);
}
-------------------------------------------------------------------------------
void Start()
{
    string str= UILocalizationManager.instance.GetLocalizedText("问候语");
    Debug.Log(str);
}

5. Subtitle display mode

insert image description here
NPC Subtitles Durign Line: When the NPC speaks, the dialogue subtitles are displayed. If your project has lip sync, don’t click it. I clicked this because I can’t afford it, haha.

With Response Menu: Check to display the last NPC subtitle in the "Player Response" menu. This helps remind players - what their reactions are. Generally tick it.

PC Subtitles: PC subtitles, check to display PC subtitles when the PC speaks. Tick ​​if you use different menu text and dialog text. Otherwise, you can choose to leave it unchecked.

Chars/Second: The amount of characters output per second, which is similar to Dotween's text output animation. I think it's good to add this narration and game, but it's better to be quicker and follow the context changes or to be able to click and jump directly to the end (see Continue Button below).

Min Seconds: The minimum time for subtitle display.

Continue Button: Continue button, corresponding to a lot of events, here we choose Always to run the Demo and find that there are more buttons and it will be completed in one click. Other explanations are as follows, in fact, you will know after trying it.

  • Never Before Response Menu: Don't show if the Player Response menu is next. For any setting other than "Never", your UI must contain a "Continue" button.

  • Optional Before Response Menu: Shown but does not require a click if the Player Response menu is next.

Rich Text: Rich text requires UI support, I choose to check it.

6. Camera, cut scenes (cutscenes)

My Sister Li is a cutscene animation. When the player talks to the NPC, there are usually needs such as perspective conversion and movement (cooperating with lip language is also included, but those who do that kind of work probably won’t read this guide). The general meaning is Use the means of sequence to realize various attribute transformations of the camera.

There are a lot of details here that should be temporarily stored, and a new file will be opened later.

7. Input system

There are corresponding documents, which explain the settings related to the input system and the new input system, which is the new one from unity. '

Awesome description: Automatic management, automatic detection of mouse or handle, and various configurations such as hiding the cursor are still very complete. Supports new and old input systems, and provides a very convenient way of writing:

bool InputDeviceManager.IsButtonDown(“button name”)
bool InputDeviceManager.IsButtonUp(“button name”)
bool InputDeviceManager.IsKeyDown(KeyCode)
float InputDeviceManager.GetAxis(“axis name”)
Vector3 InputDeviceManager.GetMousePosition()

Specific API documentation
If you are using a new system, you need to define the scripting symbol USE_NEW_INPUT (check the new system on the welcome page to add it automatically, and the interface will open in Tools/Pixel Crushers/Dialogue System/Welcome Windows.). The following is the sample code (the script registers various actions, and then we can call it elsewhere):

using UnityEngine;
using UnityEngine.InputSystem;
using PixelCrushers;
public class RegisterMyControls : MonoBehaviour
{
    
    
 protected static bool isRegistered = false;
 private bool didIRegister = false;
 private Controls controls;
 void Awake()
 {
    
    
 controls = new MyControls();
 }
 void OnEnable()
 {
    
    
 if (!isRegistered)
 {
    
    
 isRegistered = true;
 didIRegister = true;
 controls.Enable();
 InputDeviceManager.RegisterInputAction("Back", controls.Gameplay.Back);
 InputDeviceManager.RegisterInputAction("Interact", controls.Gameplay.Interact);
 }
 }
 void OnDisable()
 {
    
    
 if (didIRegister)
 {
    
    
 isRegistered = false;
 didIRegister = false;
 controls.Disable();
 InputDeviceManager.UnregisterInputAction("Back");
 InputDeviceManager.UnregisterInputAction("Interact");
 }
 }
}

If you need to use it, please check the document. The above code starts registration and ends logout. I won’t say much here.

Configuration: (Actually, it is possible not to write code, the boot interface contains the following two setting modules)

Player Response Menu: Player Response Menu

Always Force Menu: Always focus on the menu, check it to force the response menu. If unchecked, when the player has only one valid response, Ul will automatically select that response without showing the response menu. Simply means that the player has to choose an option to leave after talking to the NPC.

Include Invalid Entries: Include invalid entries (entities). If checked, false entries in the menu will be included, and the button can be seen but cannot be selected. It means that some dialogues in the game are required (for example: only when the strength reaches 20 can you threaten others in the dialogue-it is your V (20 strength), the dialogue in class 2077 cannot be selected)

Timer: response time. It is the emergency option. If you tick to select 10s, then the operation you want will be executed if you do not select within 10s. The drop-down menu defaults to select the first item when the time is up.

Quick Time Event(QTE) Trigger Buttons: Quickly trigger event buttons (the specific content can be changed in the Input Settings under the Display Settings on the prefab, for advanced points, you can add the OverrideDisplaySettings script to rewrite the settings)

Cancel Line: Cancel the button, name, etc. of the line, which means to interrupt the dialogue. The name can be conveniently called by the script.

Cancel Conversation: Cancel the button, name, etc. of the conversation, which means to cancel the conversation.

8. Alarm

insert image description here
Allow In Conversations: Checkmark to allow alerts to be displayed in conversations. If unmarked, the alert will not be displayed until the conversation is over.

Monitor Alerts: Monitor alerts, constantly monitor Lua values.

Chars/Second: Display the time of the alarm, if it is 0, the attribute of the subtitle will be used by default.

Min Seconds: The minimum time to display the alert, 0 is the minimum time for the default subtitles.

Bricks suggest that you don't need to worry about the default, anyway, my project doesn't need it.

9. Save the system

The system provides data preservation and records changes across scenarios.
insert image description here
For the saving system, please refer to the document mentioned in the first part. The specific usage is as follows (if you do not need to customize various operations, the following scripts will be added automatically at runtime):

1. First add a Save System script to the Dialogue Manager of the scene.

2. Add Json Data Serializer, data serialization script.

3. Add PlayerPrefs Saved Game Data Storer or Disk Saved Game Data Storer; they are two kinds of storage respectively.

ok, give me a chestnut. The setting menu of our game has two buttons corresponding to saving and loading the game respectively. Then we can use SaveSystem.SaveGameToSlot and SaveSystem.LoadGameFromSlot to bind the two buttons. If there is a need to load the scene, we also provide the SaveSystem.LoadScene method or add SaveSystemMethods Script onto the prefab. Among them, search for Demo Menu in the Demo scene to view the above script and jump to the inherited DemoMenu to find that he also wrote it in the same way, as follows:

   {
    
    
      private void SaveGame()
        {
    
    
            var saveSystem = FindObjectOfType<SaveSystem>();
            if (saveSystem != null)
            {
    
    
                SaveSystem.SaveToSlot(1);
            }
            else
            {
    
    
                string saveData = PersistentDataManager.GetSaveData();
                PlayerPrefs.SetString("SavedGame", saveData);
                Debug.Log("Save Game Data: " + saveData);
            }
            DialogueManager.ShowAlert("Game saved.");
        }

        private void LoadGame()
        {
    
    
            PersistentDataManager.LevelWillBeUnloaded();
            var saveSystem = FindObjectOfType<SaveSystem>();
            if (saveSystem != null)
            {
    
    
                if (SaveSystem.HasSavedGameInSlot(1))
                {
    
    
                    SaveSystem.LoadFromSlot(1);
                    DialogueManager.ShowAlert("Game loaded.");
                }
                else
                {
    
    
                    DialogueManager.ShowAlert("Save a game first.");
                }
            }
            else
            {
    
    
                if (PlayerPrefs.HasKey("SavedGame"))
                {
    
    
                    string saveData = PlayerPrefs.GetString("SavedGame");
                    Debug.Log("Load Game Data: " + saveData);
                    LevelManager levelManager = FindObjectOfType<LevelManager>();
                    if (levelManager != null)
                    {
    
    
                        levelManager.LoadGame(saveData);
                    }
                    else
                    {
    
    
                        PersistentDataManager.ApplySaveData(saveData);
                        DialogueManager.SendUpdateTracker();
                    }
                    DialogueManager.ShowAlert("Game loaded.");
                }
                else
                {
    
    
                    DialogueManager.ShowAlert("Save a game first.");
                }
            }
        }


        private void ClearSavedGame()
        {
    
    
            var saveSystem = FindObjectOfType<SaveSystem>();
            if (saveSystem != null)
            {
    
    
                if (SaveSystem.HasSavedGameInSlot(1))
                {
    
    
                    SaveSystem.DeleteSavedGameInSlot(1);
                }
            }
            else if (PlayerPrefs.HasKey("SavedGame"))
            {
    
    
                PlayerPrefs.DeleteKey("SavedGame");
                Debug.Log("Cleared saved game data");
            }
            DialogueManager.ShowAlert("Saved Game Cleared");
        }
}

The summary is that you can write the method of calling the document by yourself, otherwise add the corresponding written script, except for the component script mentioned above, the rest are as follows:
insert image description here
insert image description here

Well, let's understand this first, and add the corresponding exclusive module examples later.

10. Overview of Settings

The overview page set before, including dialogue information data, UI template, display subtitle method, response menu, response time, allow alarm, save system.
insert image description here

11. Example dialog system

Database: Basic data information
insert image description here
Actors: Actors, including the player itself
insert image description here
Quests: Task
insert image description here
Locations: Location, positioning
insert image description here
Variables: Variables
insert image description here
Conversations: Dialogue
insert image description here
Templates: Templates
insert image description here
basically include variables, characters, tasks, dialogue text and other miscellaneous settings, the directory is still very clear If you want to study, you can modify the demo at will.

Summarize

By analyzing the boot system that comes with the plug-in, I learned about the settings included in the entire plug-in. The various systems are still very comprehensive. If you develop it yourself, it will take a lot of time. In the next article, let’s start directly, and make a demo from the beginning to the end, and how to integrate the big fire into the project. Generally speaking, this is to list all the functional concepts of the plug-in. Some people may think it is useless, but in many cases, it is very important to have a concept of the plug-in in your mind, so that you can be flexible instead of memorizing it by rote. Combine various functions with ease.

For basic functions, you can go to station b and search for the Dialogue System on YouTube, which does not use code; the next practical article, but there is no guarantee that it will come out in a few days, after all, I still have my own job.

Guess you like

Origin blog.csdn.net/qq_41912124/article/details/127904958