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; private string _eventValue; private string _currentPage; private Action _callback; 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"); RushSDKManager.Instance.LogEvent("v_guide_click","entrance",_eventValue); TransferAndroidClass.RequestVpnPermission((res, msg) => { _callback?.Invoke(res, msg); RushSDKManager.Instance.LogEvent("v_auth_success","page",_currentPage); ClosePopup(); LoggerUtils.Debug($"VPN权限请求结果: {res}, 消息: {msg}"); }); } public void ReqVpnCancelBtnClick() { LoggerUtils.Debug("ReqVpnCancelBtnClick"); _currentPage = "v_retetion"; RushSDKManager.Instance.LogEvent("v_retention_view","entrance",_eventValue); _stayObj.gameObject.SetActive(true); } public void StayBtnClick() { LoggerUtils.Debug("StayBtnClick"); RushSDKManager.Instance.LogEvent("v_retention_click","entrance",_eventValue); TransferAndroidClass.RequestVpnPermission((res, msg) => { _callback?.Invoke(res,msg); RushSDKManager.Instance.LogEvent("v_auth_success","page",_currentPage); ClosePopup(); LoggerUtils.Debug($"VPN权限请求结果: {res}, 消息: {msg}"); }); } public void StayCancalBtnClick() { LoggerUtils.Debug("StayCancalBtnClick"); _callback?.Invoke(false,"用户取消授权"); RushSDKManager.Instance.LogEvent("v_retention_close","entrance",_eventValue); ClosePopup(); } public void ShowConnectionRequest(bool afterLoading,int level,Action callback) { if(TransferData.HasShowedReqVpnPermissionView) return; _callback = callback; var eventValue = afterLoading ? "after_loading" : "level_"+level.ToString(); _eventValue = eventValue; _currentPage = "v_guide"; RushSDKManager.Instance.LogEvent("v_guide_view","entrance",eventValue); 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); } } }