Benchmark03.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.TextCore.LowLevel;
  4. namespace TMPro.Examples
  5. {
  6. public class Benchmark03 : MonoBehaviour
  7. {
  8. public enum BenchmarkType { TMP_SDF_MOBILE = 0, TMP_SDF__MOBILE_SSD = 1, TMP_SDF = 2, TMP_BITMAP_MOBILE = 3, TEXTMESH_BITMAP = 4 }
  9. public int NumberOfSamples = 100;
  10. public BenchmarkType Benchmark;
  11. public Font SourceFont;
  12. void Awake()
  13. {
  14. }
  15. void Start()
  16. {
  17. TMP_FontAsset fontAsset = null;
  18. // Create Dynamic Font Asset for the given font file.
  19. switch (Benchmark)
  20. {
  21. case BenchmarkType.TMP_SDF_MOBILE:
  22. fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256, AtlasPopulationMode.Dynamic);
  23. break;
  24. case BenchmarkType.TMP_SDF__MOBILE_SSD:
  25. fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256, AtlasPopulationMode.Dynamic);
  26. fontAsset.material.shader = Shader.Find("TextMeshPro/Mobile/Distance Field SSD");
  27. break;
  28. case BenchmarkType.TMP_SDF:
  29. fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256, AtlasPopulationMode.Dynamic);
  30. fontAsset.material.shader = Shader.Find("TextMeshPro/Distance Field");
  31. break;
  32. case BenchmarkType.TMP_BITMAP_MOBILE:
  33. fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SMOOTH, 256, 256, AtlasPopulationMode.Dynamic);
  34. break;
  35. }
  36. for (int i = 0; i < NumberOfSamples; i++)
  37. {
  38. switch (Benchmark)
  39. {
  40. case BenchmarkType.TMP_SDF_MOBILE:
  41. case BenchmarkType.TMP_SDF__MOBILE_SSD:
  42. case BenchmarkType.TMP_SDF:
  43. case BenchmarkType.TMP_BITMAP_MOBILE:
  44. {
  45. GameObject go = new GameObject();
  46. go.transform.position = new Vector3(0, 1.2f, 0);
  47. TextMeshPro textComponent = go.AddComponent<TextMeshPro>();
  48. textComponent.font = fontAsset;
  49. textComponent.fontSize = 128;
  50. textComponent.text = "@";
  51. textComponent.alignment = TextAlignmentOptions.Center;
  52. textComponent.color = new Color32(255, 255, 0, 255);
  53. if (Benchmark == BenchmarkType.TMP_BITMAP_MOBILE)
  54. textComponent.fontSize = 132;
  55. }
  56. break;
  57. case BenchmarkType.TEXTMESH_BITMAP:
  58. {
  59. GameObject go = new GameObject();
  60. go.transform.position = new Vector3(0, 1.2f, 0);
  61. TextMesh textMesh = go.AddComponent<TextMesh>();
  62. textMesh.GetComponent<Renderer>().sharedMaterial = SourceFont.material;
  63. textMesh.font = SourceFont;
  64. textMesh.anchor = TextAnchor.MiddleCenter;
  65. textMesh.fontSize = 130;
  66. textMesh.color = new Color32(255, 255, 0, 255);
  67. textMesh.text = "@";
  68. }
  69. break;
  70. }
  71. }
  72. }
  73. }
  74. }