Exemplo n.º 1
0
    private void LateUpdate()
    {
        // is the cursor in the correct region (above the text area) and furthermore, in the link region?
        var isHoveringOver = TMP_TextUtilities.IsIntersectingRectTransform(pTextMeshPro.rectTransform, Input.mousePosition, pCamera);
        int linkIndex      = isHoveringOver ? TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, pCamera) : -1;

        if (isHoveringOver && linkIndex == -1)
        {
            CursorController.Instance.Default();
        }
        else if (isHoveringOver)
        {
            CursorController.Instance.Link();
        }

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

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

        // Debug.Log(string.Format("isHovering: {0}, link: {1}", isHoveringOver, linkIndex));
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        var linkID = TMP_TextUtilities.FindIntersectingLink(m_Text, Core.Instance.MouseWorldPosition.ScreenPosition, m_Camera);

        if (linkID != -1)
        {
            var linkInfo = m_Text.textInfo.linkInfo[linkID];
            m_UITMPLinkTooltip.Show(linkInfo.GetLinkID());

            if (m_OnUpdate == null)
            {
                m_OnUpdate           = gameObject.AddComponent <OnUpdateCallback>();
                m_OnUpdate.hideFlags = HideFlags.HideInInspector;
                m_OnUpdate.m_Action  = () =>
                {
                    var currentLinkID = TMP_TextUtilities.FindIntersectingLink(m_Text, Core.Instance.MouseWorldPosition.ScreenPosition, m_Camera);
                    if (currentLinkID != linkID)
                    {
                        implHide();
                    }
                };
            }
        }
    }
    private bool TryGetTooltip(out string content, out string header)
    {
        int linkIndex = TMP_TextUtilities.FindIntersectingLink(_linkedTextField,
                                                               KaynirTools.GetPointerRawPosition(),
                                                               null);

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

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

            return(true);
        }
        else
        {
            content = null;
            header  = null;
            return(false);
        }
    }
Exemplo n.º 4
0
    public void OnPointerClick(PointerEventData eventData)
    {
        // Debug.Log("Click at POS: " + eventData.position + "  World POS: " + eventData.worldPosition);

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

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


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

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

                default:
                    Debug.Log(string.Format("don't recognize the link id: {0}, text: {1}", linkInfo.GetLinkID(), linkInfo.GetLinkText()));
                    return;
                }
            }
        }
    }
Exemplo n.º 5
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.º 6
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.º 7
0
 public int GetLinkIndex() => TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
Exemplo n.º 8
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.º 9
0
        /*
         * void OnEnable()
         * {
         *  // Subscribe to event fired when text object has been regenerated.
         *  TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
         * }
         *
         * void OnDisable()
         * {
         *  // UnSubscribe to event fired when text object has been regenerated.
         *  TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
         * }
         *
         * void ON_TEXT_CHANGED(Object obj)
         * {
         *  if (obj == m_TextMeshPro)
         *  {
         *      // Update cached vertex data.
         *      m_cachedMeshInfoVertexData = m_TextMeshPro.textInfo.CopyMeshInfoVertexData();
         *  }
         * }
         */

        void LateUpdate()
        {
            if (isHoveringObject)
            {
                // Check if Mouse Intersects any of the characters. If so, assign a random color.
                #region Handle Character Selection
                // I don't need this

                /*
                 * 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
                //Don't need this either

                /*
                 * //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 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 = Vector3.zero;
                    RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out worldPointInRectangle);


                    /*string linkName = linkInfo.GetLinkID();
                     * if (linkName.Equals("id_source")) // hyperlink
                     * {
                     *  m_TextPopup_RectTransform.position = worldPointInRectangle;
                     *  m_TextPopup_TMPComponent.text = "Click to follow link";
                     * }
                     * else
                     * {
                     *  m_TextPopup_RectTransform.localPosition = Vector3.zero;
                     *  if (linkName.Equals("id_end"))
                     *      m_TextPopup_TMPComponent.text = "The latest date you want to filter";
                     *  m_TextPopup_RectTransform.gameObject.SetActive(true);
                     *  else if (linkName.Equals("id_start"))// id_start
                     *      m_TextPopup_TMPComponent.text = "The earliest date you want to filter";
                     * }
                     * Invoke("DisableLink", 1);*/
                }
                #endregion
            }

            /* else
             * {
             *  // Restore any character that may have been modified
             *  if (m_lastIndex != -1)
             *  {
             *      RestoreCachedVertexAttributes(m_lastIndex);
             *      m_lastIndex = -1;
             *  }
             * }
             */
        }
Exemplo n.º 10
0
    private void Update()
    {
        //Check if the left mouse button was used to click
        if (Input.GetMouseButtonUp(0) && _isActive)
        {
            //Finds the correct link based on the mouse position and the text field
            TextMeshProUGUI textMesh  = hpv.pages.Peek().GetComponentInChildren <TextMeshProUGUI>();
            int             linkIndex = TMP_TextUtilities.FindIntersectingLink(textMesh, Input.mousePosition, _mainCamera);
            if (linkIndex != -1)
            {
                int linkId = int.Parse(textMesh.textInfo.linkInfo[linkIndex].GetLinkID());
                HelpStickyObject currentObj = objectListByID[linkId];
                // reference it against the sticky list to see if it should get stickied or it should get un-stickied
                if (currentObj.isStickied)
                {
                    // un-sticky it
                    currentObj.stickyNote.SetActive(false);
                    currentObj.isStickied = false;
                }
                else
                {
                    soundUnderline.SoundPencilUnderline();
                    // sticky it
                    if (currentObj.stickyNote != null)
                    {
                        currentObj.stickyNote.SetActive(true);
                        currentObj.isStickied = true;
                    }
                    else
                    { // create a new sticky
                        if (_currentSticky == 10)
                        {
                            _currentSticky = 0;
                        }

                        foreach (var obje in objectListByID)
                        {
                            if (obje.stickyID == _currentSticky)
                            {
                                Destroy(obje.stickyNote);
                                obje.stickyID = -1;
                            }
                        }
                        currentObj.stickyNote = Instantiate(_stickyPrefab, stickyPositions[_currentSticky]);
                        currentObj.stickyNote.GetComponentInChildren <TextMeshProUGUI>().text = currentObj.stickyText;
                        currentObj.stickyID = _currentSticky;
                        _currentSticky++;
                        currentObj.isStickied = true;
                        if (TutorialManager.Instance._doTutorial && TutorialManager.Instance.currentState ==
                            TutorialManager.TutorialState.HelpfolderThree)
                        {
                            TutorialManager.Instance.AdvanceTutorial();
                        }
                    }
                }

                if (currentObj.isStickied)
                {
                    _underLiner.CreateLines(CreateUnderlineCoords(linkId), hpv.CurrentPageNumber(), linkId);
                }
                else
                {
                    _underLiner.DestroyLine(linkId);
                }
            }
        }
    }
Exemplo n.º 11
0
 private int GetLinkIndex()
 {
     return(TMP_TextUtilities.FindIntersectingLink(textMeshPro, Input.mousePosition, mainCamera));
 }
Exemplo n.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
0
        public void OnPointerClick(PointerEventData eventData)
        {
            //Debug.Log("Click at POS: " + eventData.position + "  World POS: " + eventData.worldPosition);

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

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

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

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


            #region Link Selection Handling

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

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

                default:     // underlying geology
                    treeReader.ReadStone(linkInfo.GetLinkID());
                    break;
                }
            }
            #endregion
        }
Exemplo n.º 18
0
        public string GetHoveredLinkID()
        {
            int linkIndex = TMP_TextUtilities.FindIntersectingLink(ContentTextDisplay, Input.mousePosition, CameraCache.Main);

            return(linkIndex < 0 ? null : ContentTextDisplay.textInfo.linkInfo[linkIndex].GetLinkID());
        }
Exemplo n.º 19
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.º 20
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.º 21
0
    public void OnPointerClick(PointerEventData eventData)
    {
        //Check if the left mouse button was used to click
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            //Finds the correct link based on the mouse position and the text field
            var linkId = TMP_TextUtilities.FindIntersectingLink(textField, Input.mousePosition, null);

            //linkInfo is an array that contains the id's and the words that match.
            _splitInfo = textField.textInfo.linkInfo;

            var info = _splitInfo[linkId];


            var wasUnselected = false;

            /*It splits the text in the textField for every '>' there is. It does this so that it can edit the text to
             * include color so that the user knows tat it has been clicked */
            _splitArray = textField.text.Split('>');
            var newText = "";

            for (int i = 0; i < _splitArray.Length; i++)
            {
                if (i != _splitArray.Length - 1)
                {
                    if (CheckCurrent(info, _splitArray[i]))
                    {
                        //If the word was unselected it wouldn't be capable of going in.
                        if (!wasUnselected)
                        {
                            //Adds the <color=red> </color> around the pressed word
                            newText += _colorRed + ">" + _splitArray[i] + ">" + _splitArray[i + 1] + ">" + "</color>";

                            //this makes it skip the next String, since it already been added above here
                            i += 1;
                            _selected.Add(info.GetLinkID());
                        }
                        else
                        {
                            newText += _splitArray[i] + ">";
                        }

                        wasUnselected = false;
                    }
                    //if the current String in the array is <color=red it will go into this else if.
                    else if (_splitArray[i].Equals(_colorRed))
                    {
                        //If the next String in the array isn't the one that needs to be found then it can enter the if.
                        if (!CheckCurrent(info, _splitArray[i + 1]))
                        {
                            newText += _splitArray[i] + ">";
                        }
                        else
                        {
                            //This else is here to remove the color from unselected words.
                            _splitArray[i + 3] = "";
                            _splitArray[i]     = "";
                            _selected.Remove(info.GetLinkID());
                            //this is here to make sure it doesn't set the color there again
                            wasUnselected = true;
                        }
                    }
                    else
                    {
                        //if the current String in the array isn't empty it will add it to the text and add a '>' to it.
                        if (!_splitArray[i].Equals(""))
                        {
                            newText += _splitArray[i] + ">";
                        }
                    }
                }
            }

            textField.text = newText;
        }
    }
Exemplo n.º 22
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
            }
        }