Page 1 of 1

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

Posted: Wed Nov 16, 2022 7:08 am
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.

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

Posted: Wed Nov 16, 2022 9:16 am
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>";
}

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

Posted: Fri Nov 18, 2022 11:23 am
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.

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

Posted: Fri Nov 18, 2022 3:17 pm
by Tony Li
Glad to help!