126 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			126 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| using DG.Tweening;
 | |
| 
 | |
| public class PanelSettings : BasePanel
 | |
| {
 | |
|     [SerializeField] CanvasGroup mCvsBg;
 | |
|     [SerializeField] RectTransform mRctBg;
 | |
| 
 | |
|     [SerializeField] Button mBtnMask;
 | |
|     [SerializeField] Button mBtnClose;
 | |
|     [SerializeField] UIToggleSwap mTglSound;
 | |
|     [SerializeField] UIToggleSwap mTglVibrate;
 | |
|     [SerializeField] Button mBtnRestore;
 | |
|     [SerializeField] Button mBtnPrivacy;
 | |
|     [SerializeField] Button mBtnPolicy;
 | |
| 
 | |
|     [SerializeField] Text mTxtRestore;
 | |
| 
 | |
|     private void Awake()
 | |
|     {
 | |
|         UIUtils.BindBtn(mBtnMask, OnClickClose);
 | |
|         UIUtils.BindBtn(mBtnClose, OnClickClose);
 | |
| 
 | |
|         UIUtils.BindBtn(mBtnRestore, OnClickRestore);
 | |
|         UIUtils.BindBtn(mBtnPrivacy, OnClickPrivacy);
 | |
|         UIUtils.BindBtn(mBtnPolicy, OnClickPolicy);
 | |
|     }
 | |
| 
 | |
|     public override void OnOpen()
 | |
|     {
 | |
|         base.OnOpen();
 | |
| 
 | |
| #if USE_IAP
 | |
|         IAPTool.Instance.OnRestoreDone += SetRestoring;
 | |
| #endif
 | |
| 
 | |
|         mTglSound.OnSwitch += SwitchSound;
 | |
|         mTglVibrate.OnSwitch += SwitchVibrate;
 | |
| 
 | |
|         mTglSound.IsOn = SettingData.Instance.IsSoundOn;
 | |
|         mTglVibrate.IsOn = SettingData.Instance.IsVibrateOn;
 | |
| 
 | |
|         mCvsBg.alpha = 0;
 | |
|         mRctBg.anchoredPosition = new Vector2(0, -160);
 | |
| 
 | |
|         mCvsBg.DOFade(1, 0.3f);
 | |
|         mRctBg.DOAnchorPosY(100, 0.3f);
 | |
| 
 | |
|         SetRestoring();
 | |
| 
 | |
| #if UNITY_EDITOR
 | |
|         mBtnRestore.transform.parent.gameObject.SetActive(true);
 | |
|         mBtnPolicy.gameObject.SetActive(true);
 | |
| #elif IOS_CN || ANDROID_CN || ANDROID_TW
 | |
|         mBtnRestore.transform.parent.gameObject.SetActive(false);
 | |
|         mBtnPolicy.gameObject.SetActive(true);
 | |
| #elif ANDROID_GP
 | |
|         mBtnRestore.transform.parent.gameObject.SetActive(false);
 | |
|         mBtnPolicy.gameObject.SetActive(false);
 | |
| #else
 | |
|         mBtnRestore.transform.parent.gameObject.SetActive(true);
 | |
|         mBtnPolicy.gameObject.SetActive(false);
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     public override void OnClose()
 | |
|     {
 | |
|         base.OnClose();
 | |
| 
 | |
| #if USE_IAP
 | |
|         IAPTool.Instance.OnRestoreDone -= SetRestoring;
 | |
| #endif
 | |
| 
 | |
|         mTglSound.OnSwitch -= SwitchSound;
 | |
|         mTglVibrate.OnSwitch -= SwitchVibrate;
 | |
|     }
 | |
| 
 | |
|     private void SwitchSound(bool pIsOn)
 | |
|     {
 | |
|         SettingData.Instance.IsSoundOn = pIsOn;
 | |
|         AudioManager.Instance.SetSoundOn(pIsOn);
 | |
|     }
 | |
| 
 | |
|     private void SwitchVibrate(bool pIsOn)
 | |
|     {
 | |
|         SettingData.Instance.IsVibrateOn = pIsOn;
 | |
|         VibrateManager.Instance.SetVibrateOn(pIsOn);
 | |
|     }
 | |
| 
 | |
|     private void SetRestoring(bool pResult = false)
 | |
|     {
 | |
| #if USE_IAP
 | |
|         mTxtRestore.text = LanguageConfig.Instance.GetText(IAPTool.Instance.IsRestoring ? "Restoring" : "Restore");
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     private void OnClickClose()
 | |
|     {
 | |
|         mCvsBg.DOFade(0, 0.3f);
 | |
|         mRctBg.DOAnchorPosY(-160, 0.3f).onComplete = Close;
 | |
|     }
 | |
| 
 | |
|     private void OnClickRestore()
 | |
|     {
 | |
| #if USE_IAP
 | |
|         if (IAPTool.Instance.IsRestoring)
 | |
|             return;
 | |
| 
 | |
|         IAPTool.Instance.RestorePurchases();
 | |
|         SetRestoring();
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     private void OnClickPrivacy()
 | |
|     {
 | |
|         TKGSDKManager.Instance.OpenPrivacyURL();
 | |
|     }
 | |
| 
 | |
|     private void OnClickPolicy()
 | |
|     {
 | |
|         TKGSDKManager.Instance.OpenUserTermURL();
 | |
|     }
 | |
| } |