using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace WZ { public class VPNGuideManager : MonoBehaviour { public GameObject _stayObj; private GameObject _contentReqPrefab; public GameObject _currentReqPopup; public Button _reqVpnBtn; public Button _reqCancelBtn; public Button _boostBtn; public Button _boostCancelBtn; public void Awake() { _reqVpnBtn.onClick.AddListener(ReqVpnBtnClick); _reqCancelBtn.onClick.AddListener(ReqVpnCancelBtnClick); _boostBtn.onClick.AddListener(StayBtnClick); _boostCancelBtn.onClick.AddListener(StayCancalBtnClick); } public void ReqVpnBtnClick() { LoggerUtils.Debug("ReqVpnBtnClick"); TransferAndroidClass.RequestVpnPermission((res, msg) => { TransferData.HasReqVpnPermission = true; ClosePopup(); LoggerUtils.Debug($"VPN权限请求结果: {res}, 消息: {msg}"); }); } public void ReqVpnCancelBtnClick() { LoggerUtils.Debug("ReqVpnCancelBtnClick"); _stayObj.gameObject.SetActive(true); } public void StayBtnClick() { LoggerUtils.Debug("StayBtnClick"); TransferAndroidClass.RequestVpnPermission((res, msg) => { TransferData.HasReqVpnPermission = true; ClosePopup(); LoggerUtils.Debug($"VPN权限请求结果: {res}, 消息: {msg}"); }); } public void StayCancalBtnClick() { LoggerUtils.Debug("StayCancalBtnClick"); ClosePopup(); } public void ShowConnectionRequest(Action onConfirm = null) { if(TransferData.HasShowedReqVpnPermissionView) return; LoggerUtils.Debug("ShowConnectionRequest"); TransferData.HasShowedReqVpnPermissionView = true; _contentReqPrefab = Resources.Load("Prefabs/PermissionRequest"); if (_contentReqPrefab == null) { LoggerUtils.Error("_contentReqPrefab not found in Resources/Prefabs/"); return; } _currentReqPopup = Instantiate(_contentReqPrefab); } public void ClosePopup() { if (_currentReqPopup != null) { Destroy(_currentReqPopup); _currentReqPopup = null; } _reqVpnBtn.onClick.RemoveListener(ReqVpnBtnClick); _reqCancelBtn.onClick.RemoveListener(ReqVpnCancelBtnClick); _boostBtn.onClick.RemoveListener(StayBtnClick); _boostCancelBtn.onClick.RemoveListener(StayCancalBtnClick); } void OnDestroy() { if (_currentReqPopup != null) { Destroy(_currentReqPopup); } _reqVpnBtn.onClick.RemoveListener(ReqVpnBtnClick); _reqCancelBtn.onClick.RemoveListener(ReqVpnCancelBtnClick); _boostBtn.onClick.RemoveListener(StayBtnClick); _boostCancelBtn.onClick.RemoveListener(StayCancalBtnClick); } } }