RestrictInputText.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*===============================================================================
  2. Copyright (C) 2022 Immersal - Part of Hexagon. All Rights Reserved.
  3. This file is part of the Immersal SDK.
  4. The Immersal SDK cannot be copied, distributed, or made available to
  5. third-parties for commercial purposes without written permission of Immersal Ltd.
  6. Contact sdk@immersal.com for licensing requests.
  7. ===============================================================================*/
  8. using UnityEngine;
  9. using TMPro;
  10. namespace Immersal.Samples.Mapping
  11. {
  12. [RequireComponent(typeof(TMP_InputField))]
  13. public class RestrictInputText : MonoBehaviour
  14. {
  15. private enum CharacterSet {alphanumeric, number, integer};
  16. [SerializeField]
  17. private CharacterSet characterSet = CharacterSet.alphanumeric;
  18. void Start()
  19. {
  20. TMP_InputField inputField = GetComponent<TMP_InputField>();
  21. switch (characterSet)
  22. {
  23. case CharacterSet.alphanumeric:
  24. inputField.contentType = TMP_InputField.ContentType.Alphanumeric;
  25. break;
  26. case CharacterSet.number:
  27. inputField.contentType = TMP_InputField.ContentType.DecimalNumber;
  28. break;
  29. case CharacterSet.integer:
  30. inputField.contentType = TMP_InputField.ContentType.IntegerNumber;
  31. break;
  32. default:
  33. inputField.contentType = TMP_InputField.ContentType.Alphanumeric;
  34. break;
  35. }
  36. }
  37. }
  38. }