SetTextV.cs 869 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class SetTextV : MonoBehaviour
  6. {
  7. public Text text;
  8. public Image bj;
  9. //public RectTransform bjRect;
  10. //public RectTransform selectbjRect;
  11. public RectTransform textRect;
  12. public RectTransform canvas;
  13. private Vector2 canvasSize;
  14. private void Start()
  15. {
  16. canvasSize = new Vector2(canvas.rect.width, canvas.rect.height);
  17. }
  18. public void SetText(string str)
  19. {
  20. if (str.Length > 100)
  21. text.fontSize = 20 - ((str.Length - 100) / 50 + 1) * 2;
  22. this.text.text = str;
  23. }
  24. public void SetBackGround(Sprite bj)
  25. {
  26. this.bj.sprite = bj;
  27. }
  28. private void FixedUpdate()
  29. {
  30. canvasSize.y = textRect.sizeDelta.y + 60;
  31. canvas.sizeDelta = canvasSize;
  32. }
  33. }