/** * This method is invoked when we initialize the billing on device. */ static void BillingUnityEditor_BuyProductWithSimulatedBilling(ProductInfo product, System.Action <bool, string, Shop.BuyResponse> callback) { if (product == null) { Debug.LogError("Error product was null - cannot puchase"); } if (instance == null) { Debug.LogError("Error singleton instance is null"); } if (instance.editorBillingUI == null) { if (instance.billingSimulatorUIPrefab == null) { Debug.LogError("Error prefab is null editorBillingUIPrefab", instance.gameObject); } var goBillingSimulator = ((GameObject)GameObject.Instantiate(instance.billingSimulatorUIPrefab)); if (goBillingSimulator == null) { Debug.LogError("Error instanciating prefab of simulated billing UI"); } if (instance.canvas == null) { Debug.LogWarning("MobyShop: Warning: Canvas was null, we're autocreating one but please setup a UI canvas in the project"); instance.canvas = CanvasHelper.GetCanvas(); } if (instance.canvas == null) { Debug.LogError("MobyShop: Error no instance of the canvas set"); } goBillingSimulator.transform.SetParent(instance.canvas.transform); var rt = goBillingSimulator.GetComponent <RectTransform> (); if (rt == null) { Debug.LogError("Error the RectTransform component was not found on the Billing UI object."); } rt.FitAnchorsToCorners(); instance.editorBillingUI = goBillingSimulator.GetComponent <SimulatedBillingUI>(); if (instance.editorBillingUI == null) { Debug.LogError("MobyShop: Error cannot show billing simulator UI becaurse no instance is set."); } } if (BillingSimulator.instance == null) { MobyShop.Shop.Instance.gameObject.AddComponent <BillingSimulator> (); } if (BillingSimulator.instance == null) { Debug.LogError("MobyShop: Error - instance of billing simulator is not present and could NOT create instance."); } BillingSimulator.instance.billingSimulatorUI = instance.editorBillingUI; BillingSimulator.BuyProduct(product.BillingId, (bool _ok, string _m) => { if (_ok) { CallUnlockProduct(BoughtOrRestored.Bought, product); } else { } callback(_ok, _m, _ok ? Shop.BuyResponse.Ok : Shop.BuyResponse.Failed); }); }
/** * Sets up all infomration used to do native billing. */ void Awake() { if (Application.isEditor && this.gameObject.GetComponent <BillingSimulator>() == null) { this.gameObject.AddComponent <BillingSimulator>(); } DontDestroyOnLoad(this.gameObject); inst = this; if (initializing == true) { throw new System.Exception("MobyShop: Cannot initialize twice."); } initializing = true; #if !UNITY_EDITOR Debug.Log("MobyShop: Init"); Debug.Log("MobyShop: Base64 License Code : " + AndroidPurchaseLicenseBase64); Debug.Log("MobyShop: ProductId List ( Unlockables )" + string.Join(",", ProductIdsOfUnlockables)); Debug.Log("MobyShop: ProductId List ( Consumeables ) " + string.Join(",", ProductIdsOfConsumeables)); Debug.Log("MobyShop: this.Object " + this.gameObject.name); #endif initialized = false; if (Application.isEditor || ShopConfig.instance.SimulateBillingOnDevice) { BillingSimulator.Init(( bool ok ) => { if (MobyShop.Shop.Verbose) { Debug.Log("MobyShop: Initialized Billing simulator"); } }); return; } #if UNITY_IOS BillingiOS.Billing_Init(inst.name, string.Join(",", ProductBillingIdListForRealProducts), NativeCallback.Create(( Hashtable res ) => { initializing = false; bool ok = res.ContainsKey("ok") ? System.Convert.ToBoolean(res["ok"]) : false; string msg = res.ContainsKey("msg") ? System.Convert.ToString(res["msg"]) : ""; Debug.Log("MobyShop: Store Init Done; ok=" + ok + " msg = '" + msg + "'"); if (ok) { initialized = true; } else { } })); initializing = false; initialized = true; #elif UNITY_ANDROID initializing = true; BillingAndroid.Init( AndroidPurchaseLicenseBase64, ProductIdsOfUnlockables, ProductIdsOfConsumeables, this.gameObject.name, NativeCallback.Create(( Hashtable res ) => { initializing = false; bool ok = res.ContainsKey("ok") ? System.Convert.ToBoolean(res["ok"]) : false; string msg = res.ContainsKey("msg") ? System.Convert.ToString(res["msg"]) : ""; Debug.Log("MobyShop: Store Init Done; ok=" + ok + " msg = '" + msg + "'"); if (ok) { initialized = true; } else { } }) ); #else UnsupportedPlatform(); #endif }
/** * Support recompile in Editor. */ void Update() { inst = this; }
/** * */ void Awake() { inst = this; }
/** * Private constructor. */ BillingSimulator() : base() { inst = this; }
/** * ensure the instance is set. */ public void EnsureInst() { inst = this; }