private void WatchLineEvents()
        {
            int lineIndex = TMP_TextUtilities.FindIntersectingLine(m_TextComponent, UnityEngine.Input.mousePosition, m_Camera);

            if (lineIndex != -1 && lineIndex != m_lastLineIndex)
            {
                if (m_lastLineIndex != -1)
                {
                    TMP_LineInfo lastLineInfo = m_TextComponent.textInfo.lineInfo[m_lastLineIndex];
                    SendOnLineLeave(GetLineText(lastLineInfo), lastLineInfo.firstCharacterIndex, lastLineInfo.characterCount);
                }
                m_lastLineIndex = lineIndex;

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

                SendOnLineEnter(GetLineText(lineInfo), lineInfo.firstCharacterIndex, lineInfo.characterCount);
            }
            else if (m_lastLineIndex != -1 && lineIndex == -1)
            {
                TMP_LineInfo lastLineInfo = m_TextComponent.textInfo.lineInfo[m_lastLineIndex];
                SendOnLineLeave(GetLineText(lastLineInfo), lastLineInfo.firstCharacterIndex, lastLineInfo.characterCount);
                m_lastLineIndex = -1;
            }
        }
    /// <summary>
    /// Word Touch Event
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerClick(PointerEventData eventData)
    {
        if (!StoryManager.instance.locked)
        {
            int index = TMP_TextUtilities.FindIntersectingWord(TMP, eventData.position, eventData.enterEventCamera); // gets the words index in the sentence.
            if (index != -1)
            {
                StoryManager.instance.locked = true;
                int          line     = TMP_TextUtilities.FindIntersectingLine(TMP, eventData.position, eventData.enterEventCamera); // gets what line the word is on
                TMP_WordInfo wordInfo = TMP.textInfo.wordInfo[index];                                                                // gets the wordInfo of the given index

                StoryManager.instance.ShowThaiPopUp(wordInfo.GetWord(), line == 0, eventData);
                Debug.Log("Word [" + wordInfo.GetWord() + "]");

                // Change word color
                string text;
                string tmp = TMP.text;
                text = TMP.text.Substring(0, wordInfo.firstCharacterIndex) + "<color=\"yellow\">" + wordInfo.GetWord() + "</color>" + TMP.text.Substring(wordInfo.lastCharacterIndex + 1);

                TMP.text = text;

                // reset word color
                StartCoroutine(rollbackHighlighting(tmp, wordInfo.GetWord()));
            }
        }
    }
        public void OnPointerClick(PointerEventData eventData)
        {
            var line = TMP_TextUtilities.FindIntersectingLine(_textComponent, eventData.position, null);

            if (line < 0)
            {
                return;
            }
            int characterClosest = TMP_TextUtilities.FindNearestCharacterOnLine(_textComponent, eventData.position, line, null, true);

            string strippedText = ChirpConsoleUtils.StripTags(_textComponent.text);
            int    logLine      = ChirpConsoleUtils.CountLineBreaks(strippedText, 0, characterClosest);

            var log = _chirpQuantumConsole.FindLog(logLine);

            if (log == null)
            {
                return;
            }
            _chirpQuantumConsole.ShowLogDetails(log);
        }
Beispiel #4
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 #5
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
            }
        }
    /// <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 #7
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
            }
        }
Beispiel #8
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
            }
        }