Benchmark01_UGUI.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. namespace TMPro.Examples
  5. {
  6. public class Benchmark01_UGUI : MonoBehaviour
  7. {
  8. public int BenchmarkType = 0;
  9. public Canvas canvas;
  10. public TMP_FontAsset TMProFont;
  11. public Font TextMeshFont;
  12. private TextMeshProUGUI m_textMeshPro;
  13. //private TextContainer m_textContainer;
  14. private Text m_textMesh;
  15. private const string label01 = "The <#0050FF>count is: </color>";
  16. private const string label02 = "The <color=#0050FF>count is: </color>";
  17. //private const string label01 = "TextMesh <#0050FF>Pro!</color> The count is: {0}";
  18. //private const string label02 = "Text Mesh<color=#0050FF> The count is: </color>";
  19. //private string m_string;
  20. //private int m_frame;
  21. private Material m_material01;
  22. private Material m_material02;
  23. IEnumerator Start()
  24. {
  25. if (BenchmarkType == 0) // TextMesh Pro Component
  26. {
  27. m_textMeshPro = gameObject.AddComponent<TextMeshProUGUI>();
  28. //m_textContainer = GetComponent<TextContainer>();
  29. //m_textMeshPro.anchorDampening = true;
  30. if (TMProFont != null)
  31. m_textMeshPro.font = TMProFont;
  32. //m_textMeshPro.font = Resources.Load("Fonts & Materials/Anton SDF", typeof(TextMeshProFont)) as TextMeshProFont; // Make sure the Anton SDF exists before calling this...
  33. //m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/Anton SDF", typeof(Material)) as Material; // Same as above make sure this material exists.
  34. m_textMeshPro.fontSize = 48;
  35. m_textMeshPro.alignment = TextAlignmentOptions.Center;
  36. //m_textMeshPro.anchor = AnchorPositions.Center;
  37. m_textMeshPro.extraPadding = true;
  38. //m_textMeshPro.outlineWidth = 0.25f;
  39. //m_textMeshPro.fontSharedMaterial.SetFloat("_OutlineWidth", 0.2f);
  40. //m_textMeshPro.fontSharedMaterial.EnableKeyword("UNDERLAY_ON");
  41. //m_textMeshPro.lineJustification = LineJustificationTypes.Center;
  42. //m_textMeshPro.enableWordWrapping = true;
  43. //m_textMeshPro.lineLength = 60;
  44. //m_textMeshPro.characterSpacing = 0.2f;
  45. //m_textMeshPro.fontColor = new Color32(255, 255, 255, 255);
  46. m_material01 = m_textMeshPro.font.material;
  47. m_material02 = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - BEVEL"); // Make sure the LiberationSans SDF exists before calling this...
  48. }
  49. else if (BenchmarkType == 1) // TextMesh
  50. {
  51. m_textMesh = gameObject.AddComponent<Text>();
  52. if (TextMeshFont != null)
  53. {
  54. m_textMesh.font = TextMeshFont;
  55. //m_textMesh.renderer.sharedMaterial = m_textMesh.font.material;
  56. }
  57. else
  58. {
  59. //m_textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font;
  60. //m_textMesh.renderer.sharedMaterial = m_textMesh.font.material;
  61. }
  62. m_textMesh.fontSize = 48;
  63. m_textMesh.alignment = TextAnchor.MiddleCenter;
  64. //m_textMesh.color = new Color32(255, 255, 0, 255);
  65. }
  66. for (int i = 0; i <= 1000000; i++)
  67. {
  68. if (BenchmarkType == 0)
  69. {
  70. m_textMeshPro.text = label01 + (i % 1000);
  71. if (i % 1000 == 999)
  72. m_textMeshPro.fontSharedMaterial = m_textMeshPro.fontSharedMaterial == m_material01 ? m_textMeshPro.fontSharedMaterial = m_material02 : m_textMeshPro.fontSharedMaterial = m_material01;
  73. }
  74. else if (BenchmarkType == 1)
  75. m_textMesh.text = label02 + (i % 1000).ToString();
  76. yield return null;
  77. }
  78. yield return null;
  79. }
  80. /*
  81. void Update()
  82. {
  83. if (BenchmarkType == 0)
  84. {
  85. m_textMeshPro.text = (m_frame % 1000).ToString();
  86. }
  87. else if (BenchmarkType == 1)
  88. {
  89. m_textMesh.text = (m_frame % 1000).ToString();
  90. }
  91. m_frame += 1;
  92. }
  93. */
  94. }
  95. }