Wonder how to collect the keywords like Do Not Feed the Monkeys?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
carzyluke2
Posts: 2
Joined: Wed Nov 16, 2022 6:23 am

Wonder how to collect the keywords like Do Not Feed the Monkeys?

Post by carzyluke2 »

Hi, I want to create the fucntion to collect the keywords like Do Not Feed the Monkeys, see this video at 5:44:https://youtu.be/PU_VhX6xCiA?t=342.

I found this video to know that TextMeshPro have some methods to get specified character/line/link/word.


Next step is integrated into Dialogue System. Considering multilanguages, I thought using markup tags is the only way, but I don't think that is possible to custom markup tags? The closest solution may be [lua(code)], but I wonder how to implent it. I'm still looking at Dialogue System's documentation.
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Wonder how to collect the keywords like Do Not Feed the Monkeys?

Post by Tony Li »

Hi,

Yes, use TextMesh Pro (see TextMesh Pro Support) and <link> tags (tutorial).

You will have to write the code that handles the <link> tag. Here's one idea: you could add a custom field to your dialogue entry template (Templates) to hold Lua code that will run if the player clicks on the link. If the player clicks the link, run the Lua code. You can register your own C# methods with Lua (tutorial). For example:

Code: Select all

[RequireComponent(typeof(TextMeshProUGUI))]
public class LuaTMProLink : MonoBehaviour, IPointerClickHandler {

    public void OnPointerClick(PointerEventData eventData) {
        int linkIndex = TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, pCamera);
        if( linkIndex != -1 ) { // was a link clicked?
            // Here we get the info, but this example isn't going to use it:
            TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex];
            
            // Instead, look up a custom field named "Link Code" in the current dialogue entry:
            var currentDialogueEntry = DialogueManager.currentConversation.subtitle.dialogueEntry;
            string linkCode = Field.LookupValue(currentDialogueEntry.fields, "Link Code");

            // Run the Lua code:
            Lua.Run(linkCode);
        }
    }
}
(Note: I just typed the example code above into the reply. I haven't tested it.)


If you want to insert <link> tags into your text at runtime, use an OnConversationLine() method. Example:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    // For this example, put a <link> tag at the very end.
    subtitle.formattedText.text += "<link=\"more_info\">More Info</link>";
}
carzyluke2
Posts: 2
Joined: Wed Nov 16, 2022 6:23 am

Re: Wonder how to collect the keywords like Do Not Feed the Monkeys?

Post by carzyluke2 »

Thanks for the help! I think the <link> tag in TextMesh Pro already meet my requirement.

I use linkInfo.GetLinkID() to know which keywords player got, and it works with multilanguages and multi keywords in one dialogue.
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Wonder how to collect the keywords like Do Not Feed the Monkeys?

Post by Tony Li »

Glad to help!
Post Reply