IAP 결제 직후 gameObject를 false 해버리면 나는 문제였다.
IAP 오류error
1)unity iap InvalidOperationException: Collection was modified; enumeration operation may not execute.2)
Purchase not correctly processed for product "상품명". Add an active IAPButton to process this purchase, or add an IAPListener to receive any unhandled purchase events.
UnityEngine.GUI:CallWindowDelegate (UnityEngine.GUI/WindowFunction,int,int,UnityEngine.GUISkin,int,single,single,UnityEngine.GUIStyle)
3)
InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.ThrowHelper.ThrowInvalidOperationException (System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNextRare () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNext () (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.Purchasing.CodelessIAPStoreListener.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at Library/PackageCache/com.unity.purchasing@4.1.3/Runtime/Codeless/CodelessIAPStoreListener.cs:277)
UnityEngine.Purchasing.StoreListenerProxy.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at Library/PackageCache/com.unity.purchasing@4.1.2/Runtime/Purchasing/StoreListenerProxy.cs:34)
UnityEngine.Purchasing.PurchasingManager.ProcessPurchaseIfNew (UnityEngine.Purchasing.Product product) (at Library/PackageCache/com.unity.purchasing@4.1.2/Runtime/Purchasing/PurchasingManager.cs:258)
UnityEngine.Purchasing.PurchasingManager.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionId) (at Library/PackageCache/com.unity.purchasing@4.1.2/Runtime/Purchasing/PurchasingManager.cs:111)
UnityEngine.Purchasing.JSONStore.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionID) (at Library/PackageCache/com.unity.purchasing@4.1.3/Runtime/Stores/BaseStore/JSONStore.cs:165)
UnityEngine.Purchasing.FakeStore.<>n__0 (System.String id, System.String receipt, System.String transactionID) (at <3d94e9c52f184ccd94fd09f24cf14ed2>:0)
UnityEngine.Purchasing.FakeStore+<>c__DisplayClass15_0.<FakePurchase>b__0 (System.Boolean allow, UnityEngine.Purchasing.PurchaseFailureReason failureReason) (at Library/PackageCache/com.unity.purchasing@4.1.3/Runtime/Stores/FakeStore/FakeStore.cs:143)
UnityEngine.Purchasing.UIFakeStore+<>c__DisplayClass10_0`1[T].<StartUI>b__0 (System.Boolean result, System.Int32 codeValue) (at Library/PackageCache/com.unity.purchasing@4.1.3/Runtime/Stores/FakeStore/UIFakeStore.cs:69)
UnityEngine.Purchasing.UIFakeStore.OkayButtonClicked () (at Library/PackageCache/com.unity.purchasing@4.1.3/Runtime/Stores/FakeStore/UIFakeStore.cs:248)
UnityEngine.Purchasing.UIFakeStoreWindow.OnOkClicked () (at Library/PackageCache/com.unity.purchasing@4.1.3/Runtime/Stores/FakeStore/UIFakeStoreWindow.cs:90)
UnityEngine.Purchasing.UIFakeStoreWindow.DoMainGUI (System.Int32 windowID) (at Library/PackageCache/com.unity.purchasing@4.1.3/Runtime/Stores/FakeStore/UIFakeStoreWindow.cs:69)
UnityEngine.GUI.CallWindowDelegate (UnityEngine.GUI+WindowFunction func, System.Int32 id, System.Int32 instanceID, UnityEngine.GUISkin _skin, System.Int32 forceRect, System.Single width, System.Single height, UnityEngine.GUIStyle style) (at <5d9cca3e225d482d8a3c2bc9152ed3be>:0)
정답 ^^ : This was happening because I was deactivating the UI where the IAP button was nested.
To follow my comment above, I found the answer (for me, at least).
This was happening because I was deactivating the UI where the IAP button was nested. Makes sense to deactivate your custom-purchase-confirmation-window (gameObject) when the purchase was completed, right? Well it throws this error.
Solution:
Inside your Purchase Complete and Purchase Failed callbacks (the functions you assign in the inspector), don't deactivate the IAP button (or its parent via hierarchy). Instead, put that deactivate-code into a separate function that you Invoke after 0.1 seconds. This lets the IAP button finish its business before it gets deactivated via the hierarchy.
천재세요 ~
https://answers.unity.com/questions/1476805/iap-button-gives-error-invalidoperationexception-c.html
# 예시파일 이대로 해도 될듯.
using System;
using UnityEngine;
using UnityEngine.Purchasing;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace Samples.Purchasing.Core.BuyingConsumables
{
public class BuyingConsumables : MonoBehaviour, IStoreListener
{
IStoreController m_StoreController; // The Unity Purchasing system.
//Your products IDs. They should match the ids of your products in your store.
public string goldProductId = "com.mycompany.mygame.gold1";
public string diamondProductId = "com.mycompany.mygame.diamond1";
public Text GoldCountText;
public Text DiamondCountText;
int m_GoldCount;
int m_DiamondCount;
void Start()
{
InitializePurchasing();
UpdateUI();
}
void InitializePurchasing()
{
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
//Add products that will be purchasable and indicate its type.
builder.AddProduct(goldProductId, ProductType.Consumable);
builder.AddProduct(diamondProductId, ProductType.Consumable);
UnityPurchasing.Initialize(this, builder);
}
public void BuyGold()
{
m_StoreController.InitiatePurchase(goldProductId);
}
public void BuyDiamond()
{
m_StoreController.InitiatePurchase(diamondProductId);
}
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
Debug.Log("In-App Purchasing successfully initialized");
m_StoreController = controller;
}
public void OnInitializeFailed(InitializationFailureReason error)
{
Debug.Log($"In-App Purchasing initialize failed: {error}");
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
//Retrieve the purchased product
var product = args.purchasedProduct;
//Add the purchased product to the players inventory
if (product.definition.id == goldProductId)
{
AddGold();
}
else if (product.definition.id == diamondProductId)
{
AddDiamond();
}
Debug.Log($"Purchase Complete - Product: {product.definition.id}");
//We return Complete, informing IAP that the processing on our side is done and the transaction can be closed.
return PurchaseProcessingResult.Complete;
}
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
Debug.Log($"Purchase failed - Product: '{product.definition.id}', PurchaseFailureReason: {failureReason}");
}
void AddGold()
{
m_GoldCount++;
UpdateUI();
}
void AddDiamond()
{
m_DiamondCount++;
UpdateUI();
}
void UpdateUI()
{
GoldCountText.text = $"Your Gold: {m_GoldCount}";
DiamondCountText.text = $"Your Diamonds: {m_DiamondCount}";
}
}
}
'DEV > Unity' 카테고리의 다른 글
[solved]is missing the class attribute 'ExtensionOfNativeClass' (0) | 2022.11.30 |
---|---|
Unity 코루틴(coroutine) 관련하여 .. (0) | 2022.07.02 |
vscode 단축키 /// summary shortcut!! (0) | 2022.03.19 |
[Unity] 클릭이 필요없는 Canvas 처리 - Canvas Group (canvas uninteractable/interactable false) (0) | 2022.03.19 |
[solved] Unity Build Error : Access to the path "Library/BuildPlayerData\Editor" is denied. (0) | 2022.03.06 |