UserFeedbackController.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. /* 用于管理用户反馈界面和提交
  4. */
  5. public class UserFeedbackController : MonoBehaviour
  6. {
  7. // Start is called once before the first execution of Update after the MonoBehaviour is created
  8. private DropdownField type;
  9. private TextField feedback;
  10. private Button submit, cancel;
  11. private string typeOption0, typeOption1;
  12. void Awake()
  13. {
  14. var root = GetComponent<UIDocument>().rootVisualElement;
  15. type = root.Q<DropdownField>("type");
  16. feedback = root.Q<TextField>("feedback");
  17. submit = root.Q<Button>("submit");
  18. cancel = root.Q<Button>("cancel");
  19. InitSetting();
  20. cancel.RegisterCallback<ClickEvent>(ev => CancelClick());
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. if(feedback.text.Trim() == "")
  26. {
  27. submit.SetEnabled(false);
  28. }
  29. else
  30. {
  31. submit.SetEnabled(true);
  32. }
  33. }
  34. void InitSetting(){
  35. string textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "button", "submit", EnviromentSetting.languageCode });
  36. submit.text = textValue;
  37. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "button", "cancel", EnviromentSetting.languageCode });
  38. cancel.text = textValue;
  39. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "type", EnviromentSetting.languageCode });
  40. type.label = textValue;
  41. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "feedback", EnviromentSetting.languageCode });
  42. feedback.label = textValue;
  43. string typeOption0 = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "option_0", EnviromentSetting.languageCode });
  44. string typeOption1 = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "option_1", EnviromentSetting.languageCode });
  45. type.choices.Clear();
  46. type.choices.Add(typeOption0);
  47. type.choices.Add(typeOption1);
  48. type.value = typeOption0;
  49. }
  50. void CancelClick()
  51. {
  52. HomeSoundEffectController.Instance.PlaySoundEffect(2);
  53. var uiPlaceholder = GameObject.Find("UI Placeholder");
  54. if (uiPlaceholder != null)
  55. {
  56. var FeedbackUI = uiPlaceholder.transform.Find("Feedback").gameObject;
  57. var UserInfoUI = uiPlaceholder.transform.Find("User Info").gameObject;
  58. FeedbackUI.SetActive(false);
  59. UserInfoUI.SetActive(false);
  60. }
  61. }
  62. }