예제 #1
0
    /// <summary>
    /// Updates the UI fields for data about the focused character (e.g. name, price).
    /// </summary>
    private void UpdateFocusAreaFields()
    {
        if (m_focusedItem == null)
        {
            return;
        }
        // Get character type of focused item
        int scrollItemIndex = m_focusedItem.ScrollItem.Index;

        // Get character struct
        CharacterResource.CharacterStruct charStruct =
            m_characterResource.GetCharacterStruct((CharacterType)(scrollItemIndex));
        m_characterNameText.SetText(charStruct.Name);
        // Show/hide buttons or text depending on whether character is owned and/or buyable
        if (m_focusedItem.IsOwned)
        {
            // Show play character and share buttons
            m_playCharacterBtn.gameObject.SetActive(true);
            m_charSelectShareBtn.gameObject.SetActive(true);
            // Hide the buy button and locked sprites
            m_buyCharacterBtn.gameObject.SetActive(false);
            m_characterPriceText.SetText("");
            m_lockedCharacterRoot.gameObject.SetActive(false);
            m_shareLockedSprite.gameObject.SetActive(false);
            // Set color of character name text
            m_characterNameText.SetColor(m_ownedCharNameColor);
        }
        else
        {
            // Hide play button
            m_playCharacterBtn.gameObject.SetActive(false);
            // Hide share button and show locked sprite
            m_charSelectShareBtn.gameObject.SetActive(false);
            m_shareLockedSprite.gameObject.SetActive(true);
            // Set color of character name text
            m_characterNameText.SetColor(m_unownedCharNameColor);

            // Show/hide buy button and locked sprite depending on whether character is buyable
            m_buyCharacterBtn.gameObject.SetActive(charStruct.IsBuyable);
            m_lockedCharacterRoot.gameObject.SetActive(!charStruct.IsBuyable);

            // If buyable, show character price. Else, leave price text empty.
            // TODO: Format price with the proper currency
            m_characterPriceText.SetText(charStruct.IsBuyable ?
                                         "$" + charStruct.Price.ToString("0.00") :
                                         "");
        }
    }
    /// <summary>
    /// Initializes this instance.
    /// </summary>
    public void Initialize(CharacterResource charResource,
                           Action <string> charPurchaseSucceededDelegate,
                           Action <string> charPurchaseCancelledDelegate,
                           Action restoreTransactionsCompletedDelegate,
                           Action restoreTransactionsFailedDelegate,
                           Action <int> coinBalanceChangedDelegate,
                           Action <int> gachaBalanceChangedDelegate)
    {
        // Initialize only once
        if (m_isInitialized)
        {
            return;
        }

        // Set up character data in Soomla's StoreAssets
        CRCAssets.CharactersLTVGArray = new EquippableVG[charResource.CharacterCount];
        m_charItemIDDictionary.Clear();
        // For testing: Index used for assigning test product IDs
        //int testIDIndex = 0;
        for (int index = 0; index < charResource.CharacterCount; ++index)
        {
            CharacterType character = (CharacterType)index;
            CharacterResource.CharacterStruct charData = charResource.GetCharacterStruct(character);

            // Check if character is buyable
            PurchaseType purchaseType = new PurchaseWithMarket(charData.ItemID, charData.Price);

            /*
             * // For testing: Use test product IDs for the first four purchasable characters
             * PurchaseType purchaseType = null;
             * string productID = charData.ItemID;
             * if (charData.IsBuyable)
             * {
             *  if (testIDIndex == 0)       productID = CRCAssets.PURCHASED_TEST_ID;
             *  else if (testIDIndex == 1)  productID = CRCAssets.CANCELED_TEST_ID;
             *  else if (testIDIndex == 2)  productID = CRCAssets.REFUNDED_TEST_ID;
             *  else if (testIDIndex == 3)  productID = CRCAssets.UNAVAILABLE_TEST_ID;
             *  testIDIndex++;
             * }
             * purchaseType = new PurchaseWithMarket(productID, charData.Price);
             * //purchaseType = new PurchaseWithMarket(CRCAssets.PURCHASED_TEST_ID, charData.Price);
             */

            // Create equippable virtual good instance for each character
            CRCAssets.CharactersLTVGArray[index] = new EquippableVG(
                EquippableVG.EquippingModel.CATEGORY,
                charData.Name,
                "",
                charData.ItemID,
                purchaseType);

            // Add the item ID and character type to a dictionary
            if (!m_charItemIDDictionary.ContainsKey(charData.ItemID))
            {
                m_charItemIDDictionary.Add(charData.ItemID, character);
            }
        }

        // Create an instance of the in-game implementation of IStoreAssets
        CRCAssets crcAssets = new CRCAssets();

        // Update the list of character goods
        for (int index = 0; index < charResource.CharacterCount; ++index)
        {
            crcAssets.AddToCharacterGoodsList(CRCAssets.CharactersLTVGArray[index]);
        }
        // Finalize character goods collections before initializing Soomla Store
        crcAssets.FinalizeCharacterGoods();

        // Save delegates
        m_charPurchaseSucceededDelegate        = charPurchaseSucceededDelegate;
        m_charPurchaseCancelledDelegate        = charPurchaseCancelledDelegate;
        m_restoreTransactionsCompletedDelegate = restoreTransactionsCompletedDelegate;
        m_restoreTransactionsFailedDelegate    = restoreTransactionsFailedDelegate;
        m_coinBalanceChangedDelegate           = coinBalanceChangedDelegate;
        m_gachaBalanceChangedDelegate          = gachaBalanceChangedDelegate;

        // Subscribe to Store events
        StoreEvents.OnSoomlaStoreInitialized      += OnSoomlaStoreInitialized;
        StoreEvents.OnCurrencyBalanceChanged      += OnCurrencyBalanceChanged;
        StoreEvents.OnMarketPurchaseStarted       += OnMarketPurchaseStarted;
        StoreEvents.OnMarketPurchase              += OnMarketPurchase;
        StoreEvents.OnMarketPurchaseCancelled     += OnMarketPurchaseCancelled;
        StoreEvents.OnMarketRefund                += OnMarketRefund;
        StoreEvents.OnRestoreTransactionsStarted  += OnRestoreTransactionsStarted;
        StoreEvents.OnRestoreTransactionsFinished += OnRestoreTransactionsFinished;
        StoreEvents.OnUnexpectedStoreError        += OnUnexpectedStoreError;

        // Initialize rewards
        m_firstLaunchReward = new VirtualItemReward(
            "first-launch",
            "Give coins at first launch",
            CRCAssets.COIN_CURRENCY_ITEM_ID,
            FIRST_LAUNCH_REWARD_AMOUNT);

        // Initialize the store with the in-game implementation of IStoreAssets
        // Note: This must be done after setting up values in the store assets class
        SoomlaStore.Initialize(crcAssets);
    }