Exemplo n.º 1
0
        private void WatchCharacterEvents()
        {
            int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, UnityEngine.Input.mousePosition, m_Camera, true);

            if (charIndex != -1 && charIndex != m_lastCharIndex)
            {
                if (m_lastCharIndex != -1)
                {
                    SendCharacterLeaveEvent();
                }

                m_lastCharIndex = charIndex;

                if (IsCharACharacter(charIndex))
                {
                    SendOnCharacterEnter(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                }
                else if (IsCharASprite(charIndex))
                {
                    SendOnSpriteEnter(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
                }
            }
            else if (m_lastCharIndex != -1 && charIndex == -1)
            {
                SendCharacterLeaveEvent();
                m_lastCharIndex = -1;
            }
        }
Exemplo n.º 2
0
    public void OnPointerClick(PointerEventData click)
    {
        // Get index of character.
        int charIndex = TMP_TextUtilities.FindIntersectingCharacter(inputfield, click.position, Camera.current, true);

        if (charIndex != -1 && charIndex != lastIndex)
        {
            lastIndex = charIndex;
            // Replace text with color value for character.
            inputText = inputText.Replace(inputText[charIndex].ToString(), "<color=yellow>" + inputText[charIndex].ToString() + "</color>");
            inputfield.GetComponent <TMP_Text>().text = inputText;
        }
    }
Exemplo n.º 3
0
    public void EndDrag()
    {
        if (Input.GetMouseButtonUp(0))
        {
            int index        = TMP_TextUtilities.FindIntersectingCharacter(text, Input.mousePosition, Camera.main, true);
            int indexPalavra = TMP_TextUtilities.FindIntersectingWord(text, Input.mousePosition, Camera.main);

            if (index >= 0)
            {
                bool flag = false;
                if (StringAux.CreckSprite(text.text, index) == 1)
                {
                    flag = true;
                    for (int i = 0; i < 4; i++)
                    {
                        indexBlocosQuestaoUsados[i] = info.indexOpcaoArrastada;
                    }
                }
                else if (StringAux.CreckPalavra(text.text, indexPalavra))
                {
                    flag = true;
                    for (int i = 0; i < 4; i++)
                    {
                        indexBlocosQuestaoUsados[i] = info.indexOpcaoArrastada;
                    }
                }
                if (flag)
                {
                    bool resp = false;

                    if (((StartupDay_QuestaoLacuna)info.atividade.questoes[info.indexQuestao]).blocoLugar[indexBlocosQuestaoUsados[0]] == 1)
                    {
                        resp = true;
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        indexBlocosQuestaoUsados[i] = -1;
                    }
                    gerente.Resposta(resp);
                }
            }
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        Vector3 touchPosition = Input.GetTouch(0).position;
        int     lastIndex     = inputfield.text.Length - 1;
        int     charIndex     = TMP_TextUtilities.FindIntersectingCharacter(inputfield, touchPosition, Camera.main, true);
        //int meshIndex = inputfield.textInfo.characterInfo[charIndex].materialReferenceIndex;
        int vertexIndex = inputfield.textInfo.characterInfo[charIndex].vertexIndex;

        if (charIndex != -1 && charIndex != lastIndex)
        {
            lastIndex = charIndex;
            Color32 color = new Color32((byte)50, (byte)69, (byte)217, 255);


            //vertexColors[vertexIndex + 0] = color;
            //vertexColors[vertexIndex + 1] = color;
            //vertexColors[vertexIndex + 2] = color;
            //vertexColors[vertexIndex + 3] = color;

            //Color32[] vertexColors = inputfield.textInfo.meshInfo.;
        }
    }
Exemplo n.º 5
0
    public void OnPointerClick(PointerEventData eventData)
    {
        int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);

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

            if (charIndex != -1)
            {
                TMP_CharacterInfo cInfo = m_TextMeshPro.textInfo.characterInfo[charIndex];
                ChangeLetterColor(m_TextMeshPro, cInfo, GetRadomColor());
                m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
            }
        }
    }
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);

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


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

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

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

                    // Need to update the appropriate
                    m_TextMeshPro.UpdateVertexData();
                }
                #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();

                    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();
                }
                #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
    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
        }
    }
Exemplo n.º 8
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
            }
        }
Exemplo n.º 9
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
            }
        }
Exemplo n.º 10
0
 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.º 11
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);
                }
            }
        }
    }
Exemplo n.º 12
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.uiVertices;
                    Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo.colors32;

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

                    if (m_TextMeshPro.textInfo.characterInfo[charIndex].type == TMP_CharacterType.Character)
                    {
                        Mesh mesh = m_TextMeshPro.textInfo.meshInfo.mesh;
                        mesh.colors32 = vertexColors;

                        m_TextMeshPro.canvasRenderer.SetMesh(mesh);
                    }
                    else if (m_TextMeshPro.textInfo.characterInfo[charIndex].type == TMP_CharacterType.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.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.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.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.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(TMP_TextUtilities.GetSimpleHashCode("id_02")); // Example of how to retrieve Hash Code for a given string.

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

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

                    case 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.º 13
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
            }
        }
Exemplo n.º 14
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.º 15
0
        private void LateUpdate()
        {
            m_isHoveringObject = false;

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

            if (m_isHoveringObject)
            {
                #region Example of Character Selection

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

                    m_lastCharIndex = charIndex;

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

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

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

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

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

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

                #endregion Example of Character Selection

                #region Example of Link Handling

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

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

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

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

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

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

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

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

                #endregion Example of Link Handling

                #region Example of Word Selection

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

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

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

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

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

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

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

                    m_TextMeshPro.mesh.colors32 = vertexColors;
                }

                #endregion Example of Word Selection
            }
        }
Exemplo n.º 16
0
 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.º 17
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Z) && Input.GetKey(KeyCode.LeftControl))
        {
            Camera.main.backgroundColor = new Color32(49, 77, 121, 255);
            var thisPipe = StartPipe;
            while (thisPipe)
            {
                thisPipe.Color = new Color32(128, 128, 128, 255);
                thisPipe       = thisPipe.NextPipe;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            var index = (TMP_TextUtilities.FindIntersectingCharacter(RecipeText, Input.mousePosition, null, true));
            if (index > -1)
            {
                var row             = index / 6;
                var characterOffset = row * 5 + Mathf.Clamp(index % 6, 0, 5);

                SelectedPipe = StartPipe;
                while (characterOffset > 0 && SelectedPipe.NextPipe)
                {
                    SelectedPipe = SelectedPipe.NextPipe;
                    characterOffset--;
                }
            }
        }

        var blinktime = Time.time % 1;

        if (blinktime >= 0.5f && IsDirty)
        {
            SaveImage.color = SelectedRotationColor;
        }
        else
        {
            SaveImage.color = Color.white;
        }


        //Statistics refresh. Could be separated out into own method
        int shortCount       = 0;
        int longCount        = 0;
        int bendCount        = 0;
        int cornerCount      = 0;
        int allCount         = 0;
        int cornerShortCount = 0;
        int offset           = 0;

        RecipeText.text = "";
        var pipe = StartPipe;

        while (pipe)
        {
            if (pipe == SelectedPipe)
            {
                RecipeText.text += "<color=#ffdf7d>";
            }

            RecipeText.text += pipe.PipeType.ToString()[0];
            if (allCount % 5 == 4)
            {
                RecipeText.text += " ";
            }

            switch (pipe.PipeType)
            {
            case Pipe.PipeTypes.Bend:
                bendCount++;
                break;

            case Pipe.PipeTypes.Corner:
                cornerCount++;
                break;

            case Pipe.PipeTypes.Short:
                shortCount++;
                break;

            case Pipe.PipeTypes.Long:
                longCount++;
                break;

            case Pipe.PipeTypes.Torus:
                cornerShortCount++;
                break;
            }

            allCount++;
            if (pipe == SelectedPipe)
            {
                offset           = allCount;
                RecipeText.text += "</color>";
            }

            pipe = pipe.NextPipe;
        }

        //Fill in the rest with blanks
        var recipeCount = allCount;

        while (recipeCount < 30)
        {
            RecipeText.text += "_";
            if (recipeCount % 5 == 4)
            {
                RecipeText.text += " ";
            }
            recipeCount++;
        }


        Statistics_Short.text       = string.Format("{0:d2}", shortCount);
        Statistics_Long.text        = string.Format("{0:d2}", longCount);
        Statistics_Bend.text        = string.Format("{0:d2}", bendCount);
        Statistics_Corner.text      = string.Format("{0:d2}", cornerCount);
        Statistics_CornerShort.text = string.Format("{0:d2}", cornerShortCount);
        Statistics_All.text         = string.Format("{0:d2}/{1:d2}", offset, allCount);
    }