123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using UnityEngine;
- using UnityEngine.UIElements;
- /* 用于管理用户反馈界面和提交
- */
- public class UserFeedbackController : MonoBehaviour
- {
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- private DropdownField type;
- private TextField feedback;
- private Button submit, cancel;
- private string typeOption0, typeOption1;
- void Awake()
- {
- var root = GetComponent<UIDocument>().rootVisualElement;
- type = root.Q<DropdownField>("type");
- feedback = root.Q<TextField>("feedback");
- submit = root.Q<Button>("submit");
- cancel = root.Q<Button>("cancel");
- InitSetting();
- cancel.RegisterCallback<ClickEvent>(ev => CancelClick());
- }
- // Update is called once per frame
- void Update()
- {
- if(feedback.text.Trim() == "")
- {
- submit.SetEnabled(false);
- }
- else
- {
- submit.SetEnabled(true);
- }
- }
- void InitSetting(){
- string textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "button", "submit", EnviromentSetting.languageCode });
- submit.text = textValue;
- textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "button", "cancel", EnviromentSetting.languageCode });
- cancel.text = textValue;
- textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "type", EnviromentSetting.languageCode });
- type.label = textValue;
- textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "feedback", EnviromentSetting.languageCode });
- feedback.label = textValue;
- string typeOption0 = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "option_0", EnviromentSetting.languageCode });
- string typeOption1 = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "FeedbackUI", "label", "option_1", EnviromentSetting.languageCode });
- type.choices.Clear();
- type.choices.Add(typeOption0);
- type.choices.Add(typeOption1);
- type.value = typeOption0;
- }
- void CancelClick()
- {
- HomeSoundEffectController.Instance.PlaySoundEffect(2);
- var uiPlaceholder = GameObject.Find("UI Placeholder");
- if (uiPlaceholder != null)
- {
- var FeedbackUI = uiPlaceholder.transform.Find("Feedback").gameObject;
- var UserInfoUI = uiPlaceholder.transform.Find("User Info").gameObject;
- FeedbackUI.SetActive(false);
- UserInfoUI.SetActive(false);
- }
- }
- }
|