/// Wait for ChilliConnect to download the catalogue and then display /// it to the user. /// private void Update() { if (m_currentState == State.FETCHING_ITEMS) { if (IAPSystem.Get().IsInitialised()) { PopulateCatalogue(IAPSystem.Get().GetAvailableItems()); } } }
/// Pressing on a catalogue item will hide the purchase menu and /// start the process of purchasing the item /// /// @param item /// Definition of the item to purchase /// private void OnCatalogueItemSelected(IAPSystem.Item item) { Debug.Assert(m_currentState == State.READY_TO_PURCHASE); m_currentState = State.PURCHASING; //Hide the Catalogue so that no more purchases can be made m_canvasGroup.interactable = false; m_canvasGroup.alpha = 0.0f; IAPSystem.Get().Purchase(item); }
/// Uses the available items from the IAP system and displays /// each one as an UI element in the catalogue. If none displays that the store is empty /// /// @param items /// Available items - could be empty if not configured on dashboard or network issues /// private void PopulateCatalogue(ReadOnlyCollection <IAPSystem.Item> items) { Debug.Assert(m_currentState == State.FETCHING_ITEMS); GameObject catalogueElement = Resources.Load <GameObject>(k_catalogueElementPrefabPath); foreach (var item in items) { var capturedItem = item; GameObject uiElement = (GameObject)GameObject.Instantiate(catalogueElement, Vector3.zero, Quaternion.identity); uiElement.transform.SetParent(transform); uiElement.transform.localScale = Vector3.one; uiElement.name = capturedItem.ProductId; uiElement.transform.Find("Name").GetComponent <Text>().text = capturedItem.Name; uiElement.transform.Find("Cost").GetComponent <Text>().text = capturedItem.LocalisedPrice; uiElement.GetComponent <Button>().onClick.AddListener(() => OnCatalogueItemSelected(capturedItem)); } IAPSystem.Get().OnPurchaseCompleteEvent += OnPurchaseComplete; IAPSystem.Get().OnPurchaseFailedEvent += OnPurchaseFailed; m_currentState = State.READY_TO_PURCHASE; }
/// public IAPSystem() { s_singletonInstance = this; }