Global Game Jam 2022
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.

128 lines
4.2 KiB

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