• Unity:InputField账号密码输入


    1. using System;
    2. using TMPro;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. public class LoginWindow : MonoBehaviour
    6. {
    7. [SerializeField] private TMP_InputField ipd_user;
    8. [SerializeField] private TMP_InputField ipd_pwd;
    9. [SerializeField] private TextMeshProUGUI txt_errorMessage;
    10. private string username;
    11. private string password;
    12. [SerializeField] private Button btn_Login;
    13. public void Awake()
    14. {
    15. ipd_user.onValidateInput += CheckForEnter;
    16. ipd_pwd.onValidateInput += CheckForEnter;
    17. btn_Login.onClick.AddListener(() =>
    18. {
    19. Login();
    20. });
    21. }
    22. private char CheckForEnter(string text, int charIndex, char addedChar)
    23. {
    24. if (addedChar == '\n')
    25. {
    26. Debug.Log("检测到回车");
    27. Login(false);
    28. return '\0';
    29. }
    30. else
    31. return addedChar;
    32. }
    33. private async void Login(bool sound = true)
    34. {
    35. //if (sound)
    36. // SoundPlay(audioClick);
    37. txt_errorMessage.text = "";
    38. username = ipd_user.text;
    39. password = ipd_pwd.text;
    40. if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
    41. {
    42. txt_errorMessage.text = "用户名或密码不能为空";
    43. }
    44. else
    45. {
    46. var result = await Entrance.instance.Login(username, password);
    47. if (result == null)
    48. txt_errorMessage.text = "请检查网络连接";
    49. else
    50. {
    51. if (result.success)
    52. Back();
    53. else
    54. txt_errorMessage.text = "账号密码错误";
    55. }
    56. }
    57. }
    58. public void Init()
    59. {
    60. txt_errorMessage.text = "";
    61. ipd_user.text = "";
    62. ipd_pwd.text = "";
    63. Show();
    64. }
    65. private void OnDestroy()
    66. {
    67. ipd_user.onValidateInput -= CheckForEnter;
    68. ipd_pwd.onValidateInput -= CheckForEnter;
    69. }
    70. void Back(Action finish = null)
    71. {
    72. //CG.DOFade(0, 0.15f);
    73. /*child1.DOScaleY(0, 0.15f).OnComplete(() =>
    74. {
    75. HideType();
    76. finish?.Invoke();
    77. });*/
    78. }
    79. public void Show()
    80. {
    81. gameObject.SetActive(true);
    82. //CG.alpha = 0;
    83. /*SoundPlay(audioShow);
    84. child1.localScale = new Vector3(1, 0, 1);
    85. //CG.DOFade(1, 0.25f);
    86. child1.DOScaleY(1, 0.25f);*/
    87. }
    88. }

     

  • 相关阅读:
    敏感词过滤--golang
    求logx(c++基础)
    DOPE-FITC在细胞定位、动态追踪等方面的应用-星戈瑞
    我用WebGL打造了一款动态壁纸
    【数据治理】数据治理标准化白皮书 (2021 年)
    数据结构——单链表的实现
    今天的码农女孩学习了关于ajax技术
    2022版:Gitee在Android studio上的使用
    排序【七大排序】
    规范 Git 提交说明
  • 原文地址:https://blog.csdn.net/XYH_78/article/details/126405731