Beispiel #1
0
 private void Update()
 {
     if (TMP_TextUtilities.IsIntersectingRectTransform(tmpText.rectTransform, Input.mousePosition, _camera))
     {
         Debug.Log("hovering text");
     }
 }
Beispiel #2
0
    void LateUpdate()
    {
        Vector3 mousePosition = Mouse.current.position.ReadValue();
        // is the cursor in the correct region (above the text area) and furthermore, in the link region?
        var isHoveringOver = TMP_TextUtilities.IsIntersectingRectTransform(pTextMeshPro.rectTransform, mousePosition, pCamera);
        int linkIndex      = isHoveringOver ? TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, mousePosition, pCamera) :
                             -1;

        // Clear previous link selection if one existed.
        if (pCurrentLink != -1 && linkIndex != pCurrentLink)
        {
            // Debug.Log("Clear old selection");
            SetLinkToColor(pCurrentLink, (linkIdx, vertIdx) => pOriginalVertexColors[linkIdx][vertIdx]);
            pOriginalVertexColors.Clear();
            pCurrentLink = -1;
        }

        // Handle new link selection.
        if (linkIndex != -1 && linkIndex != pCurrentLink)
        {
            // Debug.Log("New selection");
            pCurrentLink = linkIndex;
            if (doesColorChangeOnHover)
            {
                pOriginalVertexColors = SetLinkToColor(linkIndex, (_linkIdx, _vertIdx) => hoverColor);
            }
        }

        // Debug.Log(string.Format("isHovering: {0}, link: {1}", isHoveringOver, linkIndex));
    }
Beispiel #3
0
        private void LateUpdate()
        {
            // Is the cursor in the correct region (above the text area) and furthermore, in the link region?
            bool isHoveringOver = TMP_TextUtilities.IsIntersectingRectTransform(_textMeshPro.rectTransform,
                                                                                Mouse.current.position.ReadValue(),
                                                                                _camera);
            int linkIndex = isHoveringOver ? TMP_TextUtilities.FindIntersectingLink(_textMeshPro,
                                                                                    Mouse.current.position.ReadValue(),
                                                                                    _camera) : -1;

            // Clear previous link selection if one existed.
            if (_currentLink != -1 && linkIndex != _currentLink)
            {
                SetLinkToColor(_currentLink, (linkIdx, vertIdx) => _originalVertexColors[linkIdx][vertIdx]);
                _originalVertexColors.Clear();
                _currentLink = -1;
            }

            // Handle new link selection.
            if (linkIndex == -1 ||
                linkIndex == _currentLink)
            {
                return;
            }

            _currentLink = linkIndex;
            if (_doesColorChangeOnHover)
            {
                _originalVertexColors = SetLinkToColor(linkIndex, (linkIdx, vertIdx) => _hoverColor);
            }
        }
    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
        }
    }
Beispiel #5
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0) && TMP_TextUtilities.IsIntersectingRectTransform(GetComponent <RectTransform>(), Input.mousePosition, null))
        {
            var wordIndex = TMP_TextUtilities.FindIntersectingWord(GetComponent <TextMeshProUGUI>(), Input.mousePosition, null);

            if (wordIndex != -1)
            {
                string LastClickedWord = GetComponent <TextMeshProUGUI>().textInfo.wordInfo[wordIndex].GetWord();

                //check if word is found in carddatabase
                if (LastClickedWord.Length == 3)
                {
                    if (database.getCardById(LastClickedWord) != null)
                    {
                        cardDisplay.SetCurrentCard(database.getCardById(LastClickedWord).GetComponent <Card>());
                    }
                }
            }
        }
        if (updateTimer > updateRate)
        {
            if (logBuffer.Count > 0)
            {
                string text = logBuffer[0];
                AddLog(text);
                logBuffer.Remove(text);
            }
            updateTimer = 0;
        }
        else
        {
            updateTimer += Time.deltaTime;
        }
    }
Beispiel #6
0
    private void LateUpdate()
    {
        var position = Mouse.current.position.ReadValue();
        var hovering = TMP_TextUtilities.IsIntersectingRectTransform(choiceText.rectTransform, position, hoverCam);

        if (hovering)
        {
            var linkIndex = TMP_TextUtilities.FindIntersectingLink(choiceText, position, hoverCam);
            if (linkIndex != -1 && hoverLink != linkIndex)
            {
                if (hoverLink != -1)
                {
                    HighlightLink(hoverLink, baseColor);
                }

                hoverLink = linkIndex;
                HighlightLink(hoverLink, hoverColor);
            }
        }
        else if (hoverLink != -1)
        {
            HighlightLink(hoverLink, baseColor);
            hoverLink = -1;
        }
    }
Beispiel #7
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);
                 }
             }
         }
     }
 }
Beispiel #8
0
 private void LateUpdate()
 {
     if (TMP_TextUtilities.IsIntersectingRectTransform(this.tmpText.rectTransform, Input.mousePosition, this.cam))
     {
         int linkIndex = TMP_TextUtilities.FindIntersectingLink(this.tmpText, Input.mousePosition, this.cam);
         if ((this.selectedLink != -1) && (linkIndex != this.selectedLink))
         {
             this.UnhighlightLink(this.selectedLink);
         }
         if ((linkIndex != -1) && (linkIndex != this.selectedLink))
         {
             this.HighlightLink(linkIndex);
         }
         this.selectedLink = linkIndex;
     }
     if (Input.GetMouseButtonDown(0) && (this.selectedLink != -1))
     {
         Application.OpenURL(this.tmpText.textInfo.linkInfo[this.selectedLink].GetLinkID());
     }
 }
Beispiel #9
0
        private void LateUpdate()
        {
            var newLinkIndex = TMP_TextUtilities.IsIntersectingRectTransform(text.rectTransform, Input.mousePosition, camera)
                                ? TMP_TextUtilities.FindIntersectingLink(text, Input.mousePosition, camera)
                                : -1;

            if (newLinkIndex == hoveredLinkIndex)
            {
                return;
            }
            if (hoveredLinkIndex >= 0)
            {
                SetLinkColor(hoveredLinkIndex, _linkDefaultColor);
            }
            hoveredLinkIndex = newLinkIndex;
            if (hoveredLinkIndex >= 0)
            {
                SetLinkColor(hoveredLinkIndex, _linkHoverColor);
            }
        }
Beispiel #10
0
        public IEnumerator Event(SharedData share, SharedVariable variable, EventData e)
        {
            // TouchScreenに触れた
            if (e.intParameter == 0)
            {
                // テキスト中のリンクに触れた
                var touchPosition = Input.touchCount <= 0 ?
                                    Input.mousePosition : (Vector3)Input.GetTouch(0).position;

                if (TMP_TextUtilities.IsIntersectingRectTransform(share.view.Text.rectTransform, touchPosition, null))
                {
                    int linkIndex = TMP_TextUtilities.FindIntersectingLink(share.view.Text, touchPosition, null);
                    if (linkIndex != -1)
                    {
                        yield break;
                    }
                }

                isNext = true;
            }
            yield break;
        }
Beispiel #11
0
        private void LateUpdate()
        {
            var isHoveringOver =
                TMP_TextUtilities.IsIntersectingRectTransform(_textMeshProUgui.rectTransform, Input.mousePosition,
                                                              _camera);
            var linkIndex = isHoveringOver
                ? TMP_TextUtilities.FindIntersectingLink(_textMeshProUgui, Input.mousePosition, _camera)
                : -1;

            var i = 0;

            foreach (var linkInfo in _textMeshProUgui.textInfo.linkInfo)
            {
                SetLinkToColor(i, new Color32(255, 255, 225, 255));
                i++;
            }

            if (isHoveringOver && linkIndex != -1)
            {
                SetLinkToColor(linkIndex, new Color32(255, 122, 57, 255));
            }
        }
Beispiel #12
0
        void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
        {
            if (!TMP_TextUtilities.IsIntersectingRectTransform(_textUI.rectTransform, eventData.position, _camera))
            {
                return;
            }

            // Check if mouse intersects with any links.
            int linkIndex = TMP_TextUtilities.FindIntersectingLink(_textUI, eventData.position, _camera);

            // Handle new Link selection.
            if (linkIndex != -1)
            {
                // Get information about the link.
                TMP_LinkInfo linkInfo = _textUI.textInfo.linkInfo[linkIndex];

                // Send the event to any listeners.
                if (OnLinkClick != null)
                {
                    OnLinkClick.Invoke(Unescape(linkInfo.GetLinkID()));
                }
            }
        }
Beispiel #13
0
        void LateUpdate()
        {
            if (TMP_TextUtilities.IsIntersectingRectTransform(
                    this.m_TextComponent.rectTransform,
                    Input.mousePosition,
                    this.m_Camera))
            {
                #region Example of Character or Sprite Selection

                var charIndex = TMP_TextUtilities.FindIntersectingCharacter(
                    this.m_TextComponent,
                    Input.mousePosition,
                    this.m_Camera,
                    true);
                if (charIndex != -1 && charIndex != this.m_lastCharIndex)
                {
                    this.m_lastCharIndex = charIndex;

                    var elementType = this.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)
                    {
                        this.SendOnCharacterSelection(
                            this.m_TextComponent.textInfo.characterInfo[charIndex].character,
                            charIndex);
                    }
                    else if (elementType == TMP_TextElementType.Sprite)
                    {
                        this.SendOnSpriteSelection(
                            this.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(
                    this.m_TextComponent,
                    Input.mousePosition,
                    this.m_Camera);
                if (wordIndex != -1 && wordIndex != this.m_lastWordIndex)
                {
                    this.m_lastWordIndex = wordIndex;

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

                    // Send the event to any listeners.
                    this.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(
                    this.m_TextComponent,
                    Input.mousePosition,
                    this.m_Camera);
                if (lineIndex != -1 && lineIndex != this.m_lastLineIndex)
                {
                    this.m_lastLineIndex = lineIndex;

                    // Get the information about the selected word.
                    var lineInfo = this.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 < this.m_TextComponent.textInfo.characterInfo.Length;
                         i++)
                    {
                        buffer[i] = this.m_TextComponent.textInfo.characterInfo[i + lineInfo.firstCharacterIndex]
                                    .character;
                    }

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

                #endregion

                #region Example of Link Handling

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

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

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

                    // Send the event to any listeners.
                    this.SendOnLinkSelection(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
                }

                #endregion
            }
        }
Beispiel #14
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
            }
        }
Beispiel #15
0
 void LateUpdate()
 {
     // is the cursor in the correct region (above the text area) and furthermore, in the link region?
     var isHoveringOver = TMP_TextUtilities.IsIntersectingRectTransform(text.rectTransform, Input.mousePosition, cam);
 }
Beispiel #16
0
        void LateUpdate()
        {
            if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
            {
                #region Example of Character Selection

                int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, 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, 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.
                int 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.
                    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

                // Check if mouse intersects with any links.
                int 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
            }
        }
    /// <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);
                }
            }
        }
    }
Beispiel #18
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
        }
    }
Beispiel #19
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
            }
        }
 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;
         }
     }
 }