Benchmark02.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace TMPro.Examples
  4. {
  5. public class Benchmark02 : MonoBehaviour
  6. {
  7. public int SpawnType = 0;
  8. public int NumberOfNPC = 12;
  9. private TextMeshProFloatingText floatingText_Script;
  10. void Start()
  11. {
  12. for (int i = 0; i < NumberOfNPC; i++)
  13. {
  14. if (SpawnType == 0)
  15. {
  16. // TextMesh Pro Implementation
  17. GameObject go = new GameObject();
  18. go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.25f, Random.Range(-95f, 95f));
  19. TextMeshPro textMeshPro = go.AddComponent<TextMeshPro>();
  20. textMeshPro.autoSizeTextContainer = true;
  21. textMeshPro.rectTransform.pivot = new Vector2(0.5f, 0);
  22. textMeshPro.alignment = TextAlignmentOptions.Bottom;
  23. textMeshPro.fontSize = 96;
  24. textMeshPro.enableKerning = false;
  25. textMeshPro.color = new Color32(255, 255, 0, 255);
  26. textMeshPro.text = "!";
  27. // Spawn Floating Text
  28. floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
  29. floatingText_Script.SpawnType = 0;
  30. }
  31. else if (SpawnType == 1)
  32. {
  33. // TextMesh Implementation
  34. GameObject go = new GameObject();
  35. go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.25f, Random.Range(-95f, 95f));
  36. TextMesh textMesh = go.AddComponent<TextMesh>();
  37. textMesh.font = Resources.Load<Font>("Fonts/ARIAL");
  38. textMesh.GetComponent<Renderer>().sharedMaterial = textMesh.font.material;
  39. textMesh.anchor = TextAnchor.LowerCenter;
  40. textMesh.fontSize = 96;
  41. textMesh.color = new Color32(255, 255, 0, 255);
  42. textMesh.text = "!";
  43. // Spawn Floating Text
  44. floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
  45. floatingText_Script.SpawnType = 1;
  46. }
  47. else if (SpawnType == 2)
  48. {
  49. // Canvas WorldSpace Camera
  50. GameObject go = new GameObject();
  51. Canvas canvas = go.AddComponent<Canvas>();
  52. canvas.worldCamera = Camera.main;
  53. go.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
  54. go.transform.position = new Vector3(Random.Range(-95f, 95f), 5f, Random.Range(-95f, 95f));
  55. TextMeshProUGUI textObject = new GameObject().AddComponent<TextMeshProUGUI>();
  56. textObject.rectTransform.SetParent(go.transform, false);
  57. textObject.color = new Color32(255, 255, 0, 255);
  58. textObject.alignment = TextAlignmentOptions.Bottom;
  59. textObject.fontSize = 96;
  60. textObject.text = "!";
  61. // Spawn Floating Text
  62. floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
  63. floatingText_Script.SpawnType = 0;
  64. }
  65. }
  66. }
  67. }
  68. }