modify scripts

This commit is contained in:
2025-10-17 09:14:59 +08:00
parent 0da10d3e7c
commit 9336ed0d6f
20 changed files with 778 additions and 24 deletions

View File

@ -49,6 +49,7 @@ namespace WordsToolkit.Scripts.Popups
}
EventManager.GetEvent<string>(EGameEvent.PurchaseSucceeded).Subscribe(PurchaseSucceded);
EventManager.GetEvent<(string, string)>(EGameEvent.PurchaseFailed).Subscribe(PurchaseFailed);
}
private void OnDisable()
@ -85,6 +86,44 @@ 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();