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.

27 lines
726 B

  1. using UnityEngine;
  2. using System;
  3. namespace TMPro
  4. {
  5. /// <summary>
  6. /// EXample of a Custom Character Input Validator to only allow digits from 0 to 9.
  7. /// </summary>
  8. [Serializable]
  9. //[CreateAssetMenu(fileName = "InputValidator - Digits.asset", menuName = "TextMeshPro/Input Validators/Digits", order = 100)]
  10. public class TMP_DigitValidator : TMP_InputValidator
  11. {
  12. // Custom text input validation function
  13. public override char Validate(ref string text, ref int pos, char ch)
  14. {
  15. if (ch >= '0' && ch <= '9')
  16. {
  17. text += ch;
  18. pos += 1;
  19. return ch;
  20. }
  21. return (char)0;
  22. }
  23. }
  24. }