Esempio n. 1
0
 private void OnEnable()
 {
     // Start Iab Service
     if (this.started)
     {
         SoomlaStore.StopIabServiceInBg();
         this.enabledIab = true;
     }
 }
    // 씬 전환시에 IAB 서비스를 종료하고 이벤트를 해제한다.
    void OnDestroy()
    {
                #if UNITY_ANDROID && !UNITY_EDITOR
        SoomlaStore.StopIabServiceInBg();
                #endif

        StoreEvents.OnSoomlaStoreInitialized  -= OnSoomlaStoreInitialized;
        StoreEvents.OnMarketPurchase          -= OnMarketPurchase;
        StoreEvents.OnMarketPurchaseCancelled -= OnMarketPurchaseCancelled;
    }
        /// <summary>
        /// Display the goods screen of the game's store.
        /// </summary>
        void goodsScreen()
        {
            //white background
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), tWhitePixel);
            Color      backupColor     = GUI.color;
            TextAnchor backupAlignment = GUI.skin.label.alignment;
            Font       backupFont      = GUI.skin.label.font;

            GUI.color = Color.red;
            GUI.skin.label.alignment = TextAnchor.UpperLeft;
            GUI.Label(new Rect(10, 10, Screen.width - 10, Screen.height - 10), "SOOMLA Example Store");
            GUI.color = Color.black;
            GUI.skin.label.alignment = TextAnchor.UpperRight;
            string cItemId = StoreInfo.Currencies[0].ItemId;

            GUI.Label(new Rect(10, 10, Screen.width - 40, Screen.height), "" + StoreInventory.GetItemBalance(cItemId));
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUI.skin.label.font      = fTitle;
            GUI.Label(new Rect(0, Screen.height / 8f, Screen.width, Screen.height / 8f), "Virtual Goods");

            GUI.color = backupColor;
            GUI.DrawTexture(new Rect(Screen.width - 30, 10, 30, 30), tMuffins);
            float productSize = Screen.width * 0.30f;
            float totalHeight = StoreInfo.Goods.Count * productSize;

            //Here we start a scrollView, the first rectangle is the position of the scrollView on the screen,
            //the second rectangle is the size of the panel inside the scrollView.
            //All rectangles after this point are relative to the position of the scrollView.
            goodsScrollPosition = GUI.BeginScrollView(new Rect(0, Screen.height * 2f / 8f, Screen.width, Screen.height * 5f / 8f), goodsScrollPosition, new Rect(0, 0, Screen.width, totalHeight));
            float y = 0;

            foreach (VirtualGood vg in StoreInfo.Goods)
            {
                GUI.color = backupColor;
                if (GUI.Button(new Rect(0, y, Screen.width, productSize), "") && !isDragging)
                {
                    Debug.Log("SOOMLA/UNITY wants to buy: " + vg.Name);
                    try {
                        StoreInventory.BuyItem(vg.ItemId);
                    } catch (Exception e) {
                        Debug.LogError("SOOMLA/UNITY " + e.Message);
                    }
                }
                GUI.DrawTexture(new Rect(0, y, Screen.width, productSize), tWhitePixel);
                //We draw a button so we can detect a touch and then draw an image on top of it.
                //TODO
                //Resources.Load(path) The path is the relative path starting from the Resources folder.
                //Make sure the images used for UI, have the textureType GUI. You can change this in the Unity editor.
                GUI.color = backupColor;
                GUI.DrawTexture(new Rect(0 + productSize / 8f, y + productSize / 8f, productSize * 6f / 8f, productSize * 6f / 8f), itemsTextures[vg.ItemId]);
                GUI.color                = Color.black;
                GUI.skin.label.font      = fName;
                GUI.skin.label.alignment = TextAnchor.UpperLeft;
                GUI.Label(new Rect(productSize, y, Screen.width, productSize / 3f), vg.Name);
                GUI.skin.label.font = fDesc;
                GUI.Label(new Rect(productSize + 10f, y + productSize / 3f, Screen.width - productSize - 15f, productSize / 3f), vg.Description);
                //set price
                if (vg.PurchaseType is PurchaseWithVirtualItem)
                {
                    GUI.Label(new Rect(Screen.width / 2f, y + productSize * 2 / 3f, Screen.width, productSize / 3f), "price:" + ((PurchaseWithVirtualItem)vg.PurchaseType).Amount);
                }
                else
                {
                    GUI.Label(new Rect(Screen.width / 2f, y + productSize * 2 / 3f, Screen.width, productSize / 3f), "price:$ " + ((PurchaseWithMarket)vg.PurchaseType).MarketItem.Price.ToString("0.00"));
                }
                GUI.Label(new Rect(Screen.width * 3 / 4f, y + productSize * 2 / 3f, Screen.width, productSize / 3f), "Balance:" + StoreInventory.GetItemBalance(vg.ItemId));

                GUI.skin.label.alignment = TextAnchor.UpperRight;
                GUI.skin.label.font      = fBuy;
                GUI.Label(new Rect(0, y, Screen.width - 10, productSize), "Click to buy");
                GUI.color = Color.grey;
                GUI.DrawTexture(new Rect(0, y + productSize - 1, Screen.width, 1), tWhitePixel);
                y += productSize;
            }
            GUI.EndScrollView();
            //We have just ended the scroll view this means that all the positions are relative top-left corner again.
            GUI.skin.label.alignment = backupAlignment;
            GUI.color           = backupColor;
            GUI.skin.label.font = backupFont;

            float height       = Screen.height / 8f;
            float borderSize   = height / 8f;
            float buttonHeight = height - 2 * borderSize;
            float width        = buttonHeight * 180 / 95;

            if (GUI.Button(new Rect(Screen.width * 2f / 7f - width / 2f, Screen.height * 7f / 8f + borderSize, width, buttonHeight), "back"))
            {
                guiState = GUIState.WELCOME;
#if UNITY_ANDROID && !UNITY_EDITOR
                SoomlaStore.StopIabServiceInBg();
#endif
            }
            GUI.DrawTexture(new Rect(Screen.width * 2f / 7f - width / 2f, Screen.height * 7f / 8f + borderSize, width, buttonHeight), tBack);
            width = buttonHeight * 227 / 94;
            if (GUI.Button(new Rect(Screen.width * 5f / 7f - width / 2f, Screen.height * 7f / 8f + borderSize, width, buttonHeight), "back"))
            {
                guiState = GUIState.PRODUCTS;
            }
            GUI.DrawTexture(new Rect(Screen.width * 5f / 7f - width / 2f, Screen.height * 7f / 8f + borderSize, width, buttonHeight), tGetMore);
        }