예제 #1
0
        //initialize IAPs, billing systems and database,
        //as well as shop components in this order
        void Awake()
        {
            //make sure we keep one instance of this script in the game
            if (instance)
            {
                Destroy(gameObject);
                return;
            }
            DontDestroyOnLoad(this);
            isDebug = Debug.isDebugBuild;

            //set static reference
            instance = this;
            DBManager dbManager = GetComponent <DBManager>();

            validator = GetComponent <ReceiptValidator>();

            #if PLAYFAB
            playfabManager = null;
            GameObject playfabGO = GameObject.Find("PlayfabManager");
            if (!playfabGO)
            {
                Debug.LogWarning("IAPManager: Playfab is enabled, but could not find PlayfabManager prefab. Have you placed it in the first scene "
                                 + "of your app and started from there? Instantiating temporary copy...");
                playfabGO = Instantiate(Resources.Load("PlayfabManager", typeof(GameObject))) as GameObject;
                //remove clone tag from its name. not necessary, but nice to have
                playfabGO.name = playfabGO.name.Replace("(Clone)", "");
            }

            playfabManager = playfabGO.GetComponent <PlayfabManager>();
            if (validator == null)
            {
                validator = gameObject.AddComponent <ReceiptValidatorService>();
            }

                #if !PLAYFAB_VALIDATION
            dbManager.memoryOnly = true;
            if (isDebug)
            {
                Debug.Log("PlayFab (online mode) is enabled: IAP data will not be saved on devices.");
            }
                #endif
            #endif

            //populate IAP dictionary and arrays with product ids
            SceneManager.sceneLoaded += OnSceneWasLoaded;
            dbManager.Init();
            InitIds();

            //do not self-initialize when using PlayFab services (full):
            //wait for its login callback for querying store later
            #if PLAYFAB && !PLAYFAB_VALIDATION
            return;
            #endif

            Initialize();
        }
예제 #2
0
        #pragma warning restore 0414

        // initialize IAPs, billing systems and database,
        // as well as shop components in this order
        void Awake()
        {
            //make sure we keep one instance of this script in the game
            if (instance)
            {
                Destroy(gameObject);
                return;
            }
            DontDestroyOnLoad(this);
            isDebug = Debug.isDebugBuild;

            //set static reference
            instance = this;
            //populate IAP dictionary and arrays with product ids
            InitIds();

            var module  = StandardPurchasingModule.Instance();
            var builder = ConfigurationBuilder.Instance(module);

            RequestProductData(builder);

            builder.Configure <IGooglePlayConfiguration>().SetPublicKey(googleStoreKey);
            if (isDebug)
            {
                builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = true;
                // Write out our Amazon Sandbox JSON file.
                // This has no effect when the Amazon billing service is not in use.
                builder.Configure <IAmazonConfiguration>().WriteSandboxJSON(builder.products);
            }

            // Now we're ready to initialize Unity IAP.
            UnityPurchasing.Initialize(this, builder);

            //initialize database, remote and shop managers
            GetComponent <IAPListener>().Init();
            GetComponent <DBManager>().Init();
            StartCoroutine(RemoteDownload());
            validator = GetComponent <ReceiptValidator>();
            OnLevelWasLoaded(-1);
        }