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.

97 lines
3.5 KiB

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