Ejemplo n.º 1
0
        private void InitializeProducts()
        {
            // Create ApprienProducts from the IAP or subscription Catalog
            var catalogFile = Resources.Load <TextAsset>(_currentTab == TabType.IAPs ? "ApprienIAPProductCatalog" : "ApprienSubscriptionProductCatalog");
            var catalog     = ProductCatalog.FromTextAsset(catalogFile);

            _apprienProducts = ApprienProduct.FromIAPCatalog(catalog);

            // Initialize Unity IAP configuration builder
            _builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

            // Platform specific integration type for the manager.
            ApprienIntegrationType integrationType;

#if UNITY_IOS
            integrationType = ApprienIntegrationType.AppleAppStore;
#else
            integrationType = ApprienIntegrationType.GooglePlayStore;
#endif

            // Package name. Usually Application.identifier
            var packageName = Application.identifier;

            _apprienManager = new ApprienManager(
                Application.identifier,
                integrationType,
                ApprienConnection.Token
                );

            // Add standard IAP ids, so that there is always a fallback if Apprien variants cannot be fetched
            foreach (var product in _apprienProducts)
            {
                _builder.AddProduct(product.BaseIAPId, product.ProductType);
            }

            FetchPrices();
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            // Display the Inspector properties defined in the ApprienConnection ScriptableObject, i.e. the token
            DrawDefaultInspector();

            if (_apprienConnection.stringValue.Length == 0)
            {
                EditorGUILayout.HelpBox("Provide the authentication token into the field above before testing the connection. You should see a list of all products loaded into Apprien for the game.", MessageType.Info);
                return;
            }

            if (_apprienManager == null)
            {
                EditorGUILayout.HelpBox("The assembly containing this editor script was recompiled. Please deselect and reselect the asset.", MessageType.Error);
                return;
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("API Integration", EditorStyles.boldLabel);

            if (GUILayout.Button("Test Connection"))
            {
                _connectionCheckPressed = false;
                _fetchingStatus         = true;

                // Refresh the token to the manager before testing connection
                var token = _apprienConnection.stringValue;
                _apprienManager.Token = token;

                _initializeFetch = TestConnection((available, valid) =>
                {
                    _fetchingStatus         = false;
                    _connectionCheckPressed = true;
                    _connectionOK           = available;
                    _tokenOK = valid;
                });
            }

            EditorGUILayout.LabelField("Status:");
            if (_fetchingStatus)
            {
                EditorGUILayout.LabelField("  Loading...");
            }

            if (_connectionCheckPressed)
            {
                // Display connection information
                EditorGUILayout.LabelField(_connectionOK ?
                                           "  Apprien API connection is OK." :
                                           "  Apprien API connection failed.");

                EditorGUILayout.LabelField(_tokenOK ?
                                           "  Apprien Token is OK" :
                                           "  Apprien Token is invalid.");
            }

            EditorGUI.BeginDisabledGroup(_connectionOK == false || _tokenOK == false);
            EditorGUILayout.HelpBox("After testing the connection, click below to fetch all Apprien generated IAP variants for products defined in the default IAP Catalog. Make sure the correct package name is set in Player settings, i.e. your com.company.product identifier.", MessageType.Info);

            // Enable after active/inactive products are supported in Apprien
            //_onlyActiveProducts = EditorGUILayout.ToggleLeft("Fetch only active products", _onlyActiveProducts);

            _catalogResourceName = EditorGUILayout.TextField("Catalog resource name", _catalogResourceName);

            if (GUILayout.Button("Test fetching Apprien-generated products"))
            {
                _fetchingProducts = true;
                _fetchedProducts.Clear();

                var catalogFile = Resources.Load <TextAsset>(_catalogResourceName);
                if (catalogFile != null)
                {
                    // catalog file exists
                    var catalog  = ProductCatalog.FromTextAsset(catalogFile);
                    var products = ApprienProduct.FromIAPCatalog(catalog);

                    if (products.Length == 0)
                    {
                        _anyProducts = false;
                    }
                    else
                    {
                        _anyProducts = true;
                        _pricesFetch = _apprienManager.FetchApprienPrices(products, () =>
                        {
                            _fetchingProducts = false;
                            _fetchedProducts  = products.ToList();
                        });
                    }
                }
                else
                {
                    _anyProducts = false;
                }
            }

            if (!_anyProducts)
            {
                // catalog file does not exist
                EditorGUILayout.LabelField("Could not load catalog file: " + _catalogResourceName);
                return;
            }

            EditorGUILayout.LabelField("Products:");

            if (_fetchingProducts)
            {
                EditorGUILayout.LabelField("  Loading...");
            }
            else
            {
                foreach (var product in _fetchedProducts)
                {
                    EditorGUILayout.LabelField("  Base Product ID: " + product.BaseIAPId);
                    EditorGUILayout.LabelField("  Apprien variant ID: " + product.ApprienVariantIAPId);
                    EditorGUILayout.Space();
                }
            }

            EditorGUI.EndDisabledGroup();
        }