예제 #1
0
    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());
        }
    }
예제 #2
0
        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);
                    }
                }
            }
        }
예제 #3
0
        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();
        }
예제 #4
0
    //void LateUpdate()
    //{
    //    //if (isHoveringObject)
    //    //{
    //    //    int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, true);
    //    //}
    //    //else
    //    //{
    //    //    // Restore any character that may have been modified
    //    //    if (m_lastIndex != -1)
    //    //    {
    //    //        RestoreCachedVertexAttributes(m_lastIndex);
    //    //        m_lastIndex = -1;
    //    //    }
    //    //}


    //    //Check if Mouse intersects any words and if so assign a random color to that word.
    //    int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, m_Camera);

    //    // Clear previous word selection.
    //    if ( m_selectedWord != -1 && (wordIndex == -1 || wordIndex != m_selectedWord))
    //    {
    //        //TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[m_selectedWord];

    //        //ChangeWordColor(m_TextMeshPro, wInfo, originalColor);

    //        //m_selectedWord = -1;
    //    }

    //    if (isHoveringObject)
    //    {
    //        // Word Selection Handling
    //        //if (wordIndex != -1 && wordIndex != m_selectedWord && IsMouseOnLink("teste"))
    //        //{
    //        //    //m_selectedWord = wordIndex;

    //        //    //TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[wordIndex];

    //        //    //ChangeWordColor(m_TextMeshPro, wInfo, new Color32(255, 0, 0, 255));
    //        //}
    //        //else
    //        if (wordIndex != -1 && wordIndex != m_selectedWord)
    //        {
    //            m_selectedWord = wordIndex;

    //            TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[wordIndex];

    //            for (int charIndex = wInfo.firstCharacterIndex; charIndex < wInfo.characterCount; charIndex++)
    //            {
    //                EnlargeCharacter(wordIndex, charIndex);
    //            }
    //        }
    //        else
    //        {

    //        }
    //    }
    //    else
    //    {
    //        RestoreCachedVertexAttributes(m_lastIndex);
    //        m_lastIndex = -1;
    //    }
    //}

    public void ToBold(TMP_LinkInfo linkInfo)
    {
        if (!linkInfo.GetLinkID().ToUpper().Contains("HOVER_BOLD") ||
            linkInfo.GetLinkText().ToUpper().Contains("<B>"))
        {
            return;
        }

        var startIndex = linkInfo.linkIdFirstCharacterIndex + linkInfo.linkIdLength + 2;
        var endIndex   = startIndex + linkInfo.linkTextLength;

        var    boldContent = $"<b>{linkInfo.GetLinkText()}</b>";
        string newText     = linkInfo.textComponent.text.Substring(0, startIndex);

        newText += boldContent;
        newText += linkInfo.textComponent.text.Substring(endIndex);

        linkInfo.textComponent.text = newText;
    }
예제 #5
0
        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);
        }
    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();
        }
    }
예제 #7
0
 public void OnPointerClick(PointerEventData eventData)
 {
     linkIndex = TMP_TextUtilities.FindIntersectingLink(textMeshPro, Input.mousePosition, GetComponent <Camera>());
     if (linkIndex != -1)
     {
         TMP_LinkInfo linkInfo = textMeshPro.textInfo.linkInfo[linkIndex];
         //   TMP_TextUtilities.FindIntersectingWord(linkInfo.textComponent, linkInfo., GetComponent<Camera>())
         string dddd = linkInfo.GetLinkID();
         string fff  = linkInfo.GetLinkText();
         SetLinkToColor(linkIndex, Color.red);
         DotheThing(dddd, fff);
     }
 }
 public void OnPointerClick(PointerEventData eventData)
 {
     if ((enabled == true) && (parentCanvas != null))
     {
         // Check to see what the intersecting link is
         int linkIndex = TMP_TextUtilities.FindIntersectingLink(Label, Input.mousePosition, CanvasCamera);
         if (linkIndex != -1)
         {
             // Grab the link info
             TMP_LinkInfo linkInfo = Label.textInfo.linkInfo[linkIndex];
             OnLinkSelection.Invoke(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
         }
     }
 }
    public void OnPointerClick(PointerEventData eventData)
    {
        // Debug.Log("Click at POS: " + eventData.position + "  World POS: " + eventData.worldPosition);

        int linkIndex = TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, pCamera);

        if (linkIndex != -1)    // was a link clicked?
        {
            TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex];

            Debug.Log(string.Format("id: {0}, text: {1}", linkInfo.GetLinkID(), linkInfo.GetLinkText()));
            // open the link id as a url, which is the metadata we added in the text field
            //Application.OpenURL(linkInfo.GetLinkID());
        }
    }
예제 #10
0
    public void OnPointerDown(PointerEventData eventData)
    {
        // Check if mouse intersects with any links.
        // When clicking, get the index of the link we just clicked on/"selected" - if we didnt click on a link, itll be -1
        int linkIndex = TMP_TextUtilities.FindIntersectingLink(txt, Input.mousePosition, cam);

        // Handle link selection
        if (linkIndex < txt.textInfo.linkInfo.Length && linkIndex > -1)
        {
            // Get the linkInfo of the selected link we just clicked on (contains the id as our url, name and other useful stuff)
            TMP_LinkInfo linkInfo = txt.textInfo.linkInfo[linkIndex];

            // Open webpage of hyperlink, if the text of the hyperlink was retrieved
            if (!string.IsNullOrEmpty(linkInfo.GetLinkText()))
            {
                Application.OpenURL(linkInfo.GetLinkID());
            }
        }
    }
예제 #11
0
 void LateUpdate()
 {
     if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
     {
         if (Input.touches.Length > 0 || Input.GetMouseButton(0))
         {
             var n = Time.time;
             if (n > m_lastClick + CLICK_INTERVAL)
             {
                 m_lastClick = n;
                 int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, Input.mousePosition, m_Camera);
                 if (linkIndex != -1)
                 {
                     TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];
                     OnLinkSelection(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                 }
             }
         }
     }
 }
예제 #12
0
    public void OnPointerClick(PointerEventData eventData)
    {
        int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);

        Debug.Log("Click: ");
        if (linkIndex != -1)
        {
            TMP_LinkInfo linkInfo = m_TextMeshPro.textInfo.linkInfo[linkIndex];
            Debug.Log(linkInfo.GetLinkID());
            Debug.Log(linkInfo.GetLinkText());
        }
        else
        {
            int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, true);

            if (charIndex != -1)
            {
                TMP_CharacterInfo cInfo = m_TextMeshPro.textInfo.characterInfo[charIndex];
                ChangeLetterColor(m_TextMeshPro, cInfo, GetRadomColor());
                m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
            }
        }
    }
예제 #13
0
    private bool TryGetTooltip(out string content, out string header)
    {
        int linkIndex = TMP_TextUtilities.FindIntersectingLink(_linkedTextField,
                                                               KaynirTools.GetPointerRawPosition(),
                                                               null);

        if (linkIndex >= 0)
        {
            TMP_LinkInfo linkInfo = _linkedTextField.textInfo.linkInfo[linkIndex];
            int          localeID = GameMaster.Instance.GameSettings.CurrentLanguageID;

            content = _tooltipTables[localeID].GetEntry(linkInfo.GetLinkID())
                      .GetLocalizedString();
            header = linkInfo.GetLinkText();

            return(true);
        }
        else
        {
            content = null;
            header  = null;
            return(false);
        }
    }
 private void LateUpdate()
 {
     this.m_isHoveringObject = false;
     if (TMP_TextUtilities.IsIntersectingRectTransform(this.m_TextMeshPro.rectTransform, Input.mousePosition, Camera.main))
     {
         this.m_isHoveringObject = true;
     }
     if (this.m_isHoveringObject)
     {
         int num = TMP_TextUtilities.FindIntersectingCharacter(this.m_TextMeshPro, Input.mousePosition, Camera.main, true);
         if (num != -1 && num != this.m_lastCharIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
         {
             this.m_lastCharIndex = num;
             int       materialReferenceIndex = this.m_TextMeshPro.textInfo.characterInfo[num].materialReferenceIndex;
             int       vertexIndex            = this.m_TextMeshPro.textInfo.characterInfo[num].vertexIndex;
             Color32   color  = new Color32((byte)UnityEngine.Random.Range(0, 255), (byte)UnityEngine.Random.Range(0, 255), (byte)UnityEngine.Random.Range(0, 255), byte.MaxValue);
             Color32[] colors = this.m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].colors32;
             colors[vertexIndex]     = color;
             colors[vertexIndex + 1] = color;
             colors[vertexIndex + 2] = color;
             colors[vertexIndex + 3] = color;
             this.m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].mesh.colors32 = colors;
         }
         int num2 = TMP_TextUtilities.FindIntersectingLink(this.m_TextMeshPro, Input.mousePosition, this.m_Camera);
         if ((num2 == -1 && this.m_selectedLink != -1) || num2 != this.m_selectedLink)
         {
             this.m_selectedLink = -1;
         }
         if (num2 != -1 && num2 != this.m_selectedLink)
         {
             this.m_selectedLink = num2;
             TMP_LinkInfo tmp_LinkInfo = this.m_TextMeshPro.textInfo.linkInfo[num2];
             Debug.Log(string.Concat(new string[]
             {
                 "Link ID: \"",
                 tmp_LinkInfo.GetLinkID(),
                 "\"   Link Text: \"",
                 tmp_LinkInfo.GetLinkText(),
                 "\""
             }));
             Vector3 zero = Vector3.zero;
             RectTransformUtility.ScreenPointToWorldPointInRectangle(this.m_TextMeshPro.rectTransform, Input.mousePosition, this.m_Camera, out zero);
             string linkID = tmp_LinkInfo.GetLinkID();
             if (linkID != null)
             {
                 if (!(linkID == "id_01"))
                 {
                     if (!(linkID == "id_02"))
                     {
                     }
                 }
             }
         }
         int num3 = TMP_TextUtilities.FindIntersectingWord(this.m_TextMeshPro, Input.mousePosition, Camera.main);
         if (num3 != -1 && num3 != this.m_lastWordIndex)
         {
             this.m_lastWordIndex = num3;
             TMP_WordInfo tmp_WordInfo = this.m_TextMeshPro.textInfo.wordInfo[num3];
             Vector3      position     = this.m_TextMeshPro.transform.TransformPoint(this.m_TextMeshPro.textInfo.characterInfo[tmp_WordInfo.firstCharacterIndex].bottomLeft);
             position = Camera.main.WorldToScreenPoint(position);
             Color32[] colors2 = this.m_TextMeshPro.textInfo.meshInfo[0].colors32;
             Color32   color2  = new Color32((byte)UnityEngine.Random.Range(0, 255), (byte)UnityEngine.Random.Range(0, 255), (byte)UnityEngine.Random.Range(0, 255), byte.MaxValue);
             for (int i = 0; i < tmp_WordInfo.characterCount; i++)
             {
                 int vertexIndex2 = this.m_TextMeshPro.textInfo.characterInfo[tmp_WordInfo.firstCharacterIndex + i].vertexIndex;
                 colors2[vertexIndex2]     = color2;
                 colors2[vertexIndex2 + 1] = color2;
                 colors2[vertexIndex2 + 2] = color2;
                 colors2[vertexIndex2 + 3] = color2;
             }
             this.m_TextMeshPro.mesh.colors32 = colors2;
         }
     }
 }
예제 #15
0
    void LateUpdate()
    {
        // タッチ座標とマウス座標の両方で機能させる
        var touchPosition = Input.touchCount <= 0 ?
                            Input.mousePosition : (Vector3)Input.GetTouch(0).position;

        var touchDown = Input.touchCount <= 0 ? Input.GetMouseButtonDown(0) : true;

        // サンプルでマウス座標だったところをtouchPositionに置換
        if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, touchPosition, m_Camera))
        {
            #region Example of Character Selection
            int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, touchPosition, m_Camera, true);
            if (charIndex != -1 && charIndex != m_lastCharIndex)
            {
                m_lastCharIndex = charIndex;

                // Send event to any event listeners.
                SendOnCharacterSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
            }
            #endregion


            #region Example of Word Selection
            // Check if Mouse intersects any words and if so assign a random color to that word.
            int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextComponent, touchPosition, m_Camera);
            if (wordIndex != -1 && wordIndex != m_lastWordIndex)
            {
                m_lastWordIndex = wordIndex;

                // Get the information about the selected word.
                TMP_WordInfo wInfo = m_TextComponent.textInfo.wordInfo[wordIndex];

                // Send the event to any listeners.
                SendOnWordSelection(wInfo.GetWord(), wInfo.firstCharacterIndex, wInfo.characterCount);
            }
            #endregion


            #region Example of Line Selection
            // Check if Mouse intersects any words and if so assign a random color to that word.
            int lineIndex = TMP_TextUtilities.FindIntersectingLine(m_TextComponent, touchPosition, m_Camera);
            if (lineIndex != -1 && lineIndex != m_lastLineIndex)
            {
                m_lastLineIndex = lineIndex;

                // Get the information about the selected word.
                TMP_LineInfo lineInfo = m_TextComponent.textInfo.lineInfo[lineIndex];

                // Send the event to any listeners.
                char[] buffer = new char[lineInfo.characterCount];
                for (int i = 0; i < lineInfo.characterCount && i < m_TextComponent.textInfo.characterInfo.Length; i++)
                {
                    buffer[i] = m_TextComponent.textInfo.characterInfo[i + lineInfo.firstCharacterIndex].character;
                }

                string lineText = new string(buffer);
                SendOnLineSelection(lineText, lineInfo.firstCharacterIndex, lineInfo.characterCount);
            }
            #endregion


            #region Example of Link Handling
            // 入力があった時のみ、Linkとの当たり判定をとります
            if (touchDown)
            {
                // Check if mouse intersects with any links.
                int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, touchPosition, m_Camera);

                // Clear previous link selection if one existed.
                if ((linkIndex == -1 && m_selectedLink != -1) || linkIndex != m_selectedLink)
                {
                    SendOnLinkSelection(string.Empty, string.Empty, linkIndex);
                    m_selectedLink = -1;
                }

                // Handle new Link selection.
                if (linkIndex != -1 && linkIndex != m_selectedLink)
                {
                    m_selectedLink = linkIndex;

                    // Get information about the link.
                    TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];

                    // Send the event to any listeners.
                    SendOnLinkSelection(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                }
            }
            #endregion
        }
        // 範囲外をタップした時は、選択状態を解除します
        else
        {
            #region Example of Link Handling
            if (touchDown)
            {
                if (m_selectedLink != -1)
                {
                    m_selectedLink = -1;
                    SendOnLinkSelection(string.Empty, string.Empty, m_selectedLink);
                }
            }
            #endregion
        }
    }
예제 #16
0
        void LateUpdate()
        {
            if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
            {
                #region Example of Character or Sprite Hover
                int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, m_Camera, true);
                if (charIndex != -1 && charIndex != m_lastCharIndex)
                {
                    m_lastCharIndex = charIndex;

                    TMP_TextElementType elementType = m_TextComponent.textInfo.characterInfo[charIndex].elementType;

                    if (elementType == TMP_TextElementType.Character)
                    {
                        SendOnCharacterHover(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                    }
                    else if (elementType == TMP_TextElementType.Sprite)
                    {
                        SendOnSpriteHover(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                    }
                }
                #endregion


                #region Example of Word Hover
                int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextComponent, Input.mousePosition, m_Camera);
                if (wordIndex != -1 && wordIndex != m_lastWordIndex)
                {
                    m_lastWordIndex = wordIndex;

                    TMP_WordInfo wInfo = m_TextComponent.textInfo.wordInfo[wordIndex];

                    SendOnWordHover(wInfo.GetWord(), wInfo.firstCharacterIndex, wInfo.characterCount);
                }

                if (wordIndex != -1 && Input.GetMouseButtonDown(0))
                {
                    TMP_WordInfo wInfo = m_TextComponent.textInfo.wordInfo[wordIndex];
                    SendOnWordSelect(m_TextComponent, wInfo, wordIndex);
                    m_TextComponent.textInfo.wordInfo[70].firstCharacterIndex = 1000;
                }

                #endregion


                #region Example of Line Hover
                int lineIndex = TMP_TextUtilities.FindIntersectingLine(m_TextComponent, Input.mousePosition, m_Camera);
                if (lineIndex != -1 && lineIndex != m_lastLineIndex)
                {
                    m_lastLineIndex = lineIndex;

                    TMP_LineInfo lineInfo = m_TextComponent.textInfo.lineInfo[lineIndex];

                    char[] buffer = new char[lineInfo.characterCount];
                    for (int i = 0; i < lineInfo.characterCount && i < m_TextComponent.textInfo.characterInfo.Length; i++)
                    {
                        buffer[i] = m_TextComponent.textInfo.characterInfo[i + lineInfo.firstCharacterIndex].character;
                    }

                    string lineText = new string(buffer);
                    SendOnLineHover(lineText, lineInfo.firstCharacterIndex, lineInfo.characterCount);
                }
                #endregion


                #region Example of Link Hover
                int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, Input.mousePosition, m_Camera);

                if (linkIndex != -1 && linkIndex != m_selectedLink)
                {
                    m_selectedLink = linkIndex;

                    TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];

                    SendOnLinkHover(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                }
                #endregion
            }
        }
예제 #17
0
        private void LateUpdate()
        {
            m_isHoveringObject = false;

            if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextMeshPro.rectTransform, Input.mousePosition, Camera.main))
            {
                m_isHoveringObject = true;
            }

            if (m_isHoveringObject)
            {
                #region Example of Character Selection

                int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, Camera.main, true);
                if (charIndex != -1 && charIndex != m_lastCharIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
                {
                    //Debug.Log("[" + m_TextMeshPro.textInfo.characterInfo[charIndex].character + "] has been selected.");

                    m_lastCharIndex = charIndex;

                    int meshIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].materialReferenceIndex;

                    int vertexIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].vertexIndex;

                    Color32 c = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);

                    Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;

                    vertexColors[vertexIndex + 0] = c;
                    vertexColors[vertexIndex + 1] = c;
                    vertexColors[vertexIndex + 2] = c;
                    vertexColors[vertexIndex + 3] = c;

                    //m_TextMeshPro.mesh.colors32 = vertexColors;
                    m_TextMeshPro.textInfo.meshInfo[meshIndex].mesh.colors32 = vertexColors;
                }

                #endregion Example of Character Selection

                #region Example of Link Handling

                // Check if mouse intersects with any links.
                int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);

                // Clear previous link selection if one existed.
                if ((linkIndex == -1 && m_selectedLink != -1) || linkIndex != m_selectedLink)
                {
                    //m_TextPopup_RectTransform.gameObject.SetActive(false);
                    m_selectedLink = -1;
                }

                // Handle new Link selection.
                if (linkIndex != -1 && linkIndex != m_selectedLink)
                {
                    m_selectedLink = linkIndex;

                    TMP_LinkInfo linkInfo = m_TextMeshPro.textInfo.linkInfo[linkIndex];

                    // The following provides an example of how to access the link properties.
                    Debug.Log("Link ID: \"" + linkInfo.GetLinkID() + "\"   Link Text: \"" + linkInfo.GetLinkText() + "\""); // Example of how to retrieve the Link ID and Link Text.

                    RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out Vector3 worldPointInRectangle);

                    switch (linkInfo.GetLinkID())
                    {
                    case "id_01":     // 100041637: // id_01
                                      //m_TextPopup_RectTransform.position = worldPointInRectangle;
                                      //m_TextPopup_RectTransform.gameObject.SetActive(true);
                                      //m_TextPopup_TMPComponent.text = k_LinkText + " ID 01";
                        break;

                    case "id_02":     // 100041638: // id_02
                                      //m_TextPopup_RectTransform.position = worldPointInRectangle;
                                      //m_TextPopup_RectTransform.gameObject.SetActive(true);
                                      //m_TextPopup_TMPComponent.text = k_LinkText + " ID 02";
                        break;
                    }
                }

                #endregion Example of Link Handling

                #region Example of Word Selection

                // Check if Mouse intersects any words and if so assign a random color to that word.
                int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, Camera.main);
                if (wordIndex != -1 && wordIndex != m_lastWordIndex)
                {
                    m_lastWordIndex = wordIndex;

                    TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[wordIndex];

                    Vector3 wordPOS = m_TextMeshPro.transform.TransformPoint(m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex].bottomLeft);
                    wordPOS = Camera.main.WorldToScreenPoint(wordPOS);

                    //Debug.Log("Mouse Position: " + Input.mousePosition.ToString("f3") + "  Word Position: " + wordPOS.ToString("f3"));

                    Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[0].colors32;

                    Color32 c = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
                    for (int i = 0; i < wInfo.characterCount; i++)
                    {
                        int vertexIndex = m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex + i].vertexIndex;

                        vertexColors[vertexIndex + 0] = c;
                        vertexColors[vertexIndex + 1] = c;
                        vertexColors[vertexIndex + 2] = c;
                        vertexColors[vertexIndex + 3] = c;
                    }

                    m_TextMeshPro.mesh.colors32 = vertexColors;
                }

                #endregion Example of Word Selection
            }
        }
예제 #18
0
        void LateUpdate()
        {
            if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
            {
                #region Example of Character or Sprite Selection
                var charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, m_Camera, true);
                if (charIndex != -1 && charIndex != m_lastCharIndex)
                {
                    m_lastCharIndex = charIndex;

                    TMP_TextElementType elementType = m_TextComponent.textInfo.characterInfo[charIndex].elementType;

                    // Send event to any event listeners depending on whether it is a character or sprite.
                    if (elementType == TMP_TextElementType.Character)
                    {
                        SendOnCharacterSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                    }
                    else if (elementType == TMP_TextElementType.Sprite)
                    {
                        SendOnSpriteSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                    }
                }
                #endregion


                #region Example of Word Selection
                // Check if Mouse intersects any words and if so assign a random color to that word.
                var wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextComponent, Input.mousePosition, m_Camera);
                if (wordIndex != -1 && wordIndex != m_lastWordIndex)
                {
                    m_lastWordIndex = wordIndex;

                    // Get the information about the selected word.
                    TMP_WordInfo wInfo = m_TextComponent.textInfo.wordInfo[wordIndex];

                    // Send the event to any listeners.
                    SendOnWordSelection(wInfo.GetWord(), wInfo.firstCharacterIndex, wInfo.characterCount);
                }
                #endregion


                #region Example of Line Selection
                // Check if Mouse intersects any words and if so assign a random color to that word.
                var lineIndex = TMP_TextUtilities.FindIntersectingLine(m_TextComponent, Input.mousePosition, m_Camera);
                if (lineIndex != -1 && lineIndex != m_lastLineIndex)
                {
                    m_lastLineIndex = lineIndex;

                    // Get the information about the selected word.
                    TMP_LineInfo lineInfo = m_TextComponent.textInfo.lineInfo[lineIndex];

                    // Send the event to any listeners.
                    var buffer = new char[lineInfo.characterCount];
                    for (var i = 0; i < lineInfo.characterCount && i < m_TextComponent.textInfo.characterInfo.Length; i++)
                    {
                        buffer[i] = m_TextComponent.textInfo.characterInfo[i + lineInfo.firstCharacterIndex].character;
                    }

                    var lineText = new string(buffer);
                    SendOnLineSelection(lineText, lineInfo.firstCharacterIndex, lineInfo.characterCount);
                }
                #endregion


                #region Example of Link Handling
                // Check if mouse intersects with any links.
                var linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, Input.mousePosition, m_Camera);

                // Handle new Link selection.
                if (linkIndex != -1 && linkIndex != m_selectedLink)
                {
                    m_selectedLink = linkIndex;

                    // Get information about the link.
                    TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];

                    // Send the event to any listeners.
                    SendOnLinkSelection(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                }
                #endregion
            }
        }
예제 #19
0
    /// <summary>
    /// Override Unity Function
    /// </summary>
    void LateUpdate()
    {
        // タッチ座標とマウス座標の両方で機能させる
        var touchPosition = Input.touchCount <= 0 ?
                            Input.mousePosition : (Vector3)Input.GetTouch(0).position;

        var touchDown = Input.touchCount <= 0 ? Input.GetMouseButtonDown(0) : true;

        //	本体の矩形内をタップしたかどうか
        if (TMP_TextUtilities.IsIntersectingRectTransform(textComponent.rectTransform, touchPosition, cachedCamera))
        {
            //	文字のタップ検索
            int charIndex = TMP_TextUtilities.FindIntersectingCharacter(textComponent, touchPosition, cachedCamera, true);
            if (charIndex != -1 && charIndex != lastCharIndex)
            {
                lastCharIndex = charIndex;

                TMP_CharacterInfo info = textComponent.textInfo.characterInfo[charIndex];
                this.onCharacterSelection?.Invoke(info.character, charIndex);
            }

            //	単語のタップ検索
            int wordIndex = TMP_TextUtilities.FindIntersectingWord(textComponent, touchPosition, cachedCamera);
            if (wordIndex != -1 && wordIndex != lastWordIndex)
            {
                lastWordIndex = wordIndex;

                TMP_WordInfo info = textComponent.textInfo.wordInfo[wordIndex];
                this.onWordSelection?.Invoke(info.GetWord(), info.firstCharacterIndex, info.characterCount);
            }

            // 行のタップ検索
            int lineIndex = TMP_TextUtilities.FindIntersectingLine(textComponent, touchPosition, cachedCamera);
            if (lineIndex != -1 && lineIndex != lastLineIndex)
            {
                lastLineIndex = lineIndex;

                TMP_LineInfo lineInfo = textComponent.textInfo.lineInfo[lineIndex];

                // Send the event to any listeners.
                char[] buffer = new char[lineInfo.characterCount];
                for (int i = 0; i < lineInfo.characterCount && i < textComponent.textInfo.characterInfo.Length; i++)
                {
                    buffer[i] = textComponent.textInfo.characterInfo[i + lineInfo.firstCharacterIndex].character;
                }

                string lineText = new string(buffer);
                this.onLineSelection?.Invoke(lineText, lineInfo.firstCharacterIndex, lineInfo.characterCount);
            }

            // リンクのタップ検索(入力があった時のみ)
            if (touchDown)
            {
                int linkIndex = TMP_TextUtilities.FindIntersectingLink(textComponent, touchPosition, cachedCamera);

                // 空振り や 別のリンク をタップした時は、選択解除を通知します。
                if ((linkIndex == -1 && lastLinkIndex != -1) || linkIndex != lastLinkIndex)
                {
                    lastLinkIndex = -1;

                    this.onLinkSelection?.Invoke(string.Empty, string.Empty, linkIndex);
                }

                // 新しいリンクをタップした時は、選択を通知します
                if (linkIndex != -1 && linkIndex != lastLinkIndex)
                {
                    lastLinkIndex = linkIndex;

                    TMP_LinkInfo linkInfo = textComponent.textInfo.linkInfo[linkIndex];
                    this.onLinkSelection?.Invoke(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                }
            }
        }
        else
        {
            // リンクの選択解除(範囲外をタップした時は、選択解除を通知します)
            if (touchDown)
            {
                if (lastLinkIndex != -1)
                {
                    lastLinkIndex = -1;
                    this.onLinkSelection?.Invoke(string.Empty, string.Empty, lastLinkIndex);
                }
            }
        }
    }
예제 #20
0
    public bool TestForHit(Vector2 screenPoint, Camera eventCamera, Action <string, int> block)
    {
        TMP_TextInfo textInfo = null;
        TMP_Text     text     = null;

        if (entity.text != null)
        {
            text     = entity.text;
            textInfo = entity.text.textInfo;
        }
        if (entity.textGUI != null)
        {
            text     = entity.textGUI;
            textInfo = entity.textGUI.textInfo;
        }

        if (textInfo != null)
        {
            // find the closest link to our touch point
            float        minDistance = 999999;
            TMP_LinkInfo minLinkInfo = new TMP_LinkInfo();

            Transform rectTransform = text.transform;
            Vector3   position      = screenPoint;

            // Convert position into Worldspace coordinates
            TMP_TextUtilities.ScreenPointToWorldPointInRectangle(rectTransform, position, eventCamera, out position);

            for (int i = 0; i < text.textInfo.linkCount; i++)
            {
                TMP_LinkInfo linkInfo = text.textInfo.linkInfo [i];

                bool isBeginRegion = false;

                Vector3 bl = Vector3.zero;
                Vector3 tl = Vector3.zero;
                Vector3 br = Vector3.zero;
                Vector3 tr = Vector3.zero;

                // Iterate through each character of the word
                for (int j = 0; j < linkInfo.linkTextLength; j++)
                {
                    int characterIndex = linkInfo.linkTextfirstCharacterIndex + j;
                    TMP_CharacterInfo currentCharInfo = text.textInfo.characterInfo [characterIndex];
                    int currentLine = currentCharInfo.lineNumber;

                    // Check if Link characters are on the current page
                    if (text.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != text.pageToDisplay)
                    {
                        continue;
                    }

                    if (isBeginRegion == false)
                    {
                        isBeginRegion = true;

                        bl = rectTransform.TransformPoint(new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0));
                        tl = rectTransform.TransformPoint(new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0));

                        // If Word is one character
                        if (linkInfo.linkTextLength == 1)
                        {
                            isBeginRegion = false;

                            br = rectTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
                            tr = rectTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));

                            // Check for Intersection
                            IsCloserToPoint(position, bl, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint(position, tl, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint(position, tr, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint(position, br, linkInfo, ref minDistance, ref minLinkInfo);
                            IsCloserToPoint(position, (bl + br + tl + tr) * 0.25f, linkInfo, ref minDistance, ref minLinkInfo);
                        }
                    }

                    // Last Character of Word
                    if (isBeginRegion && j == linkInfo.linkTextLength - 1)
                    {
                        isBeginRegion = false;

                        br = rectTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
                        tr = rectTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));

                        IsCloserToPoint(position, bl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, tl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, tr, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, br, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, (bl + br + tl + tr) * 0.25f, linkInfo, ref minDistance, ref minLinkInfo);
                    }
                    // If Word is split on more than one line.
                    else if (isBeginRegion && currentLine != text.textInfo.characterInfo [characterIndex + 1].lineNumber)
                    {
                        isBeginRegion = false;

                        br = rectTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.descender, 0));
                        tr = rectTransform.TransformPoint(new Vector3(currentCharInfo.topRight.x, currentCharInfo.ascender, 0));

                        IsCloserToPoint(position, bl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, tl, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, tr, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, br, linkInfo, ref minDistance, ref minLinkInfo);
                        IsCloserToPoint(position, (bl + br + tl + tr) * 0.25f, linkInfo, ref minDistance, ref minLinkInfo);
                    }
                }
            }

            int linkIdx = Array.IndexOf(text.textInfo.linkInfo, minLinkInfo);
            if (linkIdx >= 0)
            {
                if (block != null)
                {
                    block(minLinkInfo.GetLinkText(), linkIdx);
                }
                return(true);
            }
        }

        return(false);
    }
예제 #21
0
        public void OnPointerClick(PointerEventData eventData)
        {
            //Debug.Log("Click at POS: " + eventData.position + "  World POS: " + eventData.worldPosition);

            // Check if Mouse Intersects any of the characters. If so, assign a random color.
            // I'm not using this
            #region Character Selection Handling

            /*
             * int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, true);
             * if (charIndex != -1 && charIndex != m_lastIndex)
             * {
             *  //Debug.Log("Character [" + m_TextMeshPro.textInfo.characterInfo[index].character + "] was selected at POS: " + eventData.position);
             *  m_lastIndex = charIndex;
             *
             *  Color32 c = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
             *  int vertexIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].vertexIndex;
             *
             *  UIVertex[] uiVertices = m_TextMeshPro.textInfo.meshInfo.uiVertices;
             *
             *  uiVertices[vertexIndex + 0].color = c;
             *  uiVertices[vertexIndex + 1].color = c;
             *  uiVertices[vertexIndex + 2].color = c;
             *  uiVertices[vertexIndex + 3].color = c;
             *
             *  m_TextMeshPro.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
             * }
             */
            #endregion

            // Not using this
            #region Word Selection Handling
            //Check if Mouse intersects any words and if so assign a random color to that word.

            /*
             * int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, m_Camera);
             *
             * // Clear previous word selection.
             * if (m_TextPopup_RectTransform != null && m_selectedWord != -1 && (wordIndex == -1 || wordIndex != m_selectedWord))
             * {
             *  TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[m_selectedWord];
             *
             *  // Get a reference to the uiVertices array.
             *  UIVertex[] uiVertices = m_TextMeshPro.textInfo.meshInfo.uiVertices;
             *
             *  // Iterate through each of the characters of the word.
             *  for (int i = 0; i < wInfo.characterCount; i++)
             *  {
             *      int vertexIndex = m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex + i].vertexIndex;
             *
             *      Color32 c = uiVertices[vertexIndex + 0].color.Tint(1.33333f);
             *
             *      uiVertices[vertexIndex + 0].color = c;
             *      uiVertices[vertexIndex + 1].color = c;
             *      uiVertices[vertexIndex + 2].color = c;
             *      uiVertices[vertexIndex + 3].color = c;
             *  }
             *
             *  m_TextMeshPro.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
             *
             *  m_selectedWord = -1;
             * }
             *
             * // Handle word selection
             * if (wordIndex != -1 && wordIndex != m_selectedWord)
             * {
             *  m_selectedWord = wordIndex;
             *
             *  TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[wordIndex];
             *
             *  // Get a reference to the uiVertices array.
             *  UIVertex[] uiVertices = m_TextMeshPro.textInfo.meshInfo.uiVertices;
             *
             *  // Iterate through each of the characters of the word.
             *  for (int i = 0; i < wInfo.characterCount; i++)
             *  {
             *      int vertexIndex = m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex + i].vertexIndex;
             *
             *      Color32 c = uiVertices[vertexIndex + 0].color.Tint(0.75f);
             *
             *      uiVertices[vertexIndex + 0].color = c;
             *      uiVertices[vertexIndex + 1].color = c;
             *      uiVertices[vertexIndex + 2].color = c;
             *      uiVertices[vertexIndex + 3].color = c;
             *  }
             *
             *  m_TextMeshPro.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
             * }
             */
            #endregion


            #region Link Selection Handling

            // Check if Mouse intersects any links
            int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
            if (linkIndex != -1)
            {
                TMP_LinkInfo linkInfo = m_TextMeshPro.textInfo.linkInfo[linkIndex];
                string       linkName = linkInfo.GetLinkID();
                switch (linkName)
                {
                case "id_tree":     // species of tree
                    treeReader.Read(linkInfo.GetLinkText());
                    break;

                case "id_quarry":     // type of stone
                    treeReader.ReadQuarry(linkInfo.GetLinkText());
                    break;

                default:     // underlying geology
                    treeReader.ReadStone(linkInfo.GetLinkID());
                    break;
                }
            }
            #endregion
        }
예제 #22
0
    public void OnPointerClick(PointerEventData eventData)
    {
        // Debug.Log("Click at POS: " + eventData.position + "  World POS: " + eventData.worldPosition);

        int linkIndex = TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, pCamera);

        if (linkIndex != -1)
        {
            // was a link clicked?
            TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex];


            if (linkInfo.GetLinkID().Contains("http"))
            {
                // open the link id as a url, which is the metadata we added in the text field
                Application.OpenURL(linkInfo.GetLinkID());
            }
            else
            {
                switch (linkInfo.GetLinkID())
                {
                case "learnMore1":
                    optInDialogNavigation.ShowLearnMore1();
                    break;

                case "learnMore2":
                    optInDialogNavigation.ShowLearnMore2();
                    break;

                default:
                    Debug.Log(string.Format("don't recognize the link id: {0}, text: {1}", linkInfo.GetLinkID(), linkInfo.GetLinkText()));
                    return;
                }
            }
        }
    }