예제 #1
0
        public OpenIABClient(Options options)
        {
            WriteLog("initializing client...");
            WriteLog("options.checkInventoryTimeoutMs: {0}", options.checkInventoryTimeoutMs);
            WriteLog("options.discoveryTimeoutMs: {0}", options.discoveryTimeoutMs);
            WriteLog("options.verifyMode: {0}", options.verifyMode);
            WriteLog("options.prefferedStoreNames: {0}", string.Join(", ", options.prefferedStoreNames));
            WriteLog("options.storeKeys: {0}", string.Join(", ", options.storeKeys.Select(i => string.Format("{0}:{1}", i.Key, i.Value.Substring(0, 10) + "...")).ToArray()));

            _options = options;

            WriteLog("subscribing events...");

            if (UnityEngine.Object.FindObjectOfType <OpenIABEventManager>() == null)
            {
                throw new Exception("OpenIABEventManager component missed, please add it to game scene");
            }

            OpenIABEventManager.billingSupportedEvent        += BillingSupportedEvent;
            OpenIABEventManager.queryInventorySucceededEvent += QueryInventorySucceededEvent;

            OpenIABEventManager.purchaseSucceededEvent        += purchase => CompleteTask(Purchased, "purchaseSucceededEvent", purchase);
            OpenIABEventManager.consumePurchaseSucceededEvent += purchase => CompleteTask(Consumed, "consumePurchaseSucceededEvent", purchase);
            OpenIABEventManager.transactionRestoredEvent      += sku => CompleteTask(Restored, "transactionRestoredEvent", sku);
            OpenIABEventManager.restoreSucceededEvent         += () => CompleteTask(RestoreCompleted, "restoreSucceededEvent");

            OpenIABEventManager.billingNotSupportedEvent   += error => { CompleteTask(Failed, "billingNotSupportedEvent", error); _state = State.Unknown; };
            OpenIABEventManager.queryInventoryFailedEvent  += error => CompleteTask(Failed, "queryInventoryFailedEvent", error);
            OpenIABEventManager.purchaseFailedEvent        += (number, error) => CompleteTask(Failed, "purchaseFailedEvent", error);
            OpenIABEventManager.consumePurchaseFailedEvent += error => CompleteTask(Failed, "consumePurchaseFailedEvent", error);
            OpenIABEventManager.restoreFailedEvent         += error => CompleteTask(Failed, "restoreFailedEvent", error);

            #if !UNITY_EDITOR
            OpenIAB.enableDebugLogging(true);
            #endif
        }