当前位置: 首页>>代码示例>>C#>>正文


C# Font.RequestCharactersInTexture方法代码示例

本文整理汇总了C#中UnityEngine.Font.RequestCharactersInTexture方法的典型用法代码示例。如果您正苦于以下问题:C# Font.RequestCharactersInTexture方法的具体用法?C# Font.RequestCharactersInTexture怎么用?C# Font.RequestCharactersInTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Font的用法示例。


在下文中一共展示了Font.RequestCharactersInTexture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildTextLine

    ///////////////////////////////////////////////////////////////////////////////
    // build mesh
    ///////////////////////////////////////////////////////////////////////////////
    // ------------------------------------------------------------------
    // Desc: This only calculate result in one line
    // ------------------------------------------------------------------
    public static void BuildTextLine( Vector3[] _vertices, Vector2[] _uvs, 
                                       string _text, 
                                       Font _font, 
                                       int _lineHeight,
                                       int _fontSize, 
                                       int _wordSpacing, 
                                       int _letterSpacing )
    {
        int cur_x = 0;
        int cur_y = 0;

        // yes, Unity's GetCharacterInfo have y problem, you should get lowest character j's y-offset adjust it.
        CharacterInfo jCharInfo;
        _font.RequestCharactersInTexture ( "j", _fontSize, FontStyle.Normal );
        _font.GetCharacterInfo('j', out jCharInfo, _fontSize, FontStyle.Normal);
        float ttf_offset = (_fontSize + jCharInfo.vert.yMax);

        //
        for ( int i = 0; i < _text.Length; ++i ) {
            char cur_char = _text[i];

            // NOTE: we skip new-line operation, since we believe this function only have one-line text
            if ( cur_char == '\n' ) {
                continue;
            }

            // generate mesh
            CharacterInfo charInfo;
            _font.GetCharacterInfo ( cur_char, out charInfo, _fontSize );
            int idx = 4*i;

            // build vertices
            _vertices[idx + 0] = new Vector3(cur_x + charInfo.vert.xMin, cur_y - charInfo.vert.yMin + ttf_offset, 0.0f);
            _vertices[idx + 1] = new Vector3(cur_x + charInfo.vert.xMax, cur_y - charInfo.vert.yMin + ttf_offset, 0.0f);
            _vertices[idx + 2] = new Vector3(cur_x + charInfo.vert.xMax, cur_y - charInfo.vert.yMax + ttf_offset, 0.0f);
            _vertices[idx + 3] = new Vector3(cur_x + charInfo.vert.xMin, cur_y - charInfo.vert.yMax + ttf_offset, 0.0f);

            // build uv
            if ( charInfo.flipped ) {
                _uvs[idx + 0] = new Vector2(charInfo.uv.xMax, charInfo.uv.yMin);
                _uvs[idx + 1] = new Vector2(charInfo.uv.xMax, charInfo.uv.yMax);
                _uvs[idx + 2] = new Vector2(charInfo.uv.xMin, charInfo.uv.yMax);
                _uvs[idx + 3] = new Vector2(charInfo.uv.xMin, charInfo.uv.yMin);
            }
            else {
                _uvs[idx + 0] = new Vector2(charInfo.uv.xMin, charInfo.uv.yMax);
                _uvs[idx + 1] = new Vector2(charInfo.uv.xMax, charInfo.uv.yMax);
                _uvs[idx + 2] = new Vector2(charInfo.uv.xMax, charInfo.uv.yMin);
                _uvs[idx + 3] = new Vector2(charInfo.uv.xMin, charInfo.uv.yMin);
            }

            // advance x
            cur_x += (int)charInfo.width + _letterSpacing;
            if ( cur_char == ' ' )
                cur_x += _wordSpacing;
        }
    }
开发者ID:knoxHuang,项目名称:ex2d-dev,代码行数:63,代码来源:exTextUtility.cs

示例2: CalculateOffsetToFit

 public static int CalculateOffsetToFit(Font font, string text)
 {
     if (((font == null) || string.IsNullOrEmpty(text)) || (current.lineWidth < 1))
     {
         return 0;
     }
     int finalSize = current.finalSize;
     font.RequestCharactersInTexture(text, finalSize, current.style);
     float finalLineWidth = current.finalLineWidth;
     int length = text.Length;
     while ((length > 0) && (finalLineWidth > 0f))
     {
         char ch = text[--length];
         if (font.GetCharacterInfo(ch, out mTempChar, finalSize, current.style))
         {
             finalLineWidth -= mTempChar.width;
         }
     }
     if (finalLineWidth < 0f)
     {
         length++;
     }
     return length;
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:24,代码来源:NGUIText.cs

示例3: Print

	/// <summary>
	/// Print the specified text into the buffers.
	/// </summary>

	static public void Print (Font font, string text, BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
	{
		if (font == null || string.IsNullOrEmpty(text)) return;

		int size = current.finalSize;
		int indexOffset = verts.size;
		float lineHeight = size + current.finalSpacingY;

		// We need to know the baseline first
		float baseline = 0f;
		font.RequestCharactersInTexture("j", size, current.style);
		font.GetCharacterInfo('j', out mTempChar, size, current.style);
		baseline = size + mTempChar.vert.yMax;

		// Ensure that the text we're about to print exists in the font's texture
		font.RequestCharactersInTexture(text, size, current.style);

		// Start with the white tint
		mColors.Add(Color.white);

		float x = 0f;
		float y = 0f;
		float maxX = 0f;
		float spacingX = current.finalSpacingX;
		float pixelSize = 1f / current.pixelDensity;
		float sizeF = size;
		
		Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
		Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
		Color gb = current.tint * current.gradientBottom;
		Color gt = current.tint * current.gradientTop;
		Color32 uc = current.tint;
		int textLength = text.Length;

		for (int i = 0; i < textLength; ++i)
		{
			char c = text[i];

			if (c == '\n')
			{
				if (x > maxX) maxX = x;

				if (current.alignment != TextAlignment.Left)
				{
					Align(verts, indexOffset, x - spacingX);
					indexOffset = verts.size;
				}

				x = 0;
				y += lineHeight;
				continue;
			}

			if (c < ' ') continue;

			// Color changing symbol
			if (current.encoding && ParseSymbol(text, ref i, mColors, current.premultiply))
			{
				Color fc = current.tint * mColors[mColors.size - 1];
				uc = fc;

				if (current.gradient)
				{
					gb = current.gradientBottom * fc;
					gt = current.gradientTop * fc;
				}
				--i;
				continue;
			}

			if (!font.GetCharacterInfo(c, out mTempChar, size, current.style))
				continue;

			v0.x =  (x + mTempChar.vert.xMin);
			v0.y = -(y - mTempChar.vert.yMax + baseline);
			
			v1.x = v0.x + mTempChar.vert.width;
			v1.y = v0.y - mTempChar.vert.height;

			if (pixelSize != 1f)
			{
				v0 *= pixelSize;
				v1 *= pixelSize;
			}

			u0.x = mTempChar.uv.xMin;
			u0.y = mTempChar.uv.yMin;
			u1.x = mTempChar.uv.xMax;
			u1.y = mTempChar.uv.yMax;

			x += (mTempChar.width + spacingX);

			verts.Add(new Vector3(v1.x, v0.y));
			verts.Add(new Vector3(v0.x, v0.y));
			verts.Add(new Vector3(v0.x, v1.y));
			verts.Add(new Vector3(v1.x, v1.y));
//.........这里部分代码省略.........
开发者ID:Jetblacktsunami,项目名称:TreasureCove,代码行数:101,代码来源:NGUIText.cs

示例4: WrapText

	/// <summary>
	/// Text wrapping functionality. The 'width' and 'height' should be in pixels.
	/// </summary>

	static public bool WrapText (Font font, string text, out string finalText)
	{
		if (current.lineWidth < 1 || current.lineHeight < 1 || string.IsNullOrEmpty(text))
		{
			finalText = "";
			return false;
		}

		int maxLineCount = (current.maxLines > 0) ? current.maxLines : 1000000;
		int size = current.finalSize;
		float height = (current.maxLines > 0) ?
			Mathf.Min(current.finalLineHeight, size * current.maxLines) :
			current.finalLineHeight;

		float sum = size + current.finalSpacingY;
		maxLineCount = Mathf.FloorToInt((sum > 0) ? Mathf.Min(maxLineCount, height / sum) : 0);

		if (maxLineCount == 0)
		{
			finalText = "";
			return false;
		}

		// Ensure that we have the required characters to work with
		if (font != null) font.RequestCharactersInTexture(text, size, current.style);

		StringBuilder sb = new StringBuilder();
		int textLength = text.Length;
		float lineWidth = current.finalLineWidth;
		float remainingWidth = lineWidth;
		float finalSpacingX = current.finalSpacingX;

		int start = 0;
		int offset = 0;
		int lineCount = 1;
		int previousChar = 0;
		bool lineIsEmpty = true;

		// Run through all characters
		for (; offset < textLength; ++offset)
		{
			char ch = text[offset];

			// New line character -- start a new line
			if (ch == '\n')
			{
				if (lineCount == maxLineCount) break;
				remainingWidth = lineWidth;

				// Add the previous word to the final string
				if (start < offset) sb.Append(text.Substring(start, offset - start + 1));
				else sb.Append(ch);

				lineIsEmpty = true;
				++lineCount;
				start = offset + 1;
				previousChar = 0;
				continue;
			}

			// If this marks the end of a word, add it to the final string.
			if (ch == ' ' && previousChar != ' ' && start < offset)
			{
				sb.Append(text.Substring(start, offset - start + 1));
				lineIsEmpty = false;
				start = offset + 1;
				previousChar = ch;
			}

			// When encoded symbols such as [RrGgBb] or [-] are encountered, skip past them
			if (ParseSymbol(text, ref offset)) { --offset; continue; }

			// If the character is missing for any reason, skip it
			if (!font.GetCharacterInfo(ch, out mTempChar, size, current.style)) continue;

			float glyphWidth = finalSpacingX + mTempChar.width;
			remainingWidth -= glyphWidth;

			// Doesn't fit?
			if (remainingWidth < 0)
			{
				// Can't start a new line
				if (lineIsEmpty || lineCount == maxLineCount)
				{
					// This is the first word on the line -- add it up to the character that fits
					sb.Append(text.Substring(start, Mathf.Max(0, offset - start)));

					if (lineCount++ == maxLineCount)
					{
						start = offset;
						break;
					}
					EndLine(ref sb);

					// Start a brand-new line
					lineIsEmpty = true;
//.........这里部分代码省略.........
开发者ID:Jetblacktsunami,项目名称:TreasureCove,代码行数:101,代码来源:NGUIText.cs

示例5: RequestCharactersInTexture

	/// <summary>
	/// Ensure that we have the requested characters present.
	/// </summary>

	static public void RequestCharactersInTexture (Font font, string text)
	{
		if (font != null)
		{
			font.RequestCharactersInTexture(text, current.finalSize, current.style);
		}
	}
开发者ID:Jetblacktsunami,项目名称:TreasureCove,代码行数:11,代码来源:NGUIText.cs

示例6: CalculateOffsetToFit

	/// <summary>
	/// Calculate the character index offset required to print the end of the specified text.
	/// NOTE: This function assumes that the text has been stripped of all symbols.
	/// </summary>

	static public int CalculateOffsetToFit (Font font, string text)
	{
		if (font == null || string.IsNullOrEmpty(text) || current.lineWidth < 1) return 0;

		// Ensure we have the characters to work with
		int size = current.finalSize;
		font.RequestCharactersInTexture(text, size, current.style);

		float remainingWidth = current.finalLineWidth;
		int textLength = text.Length;
		int currentCharacterIndex = textLength;

		while (currentCharacterIndex > 0 && remainingWidth > 0f)
		{
			char c = text[--currentCharacterIndex];
			if (font.GetCharacterInfo(c, out mTempChar, size, current.style))
				remainingWidth -= mTempChar.width;
		}

		if (remainingWidth < 0f) ++currentCharacterIndex;
		return currentCharacterIndex;
	}
开发者ID:Jetblacktsunami,项目名称:TreasureCove,代码行数:27,代码来源:NGUIText.cs

示例7: CalculatePrintedSize

	/// <summary>
	/// Get the printed size of the specified string. The returned value is in pixels.
	/// </summary>

	static public Vector2 CalculatePrintedSize (Font font, string text)
	{
		Vector2 v = Vector2.zero;

		if (font != null && !string.IsNullOrEmpty(text))
		{
			// When calculating printed size, get rid of all symbols first since they are invisible anyway
			if (current.encoding) text = StripSymbols(text);

			// Ensure we have characters to work with
			int size = current.finalSize;
			font.RequestCharactersInTexture(text, size, current.style);

			float x = 0;
			float y = 0;
			float maxX = 0f;
			float lineHeight = size + current.finalSpacingY;
			float spacingX = current.finalSpacingX;
			int chars = text.Length;

			for (int i = 0; i < chars; ++i)
			{
				char c = text[i];

				// Start a new line
				if (c == '\n')
				{
					if (x > maxX) maxX = x;
					x = 0f;
					y += lineHeight;
					continue;
				}

				// Skip invalid characters
				if (c < ' ') continue;

				if (font.GetCharacterInfo(c, out mTempChar, size, current.style))
					x += mTempChar.width + spacingX;
			}

			// Padding is always between characters, so it's one less than the number of characters
			v.x = ((x > maxX) ? x : maxX);
			v.y = (y + size);
			v /= current.pixelDensity;
		}
		return v;
	}
开发者ID:Jetblacktsunami,项目名称:TreasureCove,代码行数:51,代码来源:NGUIText.cs

示例8: RequestCharactersInTexture

		//フォントの文字画像の作成リクエスト
		void RequestCharactersInTexture(Font font, List<UguiNovelTextCharacter> characterDataList)
		{
			List<RequestCharactersInfo> infoList = MakeRequestCharactersInfoList(characterDataList);
			isRequestingCharactersInTexture = true;

#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6
			font.textureRebuildCallback += FontTextureRebuildCallback;
			foreach (RequestCharactersInfo info in infoList)
			{
				font.RequestCharactersInTexture(info.characters, info.size, info.style);
			}
			font.textureRebuildCallback -= FontTextureRebuildCallback;
#else
			Font.textureRebuilt += FontTextureRebuildCallback;
			foreach (RequestCharactersInfo info in infoList)
			{
				font.RequestCharactersInTexture(info.characters, info.size, info.style);
			}
			Font.textureRebuilt -= FontTextureRebuildCallback;
#endif
			isRequestingCharactersInTexture = false;
		}
开发者ID:OsamaRazaAnsari,项目名称:2DDressUpGame,代码行数:23,代码来源:UguiNovelTextGenerator.cs

示例9: Print

	/// <summary>
	/// Print the specified text into the buffers.
	/// </summary>

	static public void Print (string text, Font font, int size, FontStyle style, Color32 color,
		bool encoding, TextAlignment alignment, int lineWidth, bool premultiply,
		BetterList<Vector3> verts,
		BetterList<Vector2> uvs,
		BetterList<Color32> cols)
	{
		if (font == null || string.IsNullOrEmpty(text)) return;

		float baseline = 0f;

		// We need to know the baseline first
		font.RequestCharactersInTexture("j", size, style);
		font.GetCharacterInfo('j', out mTempChar, size, style);
		baseline = size + mTempChar.vert.yMax;

		// Ensure that the text we're about to print exists in the font's texture
		font.RequestCharactersInTexture(text, size, style);

		// Start with the specified color
		mColors.Add(color);

		int indexOffset = verts.size;
		int maxX = 0;
		int x = 0;
		int y = 0;
		int lineHeight = size;
		Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
		Vector2 u0 = Vector2.zero, u1 = Vector2.zero;

		int textLength = text.Length;

		for (int i = 0; i < textLength; ++i)
		{
			char c = text[i];

			if (c == '\n')
			{
				if (x > maxX) maxX = x;

				if (alignment != TextAlignment.Left)
				{
					Align(verts, indexOffset, alignment, x, lineWidth);
					indexOffset = verts.size;
				}

				x = 0;
				y += lineHeight;
				continue;
			}

			if (c < ' ') continue;

			if (encoding && ParseSymbol(text, ref i, mColors, premultiply))
			{
				color = mColors[mColors.size - 1];
				--i;
				continue;
			}

			if (!font.GetCharacterInfo(c, out mTempChar, size, style))
				continue;

			v0.x =  (x + mTempChar.vert.xMin);
			v0.y = -(y - mTempChar.vert.yMax + baseline);

			v1.x = v0.x + mTempChar.vert.width;
			v1.y = v0.y - mTempChar.vert.height;

			u0.x = mTempChar.uv.xMin;
			u0.y = mTempChar.uv.yMin;
			u1.x = mTempChar.uv.xMax;
			u1.y = mTempChar.uv.yMax;

			x += (int)mTempChar.width;

			for (int b = 0; b < 4; ++b) cols.Add(color);

			if (mTempChar.flipped)
			{
				uvs.Add(new Vector2(u0.x, u1.y));
				uvs.Add(new Vector2(u0.x, u0.y));
				uvs.Add(new Vector2(u1.x, u0.y));
				uvs.Add(new Vector2(u1.x, u1.y));
			}
			else
			{
				uvs.Add(new Vector2(u1.x, u0.y));
				uvs.Add(new Vector2(u0.x, u0.y));
				uvs.Add(new Vector2(u0.x, u1.y));
				uvs.Add(new Vector2(u1.x, u1.y));
			}

			verts.Add(new Vector3(v1.x, v0.y));
			verts.Add(new Vector3(v0.x, v0.y));
			verts.Add(new Vector3(v0.x, v1.y));
			verts.Add(new Vector3(v1.x, v1.y));
//.........这里部分代码省略.........
开发者ID:huw12313212,项目名称:Virtual-Piano,代码行数:101,代码来源:NGUIText.cs

示例10: CalculateOffsetToFit

	/// <summary>
	/// Calculate the character index offset required to print the end of the specified text.
	/// NOTE: This function assumes that the text has been stripped of all symbols.
	/// </summary>

	static public int CalculateOffsetToFit (string text, Font font, int size, FontStyle style, int lineWidth)
	{
		if (font == null || string.IsNullOrEmpty(text) || lineWidth < 1) return 0;

		// Ensure we have the characters to work with
		font.RequestCharactersInTexture(text, size, style);
		
		int textLength = text.Length;
		int remainingWidth = lineWidth;
		int currentCharacterIndex = textLength;

		while (currentCharacterIndex > 0 && remainingWidth > 0)
		{
			char c = text[--currentCharacterIndex];
			if (font.GetCharacterInfo(c, out mTempChar, size, style))
				remainingWidth -= (int)mTempChar.width;
		}

		if (remainingWidth < 0) ++currentCharacterIndex;
		return currentCharacterIndex;
	}
开发者ID:huw12313212,项目名称:Virtual-Piano,代码行数:26,代码来源:NGUIText.cs

示例11: CalculatePrintedSize

	/// <summary>
	/// Get the printed size of the specified string. The returned value is in pixels.
	/// </summary>

	static public Vector2 CalculatePrintedSize (string text, Font font, int size, FontStyle style, bool encoding)
	{
		Vector2 v = Vector2.zero;

		if (font != null && !string.IsNullOrEmpty(text))
		{
			// When calculating printed size, get rid of all symbols first since they are invisible anyway
			if (encoding) text = NGUIText.StripSymbols(text);

			// Ensure we have characters to work with
			font.RequestCharactersInTexture(text, size, style);

			float x = 0f;
			float y = 0;
			float fs = size;
			float maxX = 0f;

			for (int i = 0, imax = text.Length; i < imax; ++i)
			{
				char c = text[i];

				// Start a new line
				if (c == '\n')
				{
					if (x > maxX) maxX = x;
					x = 0f;
					y += fs;
					continue;
				}

				// Skip invalid characters
				if (c < ' ') continue;

				if (font.GetCharacterInfo(c, out mTempChar, size, style))
					x += mTempChar.width;

				// Convert from pixel coordinates to local coordinates
				v.x = ((x > maxX) ? x : maxX);
				v.y = (y + fs);
			}
		}
		return v;
	}
开发者ID:huw12313212,项目名称:Virtual-Piano,代码行数:47,代码来源:NGUIText.cs

示例12: CalculatePrintedSize

 public static Vector2 CalculatePrintedSize(Font font, string text)
 {
     Vector2 zero = Vector2.zero;
     if ((font == null) || string.IsNullOrEmpty(text))
     {
         return zero;
     }
     if (current.encoding)
     {
         text = StripSymbols(text);
     }
     int finalSize = current.finalSize;
     font.RequestCharactersInTexture(text, finalSize, current.style);
     float num2 = 0f;
     float num3 = 0f;
     float num4 = 0f;
     float num5 = finalSize + current.finalSpacingY;
     float finalSpacingX = current.finalSpacingX;
     int length = text.Length;
     for (int i = 0; i < length; i++)
     {
         char ch = text[i];
         if (ch == '\n')
         {
             if (num2 > num4)
             {
                 num4 = num2;
             }
             num2 = 0f;
             num3 += num5;
         }
         else if ((ch >= ' ') && font.GetCharacterInfo(ch, out mTempChar, finalSize, current.style))
         {
             num2 += mTempChar.width + finalSpacingX;
         }
     }
     zero.x = (num2 <= num4) ? num4 : num2;
     zero.y = num3 + finalSize;
     return (Vector2) (zero / current.pixelDensity);
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:40,代码来源:NGUIText.cs

示例13: WrapText

 public static bool WrapText(Font font, string text, out string finalText)
 {
     if (((current.lineWidth < 1) || (current.lineHeight < 1)) || string.IsNullOrEmpty(text))
     {
         finalText = string.Empty;
         return false;
     }
     int b = (current.maxLines <= 0) ? 0xf4240 : current.maxLines;
     int finalSize = current.finalSize;
     float num3 = (current.maxLines <= 0) ? current.finalLineHeight : Mathf.Min(current.finalLineHeight, (float) (finalSize * current.maxLines));
     float num4 = finalSize + current.finalSpacingY;
     b = Mathf.FloorToInt((num4 <= 0f) ? 0f : Mathf.Min((float) b, num3 / num4));
     if (b == 0)
     {
         finalText = string.Empty;
         return false;
     }
     if (font != null)
     {
         font.RequestCharactersInTexture(text, finalSize, current.style);
     }
     StringBuilder s = new StringBuilder();
     int length = text.Length;
     float finalLineWidth = current.finalLineWidth;
     float num7 = finalLineWidth;
     float finalSpacingX = current.finalSpacingX;
     int startIndex = 0;
     int index = 0;
     int num11 = 1;
     int num12 = 0;
     bool flag = true;
     while (index < length)
     {
         char ch = text[index];
         if (ch == '\n')
         {
             if (num11 == b)
             {
                 break;
             }
             num7 = finalLineWidth;
             if (startIndex < index)
             {
                 s.Append(text.Substring(startIndex, (index - startIndex) + 1));
             }
             else
             {
                 s.Append(ch);
             }
             flag = true;
             num11++;
             startIndex = index + 1;
             num12 = 0;
         }
         else
         {
             if (((ch == ' ') && (num12 != 0x20)) && (startIndex < index))
             {
                 s.Append(text.Substring(startIndex, (index - startIndex) + 1));
                 flag = false;
                 startIndex = index + 1;
                 num12 = ch;
             }
             if (ParseSymbol(text, ref index))
             {
                 index--;
             }
             else if (font.GetCharacterInfo(ch, out mTempChar, finalSize, current.style))
             {
                 float num13 = finalSpacingX + mTempChar.width;
                 num7 -= num13;
                 if (num7 < 0f)
                 {
                     if (flag || (num11 == b))
                     {
                         s.Append(text.Substring(startIndex, Mathf.Max(0, index - startIndex)));
                         if (num11++ == b)
                         {
                             startIndex = index;
                             break;
                         }
                         EndLine(ref s);
                         flag = true;
                         if (ch == ' ')
                         {
                             startIndex = index + 1;
                             num7 = finalLineWidth;
                         }
                         else
                         {
                             startIndex = index;
                             num7 = finalLineWidth - num13;
                         }
                         num12 = 0;
                     }
                     else
                     {
                         while ((startIndex < length) && (text[startIndex] == ' '))
                         {
                             startIndex++;
//.........这里部分代码省略.........
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:101,代码来源:NGUIText.cs

示例14: Print

 public static void Print(Font font, string text, BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
 {
     if ((font != null) && !string.IsNullOrEmpty(text))
     {
         int finalSize = current.finalSize;
         int size = verts.size;
         float num3 = finalSize + current.finalSpacingY;
         float num4 = 0f;
         font.RequestCharactersInTexture("j", finalSize, current.style);
         font.GetCharacterInfo('j', out mTempChar, finalSize, current.style);
         num4 = finalSize + mTempChar.vert.yMax;
         font.RequestCharactersInTexture(text, finalSize, current.style);
         mColors.Add(Color.white);
         float num5 = 0f;
         float num6 = 0f;
         float num7 = 0f;
         float finalSpacingX = current.finalSpacingX;
         float num9 = 1f / current.pixelDensity;
         float num10 = finalSize;
         Vector3 zero = Vector3.zero;
         Vector3 vector2 = Vector3.zero;
         Vector2 vector3 = Vector2.zero;
         Vector2 vector4 = Vector2.zero;
         Color a = current.tint * current.gradientBottom;
         Color b = current.tint * current.gradientTop;
         Color32 tint = current.tint;
         int length = text.Length;
         for (int i = 0; i < length; i++)
         {
             char ch = text[i];
             if (ch == '\n')
             {
                 if (num5 > num7)
                 {
                     num7 = num5;
                 }
                 if (current.alignment != TextAlignment.Left)
                 {
                     Align(verts, size, num5 - finalSpacingX);
                     size = verts.size;
                 }
                 num5 = 0f;
                 num6 += num3;
             }
             else if (ch >= ' ')
             {
                 if (current.encoding && ParseSymbol(text, ref i, mColors, current.premultiply))
                 {
                     Color color4 = current.tint * mColors[mColors.size - 1];
                     tint = color4;
                     if (current.gradient)
                     {
                         a = current.gradientBottom * color4;
                         b = current.gradientTop * color4;
                     }
                     i--;
                 }
                 else if (font.GetCharacterInfo(ch, out mTempChar, finalSize, current.style))
                 {
                     zero.x = num5 + mTempChar.vert.xMin;
                     zero.y = -((num6 - mTempChar.vert.yMax) + num4);
                     vector2.x = zero.x + mTempChar.vert.width;
                     vector2.y = zero.y - mTempChar.vert.height;
                     if (num9 != 1f)
                     {
                         zero = (Vector3) (zero * num9);
                         vector2 = (Vector3) (vector2 * num9);
                     }
                     vector3.x = mTempChar.uv.xMin;
                     vector3.y = mTempChar.uv.yMin;
                     vector4.x = mTempChar.uv.xMax;
                     vector4.y = mTempChar.uv.yMax;
                     num5 += mTempChar.width + finalSpacingX;
                     verts.Add(new Vector3(vector2.x, zero.y));
                     verts.Add(new Vector3(zero.x, zero.y));
                     verts.Add(new Vector3(zero.x, vector2.y));
                     verts.Add(new Vector3(vector2.x, vector2.y));
                     if (mTempChar.flipped)
                     {
                         uvs.Add(new Vector2(vector3.x, vector4.y));
                         uvs.Add(new Vector2(vector3.x, vector3.y));
                         uvs.Add(new Vector2(vector4.x, vector3.y));
                         uvs.Add(new Vector2(vector4.x, vector4.y));
                     }
                     else
                     {
                         uvs.Add(new Vector2(vector4.x, vector3.y));
                         uvs.Add(new Vector2(vector3.x, vector3.y));
                         uvs.Add(new Vector2(vector3.x, vector4.y));
                         uvs.Add(new Vector2(vector4.x, vector4.y));
                     }
                     if (current.gradient)
                     {
                         float t = num10 - (-mTempChar.vert.yMax + num4);
                         float num14 = t - mTempChar.vert.height;
                         t /= num10;
                         num14 /= num10;
                         s_c0 = Color.Lerp(a, b, t);
                         s_c1 = Color.Lerp(a, b, num14);
                         cols.Add(s_c0);
//.........这里部分代码省略.........
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:101,代码来源:NGUIText.cs

示例15: WrapText

	/// <summary>
	/// Text wrapping functionality. The 'width' and 'height' should be in pixels.
	/// </summary>

	static public bool WrapText (string text, Font font, int size, FontStyle style, int width,
		int height, int maxLines, bool encoding, out string finalText)
	{
		if (width < 1 || height < 1)
		{
			finalText = "";
			return false;
		}

		int maxLineCount = (maxLines > 0) ? maxLines : 999999;
		maxLineCount = Mathf.Min(maxLineCount, height / size);

		if (maxLineCount == 0)
		{
			finalText = "";
			return false;
		}

		// Ensure that we have the required characters to work with
		if (font != null) font.RequestCharactersInTexture(text, size, style);

		StringBuilder sb = new StringBuilder();
		int textLength = text.Length;
		int remainingWidth = width;
		int previousChar = 0;
		int start = 0;
		int offset = 0;
		bool lineIsEmpty = true;
		bool multiline = (maxLines != 1);
		int lineCount = 1;

		// Run through all characters
		for (; offset < textLength; ++offset)
		{
			char ch = text[offset];

			// New line character -- start a new line
			if (ch == '\n')
			{
				if (!multiline || lineCount == maxLineCount) break;
				remainingWidth = width;

				// Add the previous word to the final string
				if (start < offset) sb.Append(text.Substring(start, offset - start + 1));
				else sb.Append(ch);

				lineIsEmpty = true;
				++lineCount;
				start = offset + 1;
				previousChar = 0;
				continue;
			}

			// If this marks the end of a word, add it to the final string.
			if (ch == ' ' && previousChar != ' ' && start < offset)
			{
				sb.Append(text.Substring(start, offset - start + 1));
				lineIsEmpty = false;
				start = offset + 1;
				previousChar = ch;
			}

			// When encoded symbols such as [RrGgBb] or [-] are encountered, skip past them
			if (ParseSymbol(text, ref offset)) { --offset; continue; }

			int glyphWidth = 0;
			if (font.GetCharacterInfo(ch, out mTempChar, size, style))
				glyphWidth = Mathf.RoundToInt(mTempChar.width);

			remainingWidth -= glyphWidth;

			// Doesn't fit?
			if (remainingWidth < 0)
			{
				// Can't start a new line
				if (lineIsEmpty || !multiline || lineCount == maxLineCount)
				{
					// This is the first word on the line -- add it up to the character that fits
					sb.Append(text.Substring(start, Mathf.Max(0, offset - start)));

					if (!multiline || lineCount == maxLineCount)
					{
						start = offset;
						break;
					}
					EndLine(ref sb);

					// Start a brand-new line
					lineIsEmpty = true;
					++lineCount;

					if (ch == ' ')
					{
						start = offset + 1;
						remainingWidth = width;
					}
//.........这里部分代码省略.........
开发者ID:keplergames,项目名称:TowerDefence2D,代码行数:101,代码来源:NGUIText.cs


注:本文中的UnityEngine.Font.RequestCharactersInTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。