UILabel.MakePixelPerfect C# (CSharp) Méthode

MakePixelPerfect() public méthode

Text is pixel-perfect when its scale matches the size.
public MakePixelPerfect ( ) : void
Résultat void
	public override void MakePixelPerfect ()
	{
		if (ambigiousFont != null)
		{
			float pixelSize = (trueTypeFont != null) ? 1f : bitmapFont.pixelSize;

			Vector3 pos = cachedTransform.localPosition;
			pos.x = Mathf.RoundToInt(pos.x);
			pos.y = Mathf.RoundToInt(pos.y);
			pos.z = Mathf.RoundToInt(pos.z);

			cachedTransform.localPosition = pos;
			cachedTransform.localScale = Vector3.one;

			if (mOverflow == Overflow.ResizeFreely)
			{
				AssumeNaturalSize();
			}
			else
			{
				int w = width;
				int h = height;

				Overflow over = mOverflow;
				mOverflow = Overflow.ShrinkContent;
				mWidth = 100000;
				mHeight = 100000;
				ProcessText(false);
				mOverflow = over;

				int minX = Mathf.RoundToInt(mCalculatedSize.x * pixelSize);
				int minY = Mathf.RoundToInt(mCalculatedSize.y * pixelSize);

				minX = Mathf.Max(minX, base.minWidth);
				minY = Mathf.Max(minY, base.minHeight);

				mWidth = Mathf.Max(w, minX);
				mHeight = Mathf.Max(h, minY);

				MarkAsChanged();
			}
		}
		else base.MakePixelPerfect();
	}

Usage Example

Exemple #1
0
    public void AddText(string txt)
    {
        if (textList.Count == 0)
        {
            UILabel label = msg.GetComponent <UILabel>();
            label.text = txt;
            label.MakePixelPerfect();
            AddLabel(label);
            msg.name = "0";
        }
        else if (textList.Count >= MaxLine)
        {
            UILabel label = textList[0];
            textList.Remove(label);
            Vector3 pos  = msg.transform.localPosition;
            UILabel temp = msg.GetComponent <UILabel>();
            pos.y -= temp.height;
            label.transform.localPosition = pos;
            label.text = txt;
            label.MakePixelPerfect();
            AddLabel(label);
            msg = label.gameObject;
        }
        else
        {
            GameObject obj = GameObject.Instantiate(msg) as GameObject;
            obj.transform.parent = msg.transform.parent;
            obj.name             = (int.Parse(msg.name) + 1).ToString();
            Vector3 pos   = msg.transform.localPosition;
            UILabel label = msg.GetComponent <UILabel>();
            pos.y -= label.height;
            obj.transform.localPosition = pos;
            label      = obj.GetComponent <UILabel>();
            label.text = txt;
            label.MakePixelPerfect();
            AddLabel(label);
            msg = obj;
        }

        UIDraggablePanel panel = GetComponent <UIDraggablePanel>();
        float            size  = panel.bounds.size.y;

        if (size > 300)
        {
            Vector3 pos  = panel.transform.localPosition;
            Vector3 pos1 = msg.transform.localPosition;
            pos.y = (Mathf.Abs(pos1.y) - 152 - pos.y);
            panel.MoveRelative(pos);
        }
    }
All Usage Examples Of UILabel::MakePixelPerfect