You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.0 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. namespace TMPro.Examples
  4. {
  5. public class Benchmark04 : MonoBehaviour
  6. {
  7. public int SpawnType = 0;
  8. public int MinPointSize = 12;
  9. public int MaxPointSize = 64;
  10. public int Steps = 4;
  11. private Transform m_Transform;
  12. //private TextMeshProFloatingText floatingText_Script;
  13. //public Material material;
  14. void Start()
  15. {
  16. m_Transform = transform;
  17. float lineHeight = 0;
  18. float orthoSize = Camera.main.orthographicSize = Screen.height / 2;
  19. float ratio = (float)Screen.width / Screen.height;
  20. for (int i = MinPointSize; i <= MaxPointSize; i += Steps)
  21. {
  22. if (SpawnType == 0)
  23. {
  24. // TextMesh Pro Implementation
  25. GameObject go = new GameObject("Text - " + i + " Pts");
  26. if (lineHeight > orthoSize * 2) return;
  27. go.transform.position = m_Transform.position + new Vector3(ratio * -orthoSize * 0.975f, orthoSize * 0.975f - lineHeight, 0);
  28. TextMeshPro textMeshPro = go.AddComponent<TextMeshPro>();
  29. //textMeshPro.fontSharedMaterial = material;
  30. //textMeshPro.font = Resources.Load("Fonts & Materials/LiberationSans SDF", typeof(TextMeshProFont)) as TextMeshProFont;
  31. //textMeshPro.anchor = AnchorPositions.Left;
  32. textMeshPro.rectTransform.pivot = new Vector2(0, 0.5f);
  33. textMeshPro.enableWordWrapping = false;
  34. textMeshPro.extraPadding = true;
  35. textMeshPro.isOrthographic = true;
  36. textMeshPro.fontSize = i;
  37. textMeshPro.text = i + " pts - Lorem ipsum dolor sit...";
  38. textMeshPro.color = new Color32(255, 255, 255, 255);
  39. lineHeight += i;
  40. }
  41. else
  42. {
  43. // TextMesh Implementation
  44. // Causes crashes since atlas needed exceeds 4096 X 4096
  45. /*
  46. GameObject go = new GameObject("Arial " + i);
  47. //if (lineHeight > orthoSize * 2 * 0.9f) return;
  48. go.transform.position = m_Transform.position + new Vector3(ratio * -orthoSize * 0.975f, orthoSize * 0.975f - lineHeight, 1);
  49. TextMesh textMesh = go.AddComponent<TextMesh>();
  50. textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font;
  51. textMesh.renderer.sharedMaterial = textMesh.font.material;
  52. textMesh.anchor = TextAnchor.MiddleLeft;
  53. textMesh.fontSize = i * 10;
  54. textMesh.color = new Color32(255, 255, 255, 255);
  55. textMesh.text = i + " pts - Lorem ipsum dolor sit...";
  56. lineHeight += i;
  57. */
  58. }
  59. }
  60. }
  61. }
  62. }