GetClosestCharacter() static public méthode

Get the index of the closest character within the provided list of values. This function first sorts by Y, and only then by X.
static public GetClosestCharacter ( BetterList verts, Vector2 pos ) : int
verts BetterList
pos Vector2
Résultat int
Exemple #1
0
    /// <summary>
    /// Return the index of the character at the specified local position.
    /// </summary>

    public int GetCharacterIndex(Vector2 localPos)
    {
        if (isValid)
        {
            string text = processedText;
            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }

            if (usePrintedSize)
            {
                UpdateNGUIText(mPrintedSize, mWidth, mHeight);
            }
            else
            {
                UpdateNGUIText(fontSize, mWidth, mHeight);
            }

            NGUIText.PrintCharacterPositions(text, mTempVerts, mTempIndices);

            if (mTempVerts.size > 0)
            {
                ApplyOffset(mTempVerts, 0);
                int retVal = NGUIText.GetClosestCharacter(mTempVerts, localPos);
                retVal = mTempIndices[retVal];

                mTempVerts.Clear();
                mTempIndices.Clear();
                return(retVal);
            }
        }
        return(0);
    }
Exemple #2
0
    /// <summary>
    /// Return the index of the character at the specified local position.
    /// </summary>

    public int GetCharacterIndexAtPosition(Vector2 localPos)
    {
        if (isValid)
        {
            string text = processedText;
            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }

            UpdateNGUIText();

            NGUIText.PrintCharacterPositions(text, mTempVerts, mTempIndices);

            if (mTempVerts.size > 0)
            {
                ApplyOffset(mTempVerts, 0);
                int retVal = NGUIText.GetClosestCharacter(mTempVerts, localPos);
                retVal = mTempIndices[retVal];

                mTempVerts.Clear();
                mTempIndices.Clear();
                return(retVal);
            }
        }
        return(0);
    }
Exemple #3
0
    static int GetClosestCharacter(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        BetterList <Vector3> arg0 = (BetterList <Vector3>)LuaScriptMgr.GetNetObject(L, 1, typeof(BetterList <Vector3>));
        Vector2 arg1 = LuaScriptMgr.GetVector2(L, 2);
        int     o    = NGUIText.GetClosestCharacter(arg0, arg1);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Exemple #4
0
 public int GetCharacterIndexAtPosition(Vector2 localPos)
 {
     if (isValid)
     {
         string value = processedText;
         if (string.IsNullOrEmpty(value))
         {
             return(0);
         }
         UpdateNGUIText();
         NGUIText.PrintCharacterPositions(value, mTempVerts, mTempIndices);
         if (mTempVerts.size > 0)
         {
             ApplyOffset(mTempVerts, 0);
             int closestCharacter = NGUIText.GetClosestCharacter(mTempVerts, localPos);
             closestCharacter = mTempIndices[closestCharacter];
             mTempVerts.Clear();
             mTempIndices.Clear();
             return(closestCharacter);
         }
     }
     return(0);
 }
Exemple #5
0
 public int GetCharacterIndexAtPosition(Vector2 localPos)
 {
     if (this.isValid)
     {
         string processedText = this.processedText;
         if (string.IsNullOrEmpty(processedText))
         {
             return(0);
         }
         this.UpdateNGUIText();
         NGUIText.PrintCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
         if (UILabel.mTempVerts.size > 0)
         {
             this.ApplyOffset(UILabel.mTempVerts, 0);
             int num = NGUIText.GetClosestCharacter(UILabel.mTempVerts, localPos);
             num = UILabel.mTempIndices[num];
             UILabel.mTempVerts.Clear();
             UILabel.mTempIndices.Clear();
             return(num);
         }
     }
     return(0);
 }
Exemple #6
0
    /// <summary>
    /// Return the index of the character at the specified local position.
    /// </summary>

    public int GetCharacterIndex(Vector2 localPos)
    {
        if (isValid)
        {
            string text = processedText;
            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }
            float pixelSize = (mFont != null) ? mFont.pixelSize : 1f;
            float scale     = mScale * pixelSize;
            bool  usePS     = usePrintedSize;

            if (usePS)
            {
                UpdateNGUIText(mPrintedSize, mWidth, mHeight);
            }
            else
            {
                UpdateNGUIText(fontSize, Mathf.RoundToInt(mWidth / scale), mHeight);
            }

            NGUIText.PrintCharacterPositions(text, mTempVerts, mTempIndices);

            if (mTempVerts.size > 0)
            {
                ApplyOffset(mTempVerts, usePS, scale, 0);
                int retVal = NGUIText.GetClosestCharacter(mTempVerts, localPos);
                retVal = mTempIndices[retVal];

                mTempVerts.Clear();
                mTempIndices.Clear();
                return(retVal);
            }
        }
        return(0);
    }
Exemple #7
0
    /// <summary>
    /// Get the index of the character on the line directly above or below the current index.
    /// </summary>

    public int GetCharacterIndex(int currentIndex, KeyCode key)
    {
        if (isValid)
        {
            string text = processedText;
            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }

            int def = defaultFontSize;
            UpdateNGUIText();

            NGUIText.PrintCharacterPositions(text, mTempVerts, mTempIndices);

            if (mTempVerts.size > 0)
            {
                ApplyOffset(mTempVerts, 0);

                for (int i = 0; i < mTempIndices.size; ++i)
                {
                    if (mTempIndices[i] == currentIndex)
                    {
                        // Determine position on the line above or below this character
                        Vector2 localPos = mTempVerts[i];

                        if (key == KeyCode.UpArrow)
                        {
                            localPos.y += def + spacingY;
                        }
                        else if (key == KeyCode.DownArrow)
                        {
                            localPos.y -= def + spacingY;
                        }
                        else if (key == KeyCode.Home)
                        {
                            localPos.x -= 1000f;
                        }
                        else if (key == KeyCode.End)
                        {
                            localPos.x += 1000f;
                        }

                        // Find the closest character to this position
                        int retVal = NGUIText.GetClosestCharacter(mTempVerts, localPos);
                        retVal = mTempIndices[retVal];
                        if (retVal == currentIndex)
                        {
                            break;
                        }

                        mTempVerts.Clear();
                        mTempIndices.Clear();
                        return(retVal);
                    }
                }
                mTempVerts.Clear();
                mTempIndices.Clear();
            }

            // If the selection doesn't move, then we're at the top or bottom-most line
            if (key == KeyCode.UpArrow || key == KeyCode.Home)
            {
                return(0);
            }
            if (key == KeyCode.DownArrow || key == KeyCode.End)
            {
                return(text.Length);
            }
        }
        return(currentIndex);
    }
Exemple #8
0
    public int GetCharacterIndex(int currentIndex, KeyCode key)
    {
        if (isValid)
        {
            string text = processedText;
            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }
            int num = defaultFontSize;
            UpdateNGUIText();
            NGUIText.PrintCharacterPositions(text, mTempVerts, mTempIndices);
            if (mTempVerts.size > 0)
            {
                ApplyOffset(mTempVerts, 0);
                for (int i = 0; i < mTempIndices.size; i++)
                {
                    if (mTempIndices[i] == currentIndex)
                    {
                        Vector2 pos = mTempVerts[i];
                        switch (key)
                        {
                        case KeyCode.UpArrow:
                            pos.y += num + spacingY;
                            break;

                        case KeyCode.DownArrow:
                            pos.y -= num + spacingY;
                            break;

                        case KeyCode.Home:
                            pos.x -= 1000f;
                            break;

                        case KeyCode.End:
                            pos.x += 1000f;
                            break;
                        }
                        int closestCharacter = NGUIText.GetClosestCharacter(mTempVerts, pos);
                        closestCharacter = mTempIndices[closestCharacter];
                        if (closestCharacter == currentIndex)
                        {
                            break;
                        }
                        mTempVerts.Clear();
                        mTempIndices.Clear();
                        return(closestCharacter);
                    }
                }
                mTempVerts.Clear();
                mTempIndices.Clear();
            }
            if (key == KeyCode.UpArrow || key == KeyCode.Home)
            {
                return(0);
            }
            if (key == KeyCode.DownArrow || key == KeyCode.End)
            {
                return(text.Length);
            }
        }
        return(currentIndex);
    }
Exemple #9
0
 public int GetCharacterIndex(int currentIndex, KeyCode key)
 {
     if (this.isValid)
     {
         string processedText = this.processedText;
         if (string.IsNullOrEmpty(processedText))
         {
             return(0);
         }
         int defaultFontSize = this.defaultFontSize;
         this.UpdateNGUIText();
         NGUIText.PrintCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
         if (UILabel.mTempVerts.size > 0)
         {
             this.ApplyOffset(UILabel.mTempVerts, 0);
             int i = 0;
             while (i < UILabel.mTempIndices.size)
             {
                 if (UILabel.mTempIndices[i] == currentIndex)
                 {
                     Vector2 pos = UILabel.mTempVerts[i];
                     if (key == KeyCode.UpArrow)
                     {
                         pos.y += (float)(defaultFontSize + this.spacingY);
                     }
                     else if (key == KeyCode.DownArrow)
                     {
                         pos.y -= (float)(defaultFontSize + this.spacingY);
                     }
                     else if (key == KeyCode.Home)
                     {
                         pos.x -= 1000f;
                     }
                     else if (key == KeyCode.End)
                     {
                         pos.x += 1000f;
                     }
                     int num = NGUIText.GetClosestCharacter(UILabel.mTempVerts, pos);
                     num = UILabel.mTempIndices[num];
                     if (num == currentIndex)
                     {
                         break;
                     }
                     UILabel.mTempVerts.Clear();
                     UILabel.mTempIndices.Clear();
                     return(num);
                 }
                 else
                 {
                     i++;
                 }
             }
             UILabel.mTempVerts.Clear();
             UILabel.mTempIndices.Clear();
         }
         if (key == KeyCode.UpArrow || key == KeyCode.Home)
         {
             return(0);
         }
         if (key == KeyCode.DownArrow || key == KeyCode.End)
         {
             return(processedText.Length);
         }
     }
     return(currentIndex);
 }
Exemple #10
0
    /// <summary>
    /// Get the index of the character on the line directly above or below the current index.
    /// </summary>

    public int GetCharacterIndex(int currentIndex, KeyCode key)
    {
        if (isValid)
        {
            string text = processedText;
            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }
            float pixelSize = (mFont != null) ? mFont.pixelSize : 1f;
            float scale     = mScale * pixelSize;
            bool  usePS     = usePrintedSize;

            if (usePS)
            {
                UpdateNGUIText(mPrintedSize, mWidth, mHeight);
            }
            else
            {
                UpdateNGUIText(fontSize, Mathf.RoundToInt(mWidth / scale), mHeight);
            }

            NGUIText.PrintCharacterPositions(text, mTempVerts, mTempIndices);

            if (mTempVerts.size > 0)
            {
                ApplyOffset(mTempVerts, usePS, scale, 0);

                for (int i = 0; i < mTempIndices.size; ++i)
                {
                    if (mTempIndices[i] == currentIndex)
                    {
                        // Determine position on the line above or below this character
                        Vector2 localPos = mTempVerts[i];

                        if (key == KeyCode.UpArrow)
                        {
                            localPos.y += fontSize + spacingY;
                        }
                        else if (key == KeyCode.DownArrow)
                        {
                            localPos.y -= fontSize + spacingY;
                        }
                        else if (key == KeyCode.Home)
                        {
                            localPos.x -= 1000f;
                        }
                        else if (key == KeyCode.End)
                        {
                            localPos.x += 1000f;
                        }

                        // Find the closest character to this position
                        int retVal = NGUIText.GetClosestCharacter(mTempVerts, localPos);
                        retVal = mTempIndices[retVal];
                        if (retVal == currentIndex)
                        {
                            break;
                        }

                        mTempVerts.Clear();
                        mTempIndices.Clear();
                        return(retVal);
                    }
                }
                mTempVerts.Clear();
                mTempIndices.Clear();
            }

            // If the selection doesn't move, then we're at the top or bottom-most line
            if (key == KeyCode.UpArrow || key == KeyCode.Home)
            {
                return(0);
            }
            if (key == KeyCode.DownArrow || key == KeyCode.End)
            {
                return(text.Length);
            }
        }
        return(currentIndex);
    }