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.
Wonder how to collect the keywords like Do Not Feed the Monkeys?
-
- Posts: 2
- Joined: Wed Nov 16, 2022 6:23 am
Re: Wonder how to collect the keywords like Do Not Feed the Monkeys?
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:
(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:
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);
}
}
}
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>";
}
-
- Posts: 2
- Joined: Wed Nov 16, 2022 6:23 am
Re: Wonder how to collect the keywords like Do Not Feed the Monkeys?
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.
I use linkInfo.GetLinkID() to know which keywords player got, and it works with multilanguages and multi keywords in one dialogue.