using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using Kill.Managers; using Kill.Network; using Kill.UI.Components; using Unity.VisualScripting; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; namespace Kill.UI.Pages { public class FeedbackPage : MonoBehaviour { public enum FeedbackType { TechnicalIssue, ProductSuggestion, UseConsultation, OtherIssues } public Button[] issueTypeButtons; public InputField issueInput; public Text textLimit; public Text screenShotLimit; FeedbackType feedbackType; Action callback; public Button back; public void Init(Action callback) { feedbackType = FeedbackType.OtherIssues; ChooseType(0); issueInput.text = ""; this.callback=callback; back.onClick.RemoveAllListeners(); back.onClick.AddListener(Back); UIManager.Instance.RegisterBackAction(Back); } public void Back() { callback?.Invoke(); Destroy(gameObject); } private Texture2D selectedImage; List selectedImageList = new List(); public void ChooseType(int index) { feedbackType = (FeedbackType)index; for (int i = 0; i < issueTypeButtons.Length; i++) { if (i == index) { issueTypeButtons[i].interactable = false; issueTypeButtons[i].transform.Find("选中").gameObject.SetActive(true); } else { issueTypeButtons[i].interactable = true; issueTypeButtons[i].transform.Find("选中").gameObject.SetActive(false); } } } public void OnTextValueChanged(String text) { textLimit.text=text.Length+"/300"; } public void SelectPhotoFromGallery() { #if UNITY_EDITOR // 在编辑器中测试时,加载一个默认图片 string testImagePath = UnityEditor.EditorUtility.OpenFilePanel("Select Image", "", "jpg,png,jpeg"); if (!string.IsNullOrEmpty(testImagePath)) { byte[] fileData = File.ReadAllBytes(testImagePath); selectedImage = new Texture2D(2, 2); selectedImage.LoadImage(fileData); ShowSelectImage(); } #else // 使用NativeGallery插件从相册选择图片 bool permission = NativeGallery.CheckPermission(NativeGallery.PermissionType.Read, NativeGallery.MediaType.Image); if (permission) { PickImage(); } else { NativeGallery.RequestPermissionAsync((perm) => { if (perm == NativeGallery.Permission.Granted) { PickImage(); } else { Debug.LogWarning("没有获得相册访问权限"); } }, NativeGallery.PermissionType.Read, NativeGallery.MediaType.Image); } #endif } private void PickImage() { NativeGallery.GetImageFromGallery((path) => { if (path != null) { // 加载选中的图片,并确保纹理是可读的 selectedImage = NativeGallery.LoadImageAtPath(path, -1, false); // 设置 markTextureNonReadable 为 false if (selectedImage != null) { ShowSelectImage(); } else { Debug.LogError("无法加载选定的图片"); } } }, ""); } public GameObject selectImagePrefab; public Transform imageParent; public List selectImageObjs; public GameObject addImageButton; public void ShowSelectImage() { GameObject i=Instantiate(selectImagePrefab,imageParent); i.GetComponent().texture = selectedImage; i.GetComponentInChildren