modify scripts
This commit is contained in:
@ -11,14 +11,9 @@
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using WordsToolkit.Scripts.Audio;
|
||||
using WordsToolkit.Scripts.Data;
|
||||
using WordsToolkit.Scripts.Enums;
|
||||
using WordsToolkit.Scripts.GUI;
|
||||
using WordsToolkit.Scripts.GUI.Labels;
|
||||
using WordsToolkit.Scripts.Services;
|
||||
using WordsToolkit.Scripts.Services.IAP;
|
||||
using WordsToolkit.Scripts.Settings;
|
||||
using WordsToolkit.Scripts.System;
|
||||
@ -31,6 +26,8 @@ namespace WordsToolkit.Scripts.Popups
|
||||
private CoinsShopSettings shopSettings;
|
||||
public ProductID noAdsProduct;
|
||||
[SerializeField]
|
||||
public TextMeshProUGUI noAdsPriceText;
|
||||
[SerializeField]
|
||||
private AudioClip coinsSound;
|
||||
|
||||
private void OnEnable()
|
||||
@ -49,11 +46,14 @@ namespace WordsToolkit.Scripts.Popups
|
||||
}
|
||||
|
||||
EventManager.GetEvent<string>(EGameEvent.PurchaseSucceeded).Subscribe(PurchaseSucceded);
|
||||
EventManager.GetEvent<(string, string)>(EGameEvent.PurchaseFailed).Subscribe(PurchaseFailed);
|
||||
|
||||
// Update NoAds price display
|
||||
UpdateNoAdsPriceDisplay();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
EventManager.GetEvent<string>(EGameEvent.PurchaseSucceeded).Unsubscribe(PurchaseSucceded);
|
||||
}
|
||||
|
||||
@ -86,44 +86,6 @@ namespace WordsToolkit.Scripts.Popups
|
||||
}
|
||||
}
|
||||
|
||||
private void PurchaseFailed((string, string) info)
|
||||
{
|
||||
var productId = info.Item1;
|
||||
var errorMessage = info.Item2;
|
||||
|
||||
var errorType = IAPErrorHelper.ParseError(errorMessage);
|
||||
Debug.LogWarning($"Purchase failed for product {productId}: {errorMessage}, Error Type: {errorType}");
|
||||
|
||||
switch (errorType)
|
||||
{
|
||||
case IAPErrorType.InvalidProductID:
|
||||
Debug.LogError($"Invalid product ID: {productId}");
|
||||
ShowErrorMessage("Invalid product ID. Please try again later.");
|
||||
break;
|
||||
case IAPErrorType.UserCancelled:
|
||||
Debug.LogWarning("Purchase cancelled by user.");
|
||||
break;
|
||||
case IAPErrorType.DuplicateTransaction:
|
||||
Debug.LogWarning($"Duplicate transaction for product {productId}. This usually means the purchase was already completed.");
|
||||
break;
|
||||
case IAPErrorType.IAPInitFailed:
|
||||
Debug.LogError("IAP initialization failed. Please check your IAP settings.");
|
||||
ShowErrorMessage("IAP initialization failed. Please try again later.");
|
||||
break;
|
||||
default:
|
||||
ShowErrorMessage($"Payment failed: {errorMessage}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void ShowErrorMessage(string message)
|
||||
{
|
||||
var popup = menuManager.ShowPopup<MessagePopup>();
|
||||
if (popup != null)
|
||||
{
|
||||
popup.SetMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void BuyCoins(string id)
|
||||
{
|
||||
// StopInteration();
|
||||
@ -133,5 +95,17 @@ namespace WordsToolkit.Scripts.Popups
|
||||
iapManager.BuyProduct(id);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void UpdateNoAdsPriceDisplay()
|
||||
{
|
||||
if (noAdsPriceText != null && noAdsProduct != null)
|
||||
{
|
||||
var localizedPrice = iapManager.GetProductLocalizedPriceString(noAdsProduct.ID);
|
||||
if (!string.IsNullOrEmpty(localizedPrice))
|
||||
{
|
||||
noAdsPriceText.text = localizedPrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user