UGUI—InputField

作者:追风剑情 发布于:2021-10-12 15:01 分类:Unity3d

示例 1: 密码输入框

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /// <summary>
  6. /// 密码输入框
  7. /// </summary>
  8. public class PasswordInputField : MonoBehaviour
  9. {
  10. [SerializeField]
  11. private InputField m_InputField;
  12.  
  13. private void Awake()
  14. {
  15. m_InputField.inputType = InputField.InputType.Password;
  16. m_InputField.contentType = InputField.ContentType.Password;
  17. m_InputField.onValidateInput = OnValidateInput;
  18. }
  19.  
  20. // 校验输入字符
  21. private char OnValidateInput(string text, int charIndex, char addedChar)
  22. {
  23. int asciicode = addedChar;
  24.  
  25. //字符 : ASCII码
  26. //_ : 95
  27. //[0-9] : [48-57]
  28. //[A-Z] : [65-90]
  29. //[a-z] : [97-122]
  30.  
  31. //只允许输入: 下划线、数字、大写字母、小写字母
  32. if (asciicode == 95 ||
  33. asciicode >= 48 && asciicode <= 57 ||
  34. asciicode >= 65 && asciicode <= 90 ||
  35. asciicode >= 97 && asciicode <= 122
  36. )
  37. return addedChar;
  38. return '\0';
  39. }
  40. }

11111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号