Exemplo n.º 1
0
        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

                #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.

                    Vector3 worldPointInRectangle;

                    RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out 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


                #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
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to draw rectangles around each word of the text.
        /// </summary>
        /// <param name="text"></param>
        void DrawWordBounds()
        {
            TMP_TextInfo textInfo = m_TextComponent.textInfo;

            for (int i = 0; i < textInfo.wordCount; i++)
            {
                TMP_WordInfo wInfo = textInfo.wordInfo[i];

                bool isBeginRegion = false;

                Vector3 bottomLeft  = Vector3.zero;
                Vector3 topLeft     = Vector3.zero;
                Vector3 bottomRight = Vector3.zero;
                Vector3 topRight    = Vector3.zero;

                float maxAscender  = -Mathf.Infinity;
                float minDescender = Mathf.Infinity;

                Color wordColor = Color.green;

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

                    bool isCharacterVisible = characterIndex > m_TextComponent.maxVisibleCharacters ||
                                              currentCharInfo.lineNumber > m_TextComponent.maxVisibleLines ||
                                              (m_TextComponent.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;

                    // Track Max Ascender and Min Descender
                    maxAscender  = Mathf.Max(maxAscender, currentCharInfo.ascender);
                    minDescender = Mathf.Min(minDescender, currentCharInfo.descender);

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

                        bottomLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0);
                        topLeft    = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0);

                        //Debug.Log("Start Word Region at [" + currentCharInfo.character + "]");

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

                            topLeft     = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
                            bottomLeft  = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
                            bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
                            topRight    = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));

                            // Draw Region
                            DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);

                            //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
                        }
                    }

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

                        topLeft     = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
                        bottomLeft  = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
                        bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
                        topRight    = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));

                        // Draw Region
                        DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);

                        //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
                    }
                    // If Word is split on more than one line.
                    else if (isBeginRegion && currentLine != textInfo.characterInfo[characterIndex + 1].lineNumber)
                    {
                        isBeginRegion = false;

                        topLeft     = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
                        bottomLeft  = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
                        bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
                        topRight    = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));

                        // Draw Region
                        DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);
                        //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
                        maxAscender  = -Mathf.Infinity;
                        minDescender = Mathf.Infinity;
                    }
                }

                //Debug.Log(wInfo.GetWord(m_TextMeshPro.textInfo.characterInfo));
            }
        }
Exemplo n.º 3
0
        void LateUpdate()
        {
            if (isHoveringObject)
            {
                // Check if Mouse Intersects any of the characters. If so, assign a random color.
                #region Handle Character Selection
                int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, true);

                // Undo Swap and Vertex Attribute changes.
                if (charIndex == -1 || charIndex != m_lastIndex)
                {
                    RestoreCachedVertexAttributes(m_lastIndex);
                    m_lastIndex = -1;
                }

                if (charIndex != -1 && charIndex != m_lastIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
                {
                    m_lastIndex = charIndex;

                    // Get the index of the material / sub text object used by this character.
                    int materialIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].materialReferenceIndex;

                    // Get the index of the first vertex of the selected character.
                    int vertexIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].vertexIndex;

                    // Get a reference to the vertices array.
                    Vector3[] vertices = m_TextMeshPro.textInfo.meshInfo[materialIndex].vertices;

                    // Determine the center point of the character.
                    Vector2 charMidBasline = (vertices[vertexIndex + 0] + vertices[vertexIndex + 2]) / 2;

                    // Need to translate all 4 vertices of the character to aligned with middle of character / baseline.
                    // This is needed so the matrix TRS is applied at the origin for each character.
                    Vector3 offset = charMidBasline;

                    // Translate the character to the middle baseline.
                    vertices[vertexIndex + 0] = vertices[vertexIndex + 0] - offset;
                    vertices[vertexIndex + 1] = vertices[vertexIndex + 1] - offset;
                    vertices[vertexIndex + 2] = vertices[vertexIndex + 2] - offset;
                    vertices[vertexIndex + 3] = vertices[vertexIndex + 3] - offset;

                    float zoomFactor = 1.5f;

                    // Setup the Matrix for the scale change.
                    m_matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * zoomFactor);

                    // Apply Matrix operation on the given character.
                    vertices[vertexIndex + 0] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
                    vertices[vertexIndex + 1] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
                    vertices[vertexIndex + 2] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
                    vertices[vertexIndex + 3] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);

                    // Translate the character back to its original position.
                    vertices[vertexIndex + 0] = vertices[vertexIndex + 0] + offset;
                    vertices[vertexIndex + 1] = vertices[vertexIndex + 1] + offset;
                    vertices[vertexIndex + 2] = vertices[vertexIndex + 2] + offset;
                    vertices[vertexIndex + 3] = vertices[vertexIndex + 3] + offset;

                    // Change Vertex Colors of the highlighted character
                    Color32 c = new Color32(255, 255, 192, 255);

                    // Get a reference to the vertex color
                    Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[materialIndex].colors32;

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


                    // Get a reference to the meshInfo of the selected character.
                    TMP_MeshInfo meshInfo = m_TextMeshPro.textInfo.meshInfo[materialIndex];

                    // Get the index of the last character's vertex attributes.
                    int lastVertexIndex = vertices.Length - 4;

                    // Swap the current character's vertex attributes with those of the last element in the vertex attribute arrays.
                    // We do this to make sure this character is rendered last and over other characters.
                    meshInfo.SwapVertexData(vertexIndex, lastVertexIndex);

                    // Need to update the appropriate
                    m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
                }
                #endregion


                #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];

                    // Iterate through each of the characters of the word.
                    for (int i = 0; i < wInfo.characterCount; i++)
                    {
                        int characterIndex = wInfo.firstCharacterIndex + i;

                        // Get the index of the material / sub text object used by this character.
                        int meshIndex = m_TextMeshPro.textInfo.characterInfo[characterIndex].materialReferenceIndex;

                        // Get the index of the first vertex of this character.
                        int vertexIndex = m_TextMeshPro.textInfo.characterInfo[characterIndex].vertexIndex;

                        // Get a reference to the vertex color
                        Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;

                        Color32 c = vertexColors[vertexIndex + 0].Tint(1.33333f);

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

                    // Update Geometry
                    m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);

                    m_selectedWord = -1;
                }


                // Word Selection Handling
                if (wordIndex != -1 && wordIndex != m_selectedWord && !(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
                {
                    m_selectedWord = wordIndex;

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

                    // Iterate through each of the characters of the word.
                    for (int i = 0; i < wInfo.characterCount; i++)
                    {
                        int characterIndex = wInfo.firstCharacterIndex + i;

                        // Get the index of the material / sub text object used by this character.
                        int meshIndex = m_TextMeshPro.textInfo.characterInfo[characterIndex].materialReferenceIndex;

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

                        // Get a reference to the vertex color
                        Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;

                        Color32 c = vertexColors[vertexIndex + 0].Tint(0.75f);

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

                    // Update Geometry
                    m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
                }
                #endregion


                #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];

                    // Debug.Log("Link ID: \"" + linkInfo.GetLinkID() + "\"   Link Text: \"" + linkInfo.GetLinkText() + "\""); // Example of how to retrieve the Link ID and Link Text.

                    Vector3 worldPointInRectangle;

                    RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out 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
            }
            else
            {
                // Restore any character that may have been modified
                if (m_lastIndex != -1)
                {
                    RestoreCachedVertexAttributes(m_lastIndex);
                    m_lastIndex = -1;
                }
            }
        }
Exemplo n.º 4
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);
                }
            }
        }
    }
 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;
         }
     }
 }
Exemplo n.º 6
0
        void LateUpdate()
        {
            if (isHoveringObject)
            {
                // Check if Mouse Intersects any of the characters. If so, assign a random color.
                #region Handle Character Selection
                int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, true);

                if (charIndex != -1 && charIndex != m_lastIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
                {
                    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[0].uiVertices;
                    Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[0].colors32;

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

                    if (m_TextMeshPro.textInfo.characterInfo[charIndex].elementType == TMP_TextElementType.Character)
                    {
                        Mesh mesh = m_TextMeshPro.textInfo.meshInfo[0].mesh;
                        mesh.colors32 = vertexColors;

                        m_TextMeshPro.canvasRenderer.SetMesh(mesh);
                    }
                    else if (m_TextMeshPro.textInfo.characterInfo[charIndex].elementType == TMP_TextElementType.Sprite)
                    {
                        // TODO Fix for Sprites
                        //m_TextMeshPro.inlineGraphicManager.inlineGraphic.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
                    }
                }
                #endregion


                #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 vertex color
                    Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[0].colors32;

                    // 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 = vertexColors[vertexIndex + 0].Tint(1.33333f);

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

                    Mesh mesh = m_TextMeshPro.textInfo.meshInfo[0].mesh;
                    mesh.colors32 = vertexColors;

                    m_TextMeshPro.canvasRenderer.SetMesh(mesh);

                    m_selectedWord = -1;
                }


                // Word Selection Handling
                if (wordIndex != -1 && wordIndex != m_selectedWord && !(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
                {
                    m_selectedWord = wordIndex;

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

                    // Get a reference to the vertex color
                    Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[0].colors32;

                    // 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 = vertexColors[vertexIndex + 0].Tint(0.75f);

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

                    Mesh mesh = m_TextMeshPro.textInfo.meshInfo[0].mesh;
                    mesh.colors32 = vertexColors;

                    m_TextMeshPro.canvasRenderer.SetMesh(mesh);
                }
                #endregion


                #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];
                    //int linkHashCode = linkInfo.hashCode;

                    //Debug.Log("Link ID: \"" + linkInfo.GetLinkID() + "\"   Link Text: \"" + linkInfo.GetLinkText() + "\""); // Example of how to retrieve the Link ID and Link Text.

                    Vector3 worldPointInRectangle = Vector3.zero;
                    RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out 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
            }
        }
Exemplo n.º 7
0
    public IEnumerator ApplyEffects(string sentence, List <List <int> > colorIndices, int[] waveIndices, int[] jitterIndices)
    {
        int loopCount         = 0;
        int lastLoopCount     = 0;
        int currentCharTyping = 0;

        float lastTime = Time.time;

        List <TMP_WordInfo> jitterInfo;

        jitterInfo = new List <TMP_WordInfo>();

        if (jitterIndices.Length > 0)
        {
            vertexAnim = null;
            vertexAnim = new VertexAnim[1024];

            for (int i = 0; i < 1024; i++)
            {
                vertexAnim[i].angleRange = Random.Range(10f, 25f);
                vertexAnim[i].speed      = Random.Range(1f, 3f);
            }
        }

        List <TMP_WordInfo> waveInfo;

        waveInfo = new List <TMP_WordInfo>();

        if (type)
        {
            dM.dialogueText.text = "";

            yield return(new WaitUntil(() => dM.dB.isOpen));

            dM.isTyping = true;
            dM.tdCheck  = false;

            dM.dialogueText.text = sentence;
            dM.dialogueText.maxVisibleCharacters = sentence.ToCharArray().Length;

            dM.dialogueText.ForceMeshUpdate(true);

            ColorAllCharacters(0);
        }
        else
        {
            dM.dialogueText.text = sentence;
        }

        while (true)
        {
            if (type && currentCharTyping < sentence.ToCharArray().Length)
            {
                int waitCycles = 2;

                if (currentCharTyping > 0)
                {
                    char lastCharTyped = sentence.ToCharArray()[currentCharTyping - 1];
                    char thisChar      = sentence.ToCharArray()[currentCharTyping];

                    if (lastCharTyped != '.' || lastCharTyped != ',' || lastCharTyped != '?' || lastCharTyped != '!')
                    {
                        waitCycles = 2;

                        if (sentence.ToCharArray()[currentCharTyping] == ' ')
                        {
                            currentCharTyping++;
                        }
                    }

                    else
                    {
                        waitCycles = 5;
                    }
                }

                if (lastLoopCount + waitCycles <= loopCount)
                {
                    TMP_TextInfo typeInfo = dM.dialogueText.textInfo;

                    Color32 typeColor = typeInfo.textComponent.color;

                    typeColor.a = 255;

                    for (int x = 0; x < colorIndices.Count; x++)
                    {
                        TMP_TextInfo colorDialogueInfo = dM.dialogueText.textInfo;

                        if (colorIndices[x].Count != 0)
                        {
                            for (int y = 0; y < colorIndices[x].Count; y++)
                            {
                                TMP_WordInfo ColorWordInfo = colorDialogueInfo.wordInfo[colorIndices[x][y]];

                                for (int z = 0; z < ColorWordInfo.characterCount; z++)
                                {
                                    if (currentCharTyping == ColorWordInfo.firstCharacterIndex + z)
                                    {
                                        typeColor = colors[x];
                                    }
                                }
                            }
                        }
                    }

                    int typeMeshIndex   = dM.dialogueText.textInfo.characterInfo[currentCharTyping].materialReferenceIndex;
                    int typeVertexIndex = dM.dialogueText.textInfo.characterInfo[currentCharTyping].vertexIndex;

                    if (dM.dialogueText.text.ToCharArray()[currentCharTyping] == sentence.ToCharArray()[currentCharTyping])
                    {
                        Color32[] typeVertexColors = dM.dialogueText.textInfo.meshInfo[typeMeshIndex].colors32;

                        typeVertexColors[typeVertexIndex + 0] = typeColor;
                        typeVertexColors[typeVertexIndex + 1] = typeColor;
                        typeVertexColors[typeVertexIndex + 2] = typeColor;
                        typeVertexColors[typeVertexIndex + 3] = typeColor;

                        dM.dialogueText.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
                    }
                    else
                    {
                        print("error");
                    }

                    if (currentCharTyping < sentence.ToCharArray().Length)
                    {
                        currentCharTyping++;
                    }

                    lastLoopCount = loopCount;
                }
            }

            if (currentCharTyping >= sentence.ToCharArray().Length)
            {
                dM.isTyping = false;
                dM.tdCheck  = true;

                type = false;

                currentCharTyping = 0;
            }

            if (!type)
            {
                for (int x = 0; x < colorIndices.Count; x++)
                {
                    TMP_TextInfo colorDialogueInfo = dM.dialogueText.textInfo;

                    if (colorIndices[x].Count != 0)
                    {
                        for (int y = 0; y < colorIndices[x].Count; y++)
                        {
                            TMP_WordInfo ColorWordInfo = colorDialogueInfo.wordInfo[colorIndices[x][y]];

                            for (int z = 0; z < ColorWordInfo.characterCount; z++)
                            {
                                int colorTypeMeshIndex   = dM.dialogueText.textInfo.characterInfo[ColorWordInfo.firstCharacterIndex + z].materialReferenceIndex;
                                int colorTypeVertexIndex = dM.dialogueText.textInfo.characterInfo[ColorWordInfo.firstCharacterIndex + z].vertexIndex;

                                Color32[] colorTypeVertexColors = dM.dialogueText.textInfo.meshInfo[colorTypeMeshIndex].colors32;

                                colorTypeVertexColors[colorTypeVertexIndex + 0] = colors[x];
                                colorTypeVertexColors[colorTypeVertexIndex + 1] = colors[x];
                                colorTypeVertexColors[colorTypeVertexIndex + 2] = colors[x];
                                colorTypeVertexColors[colorTypeVertexIndex + 3] = colors[x];

                                dM.dialogueText.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
                            }
                        }
                    }
                }

                if (dM.isTyping && !type)
                {
                    dM.isTyping = false;
                    dM.tdCheck  = true;

                    ColorAllCharacters(255);
                }
            }

            if (jitterIndices.Length > 0 && dM.dialogueText.textInfo.wordCount >= jitterIndices[0])
            {
                jitterInfo.Clear();

                foreach (int jitterIndex in jitterIndices)
                {
                    jitterInfo.Add(dM.dialogueText.textInfo.wordInfo[jitterIndex]);
                }

                Matrix4x4 jitterMatrix;

                hasTextChanged = true;

                List <TMP_MeshInfo[]> cachedJitterMeshInfo;
                cachedJitterMeshInfo = new List <TMP_MeshInfo[]>();

                foreach (TMP_WordInfo wordInfo in jitterInfo)
                {
                    cachedJitterMeshInfo.Add(wordInfo.textComponent.textInfo.CopyMeshInfoVertexData());
                }

                if (hasTextChanged)
                {
                    foreach (TMP_WordInfo wordInfo in jitterInfo)
                    {
                        cachedJitterMeshInfo.Add(wordInfo.textComponent.textInfo.CopyMeshInfoVertexData());
                    }

                    hasTextChanged = false;
                }

                foreach (TMP_WordInfo info in jitterInfo)
                {
                    foreach (TMP_MeshInfo[] cMI in cachedJitterMeshInfo)
                    {
                        int jitterCharacterCount = info.characterCount;

                        if (jitterCharacterCount == 0)
                        {
                            yield return(new WaitForSeconds(0.25f));

                            continue;
                        }

                        for (int i = 0; i < jitterCharacterCount; i++)
                        {
                            int jitterCharIndex = info.firstCharacterIndex + i;

                            TMP_CharacterInfo jitterCharInfo = dM.dialogueText.textInfo.characterInfo[jitterCharIndex];

                            if (!jitterCharInfo.isVisible)
                            {
                                continue;
                            }

                            VertexAnim vertAnim = vertexAnim[jitterCharIndex];

                            int jitterMaterialIndex = dM.dialogueText.textInfo.characterInfo[jitterCharIndex].materialReferenceIndex;

                            int jitterVertexIndex = dM.dialogueText.textInfo.characterInfo[jitterCharIndex].vertexIndex;

                            Vector3[] jitterSourceVertices = cMI[jitterMaterialIndex].vertices;

                            Vector2 jitterCharMidBasline = (jitterSourceVertices[jitterVertexIndex + 0] + jitterSourceVertices[jitterVertexIndex + 2]) / 2;

                            Vector3 jitterOffset = jitterCharMidBasline;

                            Vector3[] jitterDestinationVertices = dM.dialogueText.textInfo.meshInfo[jitterMaterialIndex].vertices;

                            if (loopCount == 0)
                            {
                                SetInitialCoordinates(jitterCharIndex, jitterOffset);
                            }

                            jitterDestinationVertices[jitterVertexIndex + 0] = jitterSourceVertices[jitterVertexIndex + 0] - jitterOffset;
                            jitterDestinationVertices[jitterVertexIndex + 1] = jitterSourceVertices[jitterVertexIndex + 1] - jitterOffset;
                            jitterDestinationVertices[jitterVertexIndex + 2] = jitterSourceVertices[jitterVertexIndex + 2] - jitterOffset;
                            jitterDestinationVertices[jitterVertexIndex + 3] = jitterSourceVertices[jitterVertexIndex + 3] - jitterOffset;

                            vertAnim.angle = Mathf.SmoothStep(-vertAnim.angleRange, vertAnim.angleRange, Mathf.PingPong(loopCount / 25f * vertAnim.speed, 1f));
                            Vector3 jitterEffectOffset = new Vector3(Random.Range(-.5f, .5f), Random.Range(-.5f, .5f), 0);

                            jitterMatrix = Matrix4x4.TRS(jitterEffectOffset * CurveScale, Quaternion.Euler(0, 0, Random.Range(-5f, 5f) * AngleMultiplier), Vector3.one);

                            jitterDestinationVertices[jitterVertexIndex + 0] = jitterMatrix.MultiplyPoint3x4(jitterDestinationVertices[jitterVertexIndex + 0]);
                            jitterDestinationVertices[jitterVertexIndex + 1] = jitterMatrix.MultiplyPoint3x4(jitterDestinationVertices[jitterVertexIndex + 1]);
                            jitterDestinationVertices[jitterVertexIndex + 2] = jitterMatrix.MultiplyPoint3x4(jitterDestinationVertices[jitterVertexIndex + 2]);
                            jitterDestinationVertices[jitterVertexIndex + 3] = jitterMatrix.MultiplyPoint3x4(jitterDestinationVertices[jitterVertexIndex + 3]);

                            jitterDestinationVertices[jitterVertexIndex + 0].y += initialYVal[jitterCharIndex];
                            jitterDestinationVertices[jitterVertexIndex + 1].y += initialYVal[jitterCharIndex];
                            jitterDestinationVertices[jitterVertexIndex + 2].y += initialYVal[jitterCharIndex];
                            jitterDestinationVertices[jitterVertexIndex + 3].y += initialYVal[jitterCharIndex];

                            jitterDestinationVertices[jitterVertexIndex + 0].x += initialXVal[jitterCharIndex];
                            jitterDestinationVertices[jitterVertexIndex + 1].x += initialXVal[jitterCharIndex];
                            jitterDestinationVertices[jitterVertexIndex + 2].x += initialXVal[jitterCharIndex];
                            jitterDestinationVertices[jitterVertexIndex + 3].x += initialXVal[jitterCharIndex];

                            jitterDestinationVertices[jitterVertexIndex + 0] += jitterEffectOffset;
                            jitterDestinationVertices[jitterVertexIndex + 1] += jitterEffectOffset;
                            jitterDestinationVertices[jitterVertexIndex + 2] += jitterEffectOffset;
                            jitterDestinationVertices[jitterVertexIndex + 3] += jitterEffectOffset;

                            vertexAnim[i] = vertAnim;
                        }
                    }
                }
            }

            if (waveIndices.Length > 0 && dM.dialogueText.textInfo.wordCount >= waveIndices[0])
            {
                waveInfo.Clear();

                foreach (int waveIndex in waveIndices)
                {
                    //Add each word's wordInfo
                    waveInfo.Add(dM.dialogueText.textInfo.wordInfo[waveIndex]);
                }

                Matrix4x4 waveMatrix;

                hasTextChanged = true;

                List <TMP_MeshInfo[]> cachedWaveMeshInfo;
                cachedWaveMeshInfo = new List <TMP_MeshInfo[]>();
                cachedWaveMeshInfo.Clear();

                foreach (TMP_WordInfo wordInfo in waveInfo)
                {
                    cachedWaveMeshInfo.Add(wordInfo.textComponent.textInfo.CopyMeshInfoVertexData());
                }

                if (hasTextChanged)
                {
                    foreach (TMP_WordInfo wordInfo in waveInfo)
                    {
                        cachedWaveMeshInfo.Add(wordInfo.textComponent.textInfo.CopyMeshInfoVertexData());
                    }

                    hasTextChanged = false;
                }

                foreach (TMP_WordInfo info in waveInfo)
                {
                    int waveCharacterCount = info.characterCount;

                    foreach (TMP_MeshInfo[] cMI in cachedWaveMeshInfo)
                    {
                        if (waveCharacterCount == 0)
                        {
                            yield return(new WaitForSeconds(0.25f));

                            continue;
                        }

                        for (int i = 0; i < waveCharacterCount; i++)
                        {
                            int waveCharIndex = info.firstCharacterIndex + i;

                            TMP_CharacterInfo waveCharInfo = dM.dialogueText.textInfo.characterInfo[waveCharIndex];

                            if (!waveCharInfo.isVisible)
                            {
                                continue;
                            }

                            int waveMaterialIndex = dM.dialogueText.textInfo.characterInfo[waveCharIndex].materialReferenceIndex;

                            int waveVertexIndex = dM.dialogueText.textInfo.characterInfo[waveCharIndex].vertexIndex;

                            Vector3[] waveSourceVertices = cMI[waveMaterialIndex].vertices;

                            Vector2 waveCharMidBasline = (waveSourceVertices[waveVertexIndex + 0] + waveSourceVertices[waveVertexIndex + 2]) / 2;

                            Vector3 waveOffset = waveCharMidBasline;

                            Vector3[] waveDestinationVertices = dM.dialogueText.textInfo.meshInfo[waveMaterialIndex].vertices;

                            if (loopCount == 0)
                            {
                                SetInitialCoordinates(waveCharIndex, waveOffset);
                            }

                            waveDestinationVertices[waveVertexIndex + 0] = waveSourceVertices[waveVertexIndex + 0] - waveOffset;
                            waveDestinationVertices[waveVertexIndex + 1] = waveSourceVertices[waveVertexIndex + 1] - waveOffset;
                            waveDestinationVertices[waveVertexIndex + 2] = waveSourceVertices[waveVertexIndex + 2] - waveOffset;
                            waveDestinationVertices[waveVertexIndex + 3] = waveSourceVertices[waveVertexIndex + 3] - waveOffset;

                            Vector3 waveEffectOffset = new Vector3(0, Mathf.Cos((waveCharIndex * waveFrequency) - Time.time * 6) * 2, 0);

                            waveMatrix = Matrix4x4.TRS(waveEffectOffset, Quaternion.Euler(0, 0, 0), Vector3.one);

                            waveDestinationVertices[waveVertexIndex + 0] = waveMatrix.MultiplyPoint3x4(waveDestinationVertices[waveVertexIndex + 0]);
                            waveDestinationVertices[waveVertexIndex + 1] = waveMatrix.MultiplyPoint3x4(waveDestinationVertices[waveVertexIndex + 1]);
                            waveDestinationVertices[waveVertexIndex + 2] = waveMatrix.MultiplyPoint3x4(waveDestinationVertices[waveVertexIndex + 2]);
                            waveDestinationVertices[waveVertexIndex + 3] = waveMatrix.MultiplyPoint3x4(waveDestinationVertices[waveVertexIndex + 3]);

                            waveDestinationVertices[waveVertexIndex + 0].y += waveEffectOffset.y;
                            waveDestinationVertices[waveVertexIndex + 1].y += waveEffectOffset.y;
                            waveDestinationVertices[waveVertexIndex + 2].y += waveEffectOffset.y;
                            waveDestinationVertices[waveVertexIndex + 3].y += waveEffectOffset.y;


                            waveDestinationVertices[waveVertexIndex + 0].y += initialYVal[waveCharIndex];
                            waveDestinationVertices[waveVertexIndex + 1].y += initialYVal[waveCharIndex];
                            waveDestinationVertices[waveVertexIndex + 2].y += initialYVal[waveCharIndex];
                            waveDestinationVertices[waveVertexIndex + 3].y += initialYVal[waveCharIndex];

                            waveDestinationVertices[waveVertexIndex + 0].x += waveOffset.x;
                            waveDestinationVertices[waveVertexIndex + 1].x += waveOffset.x;
                            waveDestinationVertices[waveVertexIndex + 2].x += waveOffset.x;
                            waveDestinationVertices[waveVertexIndex + 3].x += waveOffset.x;
                        }
                    }
                }
            }

            for (int i = 0; i < dM.dialogueText.textInfo.meshInfo.Length; i++)
            {
                dM.dialogueText.textInfo.meshInfo[i].mesh.vertices = dM.dialogueText.textInfo.meshInfo[i].vertices;
                dM.dialogueText.UpdateGeometry(dM.dialogueText.textInfo.meshInfo[i].mesh, i);
            }

            loopCount += 1;

            lastTime = Time.time;

            yield return(new WaitForSecondsRealtime(0.01f));
        }
    }
Exemplo n.º 8
0
        void LateUpdate()
        {
            if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
            {
                #region Example of Character or Sprite Selection
                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;

                    // 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.
                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
            }
        }
Exemplo n.º 9
0
 // Token: 0x06004584 RID: 17796 RVA: 0x001753A4 File Offset: 0x001737A4
 private void LateUpdate()
 {
     if (this.isHoveringObject)
     {
         int num = TMP_TextUtilities.FindIntersectingCharacter(this.m_TextMeshPro, Input.mousePosition, this.m_Camera, true);
         if (num == -1 || num != this.m_lastIndex)
         {
             this.RestoreCachedVertexAttributes(this.m_lastIndex);
             this.m_lastIndex = -1;
         }
         if (num != -1 && num != this.m_lastIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
         {
             this.m_lastIndex = num;
             int       materialReferenceIndex = this.m_TextMeshPro.textInfo.characterInfo[num].materialReferenceIndex;
             int       vertexIndex            = this.m_TextMeshPro.textInfo.characterInfo[num].vertexIndex;
             Vector3[] vertices = this.m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex].vertices;
             Vector2   v        = (vertices[vertexIndex] + vertices[vertexIndex + 2]) / 2f;
             Vector3   b        = v;
             vertices[vertexIndex]    -= b;
             vertices[vertexIndex + 1] = vertices[vertexIndex + 1] - b;
             vertices[vertexIndex + 2] = vertices[vertexIndex + 2] - b;
             vertices[vertexIndex + 3] = vertices[vertexIndex + 3] - b;
             float d = 1.5f;
             this.m_matrix             = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * d);
             vertices[vertexIndex]     = this.m_matrix.MultiplyPoint3x4(vertices[vertexIndex]);
             vertices[vertexIndex + 1] = this.m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
             vertices[vertexIndex + 2] = this.m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
             vertices[vertexIndex + 3] = this.m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
             vertices[vertexIndex]    += b;
             vertices[vertexIndex + 1] = vertices[vertexIndex + 1] + b;
             vertices[vertexIndex + 2] = vertices[vertexIndex + 2] + b;
             vertices[vertexIndex + 3] = vertices[vertexIndex + 3] + b;
             Color32   color  = new Color32(byte.MaxValue, byte.MaxValue, 192, 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;
             TMP_MeshInfo tmp_MeshInfo = this.m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex];
             int          dst          = vertices.Length - 4;
             tmp_MeshInfo.SwapVertexData(vertexIndex, dst);
             this.m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
         }
         int num2 = TMP_TextUtilities.FindIntersectingWord(this.m_TextMeshPro, Input.mousePosition, this.m_Camera);
         if (this.m_TextPopup_RectTransform != null && this.m_selectedWord != -1 && (num2 == -1 || num2 != this.m_selectedWord))
         {
             TMP_WordInfo tmp_WordInfo = this.m_TextMeshPro.textInfo.wordInfo[this.m_selectedWord];
             for (int i = 0; i < tmp_WordInfo.characterCount; i++)
             {
                 int       num3 = tmp_WordInfo.firstCharacterIndex + i;
                 int       materialReferenceIndex2 = this.m_TextMeshPro.textInfo.characterInfo[num3].materialReferenceIndex;
                 int       vertexIndex2            = this.m_TextMeshPro.textInfo.characterInfo[num3].vertexIndex;
                 Color32[] colors2 = this.m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex2].colors32;
                 Color32   color2  = colors2[vertexIndex2].Tint(1.33333f);
                 colors2[vertexIndex2]     = color2;
                 colors2[vertexIndex2 + 1] = color2;
                 colors2[vertexIndex2 + 2] = color2;
                 colors2[vertexIndex2 + 3] = color2;
             }
             this.m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
             this.m_selectedWord = -1;
         }
         if (num2 != -1 && num2 != this.m_selectedWord && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
         {
             this.m_selectedWord = num2;
             TMP_WordInfo tmp_WordInfo2 = this.m_TextMeshPro.textInfo.wordInfo[num2];
             for (int j = 0; j < tmp_WordInfo2.characterCount; j++)
             {
                 int       num4 = tmp_WordInfo2.firstCharacterIndex + j;
                 int       materialReferenceIndex3 = this.m_TextMeshPro.textInfo.characterInfo[num4].materialReferenceIndex;
                 int       vertexIndex3            = this.m_TextMeshPro.textInfo.characterInfo[num4].vertexIndex;
                 Color32[] colors3 = this.m_TextMeshPro.textInfo.meshInfo[materialReferenceIndex3].colors32;
                 Color32   color3  = colors3[vertexIndex3].Tint(0.75f);
                 colors3[vertexIndex3]     = color3;
                 colors3[vertexIndex3 + 1] = color3;
                 colors3[vertexIndex3 + 2] = color3;
                 colors3[vertexIndex3 + 3] = color3;
             }
             this.m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
         }
         int num5 = TMP_TextUtilities.FindIntersectingLink(this.m_TextMeshPro, Input.mousePosition, this.m_Camera);
         if ((num5 == -1 && this.m_selectedLink != -1) || num5 != this.m_selectedLink)
         {
             this.m_TextPopup_RectTransform.gameObject.SetActive(false);
             this.m_selectedLink = -1;
         }
         if (num5 != -1 && num5 != this.m_selectedLink)
         {
             this.m_selectedLink = num5;
             TMP_LinkInfo tmp_LinkInfo = this.m_TextMeshPro.textInfo.linkInfo[num5];
             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")
                     {
                         this.m_TextPopup_RectTransform.position = zero;
                         this.m_TextPopup_RectTransform.gameObject.SetActive(true);
                         this.m_TextPopup_TMPComponent.text = "You have selected link <#ffff00> ID 02";
                     }
                 }
                 else
                 {
                     this.m_TextPopup_RectTransform.position = zero;
                     this.m_TextPopup_RectTransform.gameObject.SetActive(true);
                     this.m_TextPopup_TMPComponent.text = "You have selected link <#ffff00> ID 01";
                 }
             }
         }
     }
     else if (this.m_lastIndex != -1)
     {
         this.RestoreCachedVertexAttributes(this.m_lastIndex);
         this.m_lastIndex = -1;
     }
 }
Exemplo n.º 10
0
 private void OnWordLeave(TMP_WordInfo wordInfo, string word, int charIndex, int length)
 {
     //ResetWordColor(wordInfo);
 }
Exemplo n.º 11
0
 private void OnWordEnter(TMP_WordInfo wordInfo, string word, int charIndex, int length)
 {
     //ChangeWordColor(wordInfo, GetRadomColor());
 }
Exemplo n.º 12
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
            }
        }