ChangeNamePop.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class ChangeNamePop : MonoBehaviour
  7. {
  8. public InputField userNameInput;
  9. public Text nameRemind;
  10. public Image inputKuangImage;
  11. public Button OkBtn;
  12. public Button returnBtn;
  13. public Text nameText;
  14. // Start is called before the first frame update
  15. void Awake()
  16. {
  17. userNameInput.onValueChanged.AddListener(NameValueChanged);
  18. userNameInput.onEndEdit.AddListener(NameEndEdit);
  19. OkBtn.onClick.AddListener(ClickOnOkBtn);
  20. returnBtn.onClick.AddListener(ClickOnCanel);
  21. }
  22. public void Init()
  23. {
  24. userNameInput.text = "";
  25. nameRemind.gameObject.SetActive(false);
  26. ChangeOriginal();
  27. }
  28. private void NameEndEdit(string name)
  29. {
  30. if (name == "" || name.Contains(" "))
  31. {
  32. nameRemind.gameObject.SetActive(true);
  33. nameRemind.text = RtcStrConfig.namenolegal;
  34. ChangeRed();
  35. }
  36. else
  37. {
  38. ChangeOriginal();
  39. }
  40. }
  41. private void NameValueChanged(string name)
  42. {
  43. nameRemind.gameObject.SetActive(false);
  44. ChangeBlue();
  45. }
  46. private void ClickOnCanel()
  47. {
  48. this.gameObject.SetActive(false);
  49. }
  50. private void ClickOnOkBtn()
  51. {
  52. if (userNameInput.text != "" && !nameRemind.gameObject.activeSelf)
  53. {
  54. nameText.text = userNameInput.text;
  55. this.gameObject.SetActive(false);
  56. }
  57. }
  58. public void ChangeOriginal()
  59. {
  60. Color color = Color.white;
  61. color.r = 255 / 255f;
  62. color.g = 255 / 255f;
  63. color.b = 255 / 255f;
  64. color.a = 100 / 255f;
  65. inputKuangImage.color = color;
  66. }
  67. public void ChangeBlue()
  68. {
  69. Color color = Color.white;
  70. color.r = 111 / 255f;
  71. color.g = 168 / 255f;
  72. color.b = 254 / 255f;
  73. color.a = 255 / 255f;
  74. inputKuangImage.color = color;
  75. }
  76. public void ChangeRed()
  77. {
  78. Color color = Color.white;
  79. color.r = 254 / 255f;
  80. color.g = 1 / 255f;
  81. color.b = 7 / 255f;
  82. color.a = 255 / 255f;
  83. inputKuangImage.color = color;
  84. }
  85. }