TeleType.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace TMPro.Examples
  4. {
  5. public class TeleType : MonoBehaviour
  6. {
  7. //[Range(0, 100)]
  8. //public int RevealSpeed = 50;
  9. private string label01 = "Example <sprite=2> of using <sprite=7> <#ffa000>Graphics Inline</color> <sprite=5> with Text in <font=\"Bangers SDF\" material=\"Bangers SDF - Drop Shadow\">TextMesh<#40a0ff>Pro</color></font><sprite=0> and Unity<sprite=1>";
  10. private string label02 = "Example <sprite=2> of using <sprite=7> <#ffa000>Graphics Inline</color> <sprite=5> with Text in <font=\"Bangers SDF\" material=\"Bangers SDF - Drop Shadow\">TextMesh<#40a0ff>Pro</color></font><sprite=0> and Unity<sprite=2>";
  11. private TMP_Text m_textMeshPro;
  12. void Awake()
  13. {
  14. // Get Reference to TextMeshPro Component
  15. m_textMeshPro = GetComponent<TMP_Text>();
  16. m_textMeshPro.text = label01;
  17. m_textMeshPro.enableWordWrapping = true;
  18. m_textMeshPro.alignment = TextAlignmentOptions.Top;
  19. //if (GetComponentInParent(typeof(Canvas)) as Canvas == null)
  20. //{
  21. // GameObject canvas = new GameObject("Canvas", typeof(Canvas));
  22. // gameObject.transform.SetParent(canvas.transform);
  23. // canvas.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
  24. // // Set RectTransform Size
  25. // gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 300);
  26. // m_textMeshPro.fontSize = 48;
  27. //}
  28. }
  29. IEnumerator Start()
  30. {
  31. // Force and update of the mesh to get valid information.
  32. m_textMeshPro.ForceMeshUpdate();
  33. int totalVisibleCharacters = m_textMeshPro.textInfo.characterCount; // Get # of Visible Character in text object
  34. int counter = 0;
  35. int visibleCount = 0;
  36. while (true)
  37. {
  38. visibleCount = counter % (totalVisibleCharacters + 1);
  39. m_textMeshPro.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?
  40. // Once the last character has been revealed, wait 1.0 second and start over.
  41. if (visibleCount >= totalVisibleCharacters)
  42. {
  43. yield return new WaitForSeconds(1.0f);
  44. m_textMeshPro.text = label02;
  45. yield return new WaitForSeconds(1.0f);
  46. m_textMeshPro.text = label01;
  47. yield return new WaitForSeconds(1.0f);
  48. }
  49. counter += 1;
  50. yield return new WaitForSeconds(0.05f);
  51. }
  52. //Debug.Log("Done revealing the text.");
  53. }
  54. }
  55. }