UILabel.GetCharacterIndex C# (CSharp) Méthode

GetCharacterIndex() public méthode

Get the index of the character on the line directly above or below the current index.
public GetCharacterIndex ( int currentIndex, KeyCode, key ) : int
currentIndex int
key KeyCode,
Résultat int
	public int GetCharacterIndex (int currentIndex, KeyCode key)
	{
		if (isValid)
		{
			string text = processedText;
			if (string.IsNullOrEmpty(text)) return 0;

			int def = defaultFontSize;
			UpdateNGUIText(def, mWidth, mHeight);

			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;
	}

Same methods

UILabel::GetCharacterIndex ( Vector2 localPos ) : int
UILabel::GetCharacterIndex ( Vector3 worldPos ) : int

Usage Example

    static int GetCharacterIndex(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        UILabel obj  = (UILabel)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UILabel");
        int     arg0 = (int)LuaScriptMgr.GetNumber(L, 2);
        KeyCode arg1 = (KeyCode)LuaScriptMgr.GetNetObject(L, 3, typeof(KeyCode));
        int     o    = obj.GetCharacterIndex(arg0, arg1);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
All Usage Examples Of UILabel::GetCharacterIndex