public void Clicked() { int linkIndex = TMP_TextUtilities.FindIntersectingLink(textMeshPro, Input.mousePosition, null); if (linkIndex != -1) { TMP_LinkInfo linkInfo = textMeshPro.textInfo.linkInfo [linkIndex]; switch (linkInfo.GetLinkID()) { case "id_1": Application.OpenURL("https://twitter.com/zephybite"); break; case "id_2": Application.OpenURL("https://zephyo.tumblr.com"); break; case "id_3": Application.OpenURL("https://facebook.com/zephybite"); break; case "id_4": Application.OpenURL("https://soundcloud.com/zephyo/i-woke-up-next-to-you-again"); break; } } }
void LateUpdate() { // is the cursor in the correct region (above the text area) and furthermore, in the link region? var isHoveringOver = TMP_TextUtilities.IsIntersectingRectTransform(pTextMeshPro.rectTransform, Input.mousePosition, pCamera); int linkIndex = isHoveringOver ? TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, pCamera) : -1; // Clear previous link selection if one existed. if (pCurrentLink != -1 && linkIndex != pCurrentLink) { SetLinkToColor(pCurrentLink, (linkIdx, vertIdx) => pOriginalVertexColors[linkIdx][vertIdx]); pOriginalVertexColors.Clear(); pCurrentLink = -1; } // Handle new link selection. if (linkIndex != -1 && linkIndex != pCurrentLink) { pCurrentLink = linkIndex; if (doesColorChangeOnHover) { pOriginalVertexColors = SetLinkToColor(linkIndex, (_linkIdx, _vertIdx) => hoverColor); } } if (Input.GetKeyDown(KeyCode.Mouse0) && linkIndex != -1) //Clicked on a link { TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex]; Application.OpenURL(linkInfo.GetLinkID()); // open the link id as a url, which is the metadata we added in the text field } }
public void OnPointerClick(PointerEventData eventData) { var linkIndex = TMP_TextUtilities.FindIntersectingLink(m_Text, eventData.position , m_Text.canvas == null ? (Core.Instance.m_Camera != null // text doesn't use canvas set world camera ? Core.Instance.m_Camera : Camera.main) : (m_Text.canvas.renderMode == RenderMode.ScreenSpaceOverlay // text use canvas, if ScreenSpaceOverlay set null, is not use canvas camera ? null : m_Text.canvas.worldCamera) ); if (linkIndex != -1) { TMP_LinkInfo linkInfo = m_Text.textInfo.linkInfo[linkIndex]; // run event if (m_EventDictionary.TryGetValue(linkInfo.GetLinkID(), out var ultEvent)) { ultEvent.Invoke(gameObject); } else { Debug.LogWarning("Link value not presented in the dictionary"); } } }
private Vector3[] CreateUnderlineCoords(int linkID) { // this method calculates the coordinates used by the line renderer, // they are returned in pairs of left, right grouped in an array with a total length of (lines of text in link)*2 List <Vector3> coords = new List <Vector3>(); TextMeshProUGUI targetPage = hpv.pages.Peek().GetComponentInChildren <TextMeshProUGUI>(); TMP_TextInfo textInfo = targetPage.textInfo; Vector3 offset = new Vector3(0, -.001f, 0); TMP_LinkInfo linkInfo = new TMP_LinkInfo(); foreach (var link in textInfo.linkInfo) { if (int.Parse(link.GetLinkID()) == linkID) { linkInfo = link; break; } } int startLine = targetPage.textInfo.characterInfo[linkInfo.linkTextfirstCharacterIndex].lineNumber; int endLine = targetPage.textInfo.characterInfo[linkInfo.linkTextfirstCharacterIndex + linkInfo.linkTextLength].lineNumber; Transform textTransform = targetPage.transform; int linkStartIndex = linkInfo.linkTextfirstCharacterIndex; int linkEndIndex = linkInfo.linkTextfirstCharacterIndex + linkInfo.linkTextLength; for (int i = startLine; i < endLine + 1; i++) { int startIndex = textInfo.lineInfo[i].firstCharacterIndex > linkStartIndex ? textInfo.lineInfo[i].firstCharacterIndex : linkStartIndex; int endIndex = textInfo.lineInfo[i].lastCharacterIndex - 3 < linkEndIndex ? textInfo.lineInfo[i].lastCharacterIndex - 3 : linkEndIndex; coords.Add(textTransform.TransformPoint(textInfo.characterInfo[startIndex].bottomLeft) + offset); coords.Add(textTransform.TransformPoint(textInfo.characterInfo[endIndex].bottomRight) + offset); } return(coords.ToArray()); }
public void OnPointerClick(PointerEventData eventData) { //var linkIndex = TMP_TextUtilities.FindIntersectingLink(m_Text, Input.mousePosition, m_Camera == null ? null : m_Camera); var linkIndex = TMP_TextUtilities.FindIntersectingLink(m_Text, Input.mousePosition, m_Text.canvas == null ? (global::Core.Core.Instance.Camera != null ? global::Core.Core.Instance.Camera : Camera.main) : (m_Text.canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : m_Text.canvas.worldCamera) ); if (linkIndex != -1) { TMP_LinkInfo linkInfo = m_Text.textInfo.linkInfo[linkIndex]; // play sound soundPlayer?.Play(m_Click); // open the link id as a url, which is the metadata we added in the text field Application.OpenURL(linkInfo.GetLinkID()); } }
List <Color32[]> SetLinkToColor(int linkIndex, Color32 color) { TMP_LinkInfo linkInfo = textMeshPro.textInfo.linkInfo[linkIndex]; var oldVertColors = new List <Color32[]>(); // store the old character colors for (int i = 0; i < linkInfo.linkTextLength; i++) { // for each character in the link string int characterIndex = linkInfo.linkTextfirstCharacterIndex + i; // the character index into the entire text var charInfo = textMeshPro.textInfo.characterInfo[characterIndex]; int meshIndex = charInfo.materialReferenceIndex; // Get the index of the material / sub text object used by this character. int vertexIndex = charInfo.vertexIndex; // Get the index of the first vertex of this character. Color32[] vertexColors = textMeshPro.textInfo.meshInfo[meshIndex].colors32; // the colors for this character oldVertColors.Add(vertexColors); if (charInfo.isVisible) { vertexColors[vertexIndex + 0] = color; vertexColors[vertexIndex + 1] = color; vertexColors[vertexIndex + 2] = color; vertexColors[vertexIndex + 3] = color; } } // Update Geometry textMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All); return(oldVertColors); }
void LateUpdate() { if (!isMouseOver) { if (m_lastCharIndex != -1) { SendCharacterLeaveEvent(); m_lastCharIndex = -1; } if (m_lastWordIndex != -1) { var lastWInfo = m_TextComponent.textInfo.wordInfo[m_lastWordIndex]; SendOnWordLeave(lastWInfo, lastWInfo.GetWord(), lastWInfo.firstCharacterIndex, lastWInfo.characterCount); m_lastWordIndex = -1; } if (m_lastLineIndex != -1) { TMP_LineInfo lastLineInfo = m_TextComponent.textInfo.lineInfo[m_lastLineIndex]; SendOnLineLeave(GetLineText(lastLineInfo), lastLineInfo.firstCharacterIndex, lastLineInfo.characterCount); m_lastLineIndex = -1; } if (m_selectedLink != -1) { TMP_LinkInfo lastLinkInfo = m_TextComponent.textInfo.linkInfo[m_selectedLink]; SendOnLinkLeave(new LinkArgs(lastLinkInfo)); m_selectedLink = -1; } return; } WatchCharacterEvents(); WatchWordEvents(); WatchLineEvents(); WatchLinkEvents(); }
public void OnPointerClick(PointerEventData eventData) { Vector3 pos = new Vector3(eventData.position.x, eventData.position.y, 0); int linkIndex = TMP_TextUtilities.FindIntersectingLink(text, pos, null); //--UI camera if (linkIndex > -1) { TMP_LinkInfo linkInfo = text.textInfo.linkInfo[linkIndex]; bool find = false; foreach (string link in links) { if (link == linkInfo.GetLinkText()) { find = true; } } if (!find) { links.Add(linkInfo.GetLinkText()); print("linkTextLength" + linkInfo.linkTextLength); print("linkTextfirstCharacterIndex" + linkInfo.linkTextfirstCharacterIndex); print(linkInfo.linkIdFirstCharacterIndex); //text.text = text.text.Insert(linkInfo.linkIdFirstCharacterIndex+linkInfo.linkIdLength+1+linkInfo.linkTextLength+15, "(dddd)"); flowChart.SetStringVariable("ddd", "Wadwadadwa"); } Debug.Log(linkInfo.GetLinkText()); //Application.OpenURL(linkInfo.GetLinkID()); } }
private void WatchLinkEvents() { // Check if mouse intersects with any links. int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, UnityEngine.Input.mousePosition, m_Camera); // Handle new Link selection. if (linkIndex != -1 && linkIndex != m_selectedLink) { if (m_selectedLink != -1) { TMP_LinkInfo lastLinkInfo = m_TextComponent.textInfo.linkInfo[m_selectedLink]; SendOnLinkLeave(new LinkArgs(lastLinkInfo)); } m_selectedLink = linkIndex; TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex]; SendOnLinkEnter(new LinkArgs(linkInfo)); } else if (m_selectedLink != -1 && linkIndex == -1) { TMP_LinkInfo lastLinkInfo = m_TextComponent.textInfo.linkInfo[m_selectedLink]; SendOnLinkLeave(new LinkArgs(lastLinkInfo)); m_selectedLink = -1; } }
public void OnPointerClick(PointerEventData eventData) { TextMeshProUGUI pTextMeshPro = gameObject.GetComponent <TextMeshProUGUI>(); // Debug.LogError("LINK CLICKED!"); int linkIndex = TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, null); if (linkIndex != -1) { // Debug.LogError("LINK != -1"); TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex]; if (linkInfo.GetLinkID().Contains("http") == true || linkInfo.GetLinkID().Contains("mailto") == true) { Application.OpenURL(linkInfo.GetLinkID()); } else { // Debug.Log("LINK clicked on " + linkInfo.GetLinkID()); Clicked.Invoke(linkInfo.GetLinkID()); } } else { // Debug.LogError("LINK nuppes, geen klik index "+ linkIndex); Clicked.Invoke(""); } }
public LinkArgs(TMP_LinkInfo info) { linkInfo = info; int actualLength = info.textComponent.text.Substring(linkRawTextfirstCharacterIndex).IndexOf("</link>"); fullText = info.textComponent.text.Substring(linkRawTextfirstCharacterIndex, actualLength); }
public void OnPointerClick(PointerEventData eventData) { int linkIndex = TMP_TextUtilities.FindIntersectingLink(Label, Input.mousePosition, eventData.pressEventCamera); Debug.Log("Click index: " + linkIndex); if (linkIndex != -1) { // was a link clicked? TMP_LinkInfo linkInfo = Label.textInfo.linkInfo[linkIndex]; // open the link id as a url, which is the metadata we added in the text field var linkId = linkInfo.GetLinkID(); Debug.Log("Link id: " + linkId + " : " + linkInfo.GetLinkText()); if (linkId == "twitter") { Application.OpenURL(TwitterUrl); } else { if (linkId == "twitch") { Application.OpenURL(TwitchUrl); } } } }
private void SetLinkToColor(int linkIndex, Color32 color) { TMP_LinkInfo linkInfo = textMessage.textInfo.linkInfo[linkIndex]; for (int i = 0; i < linkInfo.linkTextLength; i++) // for each character in the link string { int characterIndex = linkInfo.linkTextfirstCharacterIndex + i; // the character index into the entire text var charInfo = textMessage.textInfo.characterInfo[characterIndex]; int meshIndex = charInfo.materialReferenceIndex; // Get the index of the material / sub text object used by this character. int vertexIndex = charInfo.vertexIndex; // Get the index of the first vertex of this character. Color32[] vertexColors = textMessage.textInfo.meshInfo[meshIndex].colors32; // the colors for this character if (charInfo.isVisible) { vertexColors[vertexIndex + 0] = color; vertexColors[vertexIndex + 1] = color; vertexColors[vertexIndex + 2] = color; vertexColors[vertexIndex + 3] = color; } } // Update Geometry textMessage.UpdateVertexData(TMP_VertexDataUpdateFlags.All); }
private void SetLinkToColor(int linkIndex, Color32 color) { TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex]; if (linkInfo.textComponent != null) { for (int i = 0; i < linkInfo.linkTextLength; i++) { int characterIndex = linkInfo.linkTextfirstCharacterIndex + i; // the character index into the entire text var charInfo = pTextMeshPro.textInfo.characterInfo[characterIndex]; if (charInfo.character != ' ') { int meshIndex = charInfo.materialReferenceIndex; // Get the index of the material / sub text object used by this character. int vertexIndex = charInfo.vertexIndex; // Get the index of the first vertex of this character. Color32[] vertexColors = pTextMeshPro.textInfo.meshInfo[meshIndex].colors32; vertexColors[vertexIndex + 0] = color; vertexColors[vertexIndex + 1] = color; vertexColors[vertexIndex + 2] = color; vertexColors[vertexIndex + 3] = color; } } } pTextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All); }
private void ResetLinkColor(int linkIndex, List <Color32[]> startColors) { TMP_LinkInfo linkInfo = textMeshPro.textInfo.linkInfo[linkIndex]; int underlineIndex = -1; for (int i = 0; i < linkInfo.linkTextLength; i++) { int characterIndex = linkInfo.linkTextfirstCharacterIndex + i; var charInfo = textMeshPro.textInfo.characterInfo[characterIndex]; int meshIndex = charInfo.materialReferenceIndex; int vertexIndex = charInfo.vertexIndex; Color32[] vertexColors = textMeshPro.textInfo.meshInfo[meshIndex].colors32; if (charInfo.isVisible) { vertexColors[vertexIndex + 0] = startColors[i][0]; vertexColors[vertexIndex + 1] = startColors[i][1]; vertexColors[vertexIndex + 2] = startColors[i][2]; vertexColors[vertexIndex + 3] = startColors[i][3]; } if (charInfo.isVisible && charInfo.underlineVertexIndex > 0 && charInfo.underlineVertexIndex != underlineIndex && charInfo.underlineVertexIndex < vertexColors.Length) { underlineIndex = charInfo.underlineVertexIndex; for (int j = 0; j < 12; j++) { vertexColors[underlineIndex + j] = startColors[i][0]; } } } textMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All); }
void RevertLinkColor(int linkIndex) { TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex]; for (int i = 0; i < linkInfo.linkTextLength; i++) { // for each character in the link string int characterIndex = linkInfo.linkTextfirstCharacterIndex + i; // the character index into the entire text var charInfo = pTextMeshPro.textInfo.characterInfo[characterIndex]; int meshIndex = charInfo.materialReferenceIndex; // Get the index of the material / sub text object used by this character. int vertexIndex = charInfo.vertexIndex; // Get the index of the first vertex of this character. Color32[] vertexColors = pTextMeshPro.textInfo.meshInfo[meshIndex].colors32; // the colors for this character oldVertColors.Add(vertexColors.ToArray()); if (charInfo.isVisible) { for (int j = 0; j < 4; ++j) { vertexColors[vertexIndex + j] = oldVertColors[i][vertexIndex + j]; } } } // Update Geometry pTextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All); }
public void OnPointerClick(PointerEventData eventData) { if (linkIndex != -1) { linkInfo = texto.textInfo.linkInfo[linkIndex]; Application.OpenURL(linkInfo.GetLinkID()); } }
void OnLinkSelection(string linkID, string linkText, int linkIndex) { if (m_TextComponent != null) { TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex]; } Debug.Log("Link Index: " + linkIndex + " with ID [" + linkID + "] and Text \"" + linkText + "\" has been selected."); }
public void OnPointerClick(PointerEventData eventData) { int linkIndex = TMP_TextUtilities.FindIntersectingLink(GetComponent <TextMeshProUGUI>(), Input.mousePosition, Camera.main); if (linkIndex != -1) { TMP_LinkInfo linkInfo = GetComponent <TextMeshProUGUI>().textInfo.linkInfo[linkIndex]; Application.OpenURL(linkInfo.GetLinkID()); } }
private void UnhighlightLink(int linkIndex) { TMP_LinkInfo info = this.tmpText.textInfo.linkInfo[linkIndex]; string[] textArray1 = new string[] { "<u><link=", info.GetLinkID(), ">", info.GetLinkText(), "</link></u>" }; string newValue = string.Concat(textArray1); this.tmpText.text = this.tmpText.text.Replace(this.GetColoredLinkText(newValue), newValue); Cursors.SwitchToDefaultCursor(); }
private void HighlightLink(int linkIndex) { TMP_LinkInfo info = this.tmpText.textInfo.linkInfo[linkIndex]; string[] textArray1 = new string[] { "<u><link=", info.GetLinkID(), ">", info.GetLinkText(), "</link></u>" }; string oldValue = string.Concat(textArray1); this.tmpText.text = this.tmpText.text.Replace(oldValue, this.GetColoredLinkText(oldValue)); Cursors.SwitchToCursor(CursorType.HAND); }
private void IsCloserToPoint(Vector3 mousePoint, Vector3 testPoint, TMP_LinkInfo testLink, ref float minDistance, ref TMP_LinkInfo minLinkInfo) { float testDistance = Vector3.SqrMagnitude(mousePoint - testPoint); if (testDistance < minDistance) { minDistance = testDistance; minLinkInfo = testLink; } }
public void OnPointerClick(PointerEventData eventData) { int num = TMP_TextUtilities.FindIntersectingLink(this.text, Input.mousePosition, null); if (num != -1) { TMP_LinkInfo tmp_LinkInfo = this.text.textInfo.linkInfo[num]; Application.OpenURL(tmp_LinkInfo.GetLinkID()); } }
public void OnPointerClick(PointerEventData eventData) { int linkIndex = TMP_TextUtilities.FindIntersectingLink(tmpText, Input.mousePosition, cam); if (linkIndex != -1) { TMP_LinkInfo linkInfo = tmpText.textInfo.linkInfo[linkIndex]; Application.OpenURL(linkInfo.GetLinkID()); } }
// Send ID on Click to IdeaRator Brain public void OnPointerClick(PointerEventData eventData) { int linkIndex = TMP_TextUtilities.FindIntersectingLink(textMeshPro, Input.mousePosition, mainCamera); if (linkIndex != -1) { TMP_LinkInfo linkInfo = textMeshPro.textInfo.linkInfo[linkIndex]; ideaRatorBrain.changeIdea(linkInfo.GetLinkID()); } }
void CheckIfLinkAndOpenURL() { int linkIndex = TMP_TextUtilities.FindIntersectingLink(this.textMeshPro, Input.mousePosition, this.cam); if (linkIndex != -1) { TMP_LinkInfo linkInfo = this.textMeshPro.textInfo.linkInfo[linkIndex]; Application.OpenURL(linkInfo.GetLinkID()); } }
public void OnPointerClick(PointerEventData eventData) { int linkIndex = TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, null); if (linkIndex != -1) { TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex]; print(linkInfo.GetLinkID()); } }
public void OnPointerClick(PointerEventData eventData) { TMP_Text pTextMeshPro = GetComponent <TMP_Text>(); int linkIndex = TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, eventData.position, null); // If you are not in a Canvas using Screen Overlay, put your camera instead of null if (linkIndex != -1) // was a link clicked? { TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex]; Application.OpenURL(linkInfo.GetLinkID()); } }
public void OnPointerClick(PointerEventData eventData) { TextMeshProUGUI textMesh = GetComponent <TextMeshProUGUI>(); int linkIndex = TMP_TextUtilities.FindIntersectingLink(textMesh, eventData.pressPosition, Camera.main); if (linkIndex != -1) { TMP_LinkInfo linkInfo = textMesh.textInfo.linkInfo[linkIndex]; linkClicked?.Invoke(linkInfo.GetLinkID()); } }
public void OnPointerClick(PointerEventData eventData) { linkIndex = TMP_TextUtilities.FindIntersectingLink(textMeshPro, Input.mousePosition, GetComponent <Camera>()); if (linkIndex != -1) { TMP_LinkInfo linkInfo = textMeshPro.textInfo.linkInfo[linkIndex]; string dddd = linkInfo.GetLinkID(); string fff = linkInfo.GetLinkText(); } }