Наследование: PlayFabRequestCommon
		void OnGUI () {
			if(renderCatalog){
				Rect marketIconRect = new Rect (iconsSpace,Screen.height-marketIcon.height-iconsSpace,marketIcon.width,marketIcon.height );
				if (GUI.Button (marketIconRect, marketIcon,GUIStyle.none)) {
					showMenu = !showMenu;
					Time.timeScale = !showMenu ? 1.0f : 0.0f;
				};
				drawCursor = false;
				if (Input.mousePosition.x < marketIconRect.x + marketIconRect.width && Input.mousePosition.x > marketIconRect.x && Screen.height - Input.mousePosition.y < marketIconRect.y + marketIconRect.height && Screen.height - Input.mousePosition.y > marketIconRect.y)
				{
					drawCursor = true;
				}

				if (showMenu) {
					PlayFabGameBridge.mouseOverGui = true;
					Rect winRect = new Rect (Screen.width * 0.5f - (marketMenu.width+90) *0.5f,100,marketMenu.width+90,marketMenu.height );
					GUI.DrawTexture (winRect, marketMenu);
					if (Input.mousePosition.x < winRect.x + winRect.width && Input.mousePosition.x > winRect.x && Screen.height - Input.mousePosition.y < winRect.y + winRect.height && Screen.height - Input.mousePosition.y > winRect.y)
						drawCursor = true;

					Rect closeRect = new Rect (winRect.x+winRect.width-close.width,winRect.y,close.width,close.height );
					if (GUI.Button (closeRect, close,GUIStyle.none)) {
						showMenu = false;
						Time.timeScale = !showMenu ? 1.0f : 0.0f;
					};

					GUIStyle centeredStyle = GUI.skin.GetStyle("Label");
					centeredStyle.alignment = TextAnchor.UpperCenter;

					int btnWidth = 95;
					int btnHeight = 165;

					for(int x = 0; x < items.Count;  x++)	{
						Texture2D texture = itemIcons[items[x].ItemId];
						Rect btn1Rect = new Rect (winRect.x+buttonX+(btnWidth*x)+(iconsSpace*x),winRect.y+buttonY,btnWidth,btnHeight );	
						Rect labelRect = GUILayoutUtility.GetRect(new GUIContent("<size="+titleSize+">"+items[x].DisplayName+"</size>"), "label");
						labelRect.x = btn1Rect.x + btn1Rect.width*0.5f-labelRect.width*0.5f;
						labelRect.y = btn1Rect.y+textY;
						Rect gun2Rect = new Rect (btn1Rect.x+btn1Rect.width*0.5f-texture.width*0.5f,btn1Rect.y+iconsY,texture.width, texture.height);
						Rect labelRectb = GUILayoutUtility.GetRect(new GUIContent("<size="+textSize+">"+items[x].Description+"</size>"), "label");
						labelRectb.width = 100;
						labelRectb.height = 80;
						labelRectb.x = btn1Rect.x + btn1Rect.width*0.5f-labelRectb.width*0.5f;
						labelRectb.y = gun2Rect.y+gun2Rect.height+textY;
						foreach (KeyValuePair<string, uint> price in items[x].VirtualCurrencyPrices)
						{

							if (GUI.Button(btn1Rect,"")){
								PurchaseItemRequest request = new PurchaseItemRequest();
								request.CatalogVersion = items[x].CatalogVersion;
								request.VirtualCurrency = price.Key;
								request.Price = Convert.ToInt32(price.Value);
								request.ItemId = items[x].ItemId;
								PlayFabClientAPI.PurchaseItem(request,PlayFabItemsController.OnPurchase,OnPlayFabError);
							};
							GUI.Label (new Rect (btn1Rect.x+btn1Rect.width*0.5f-10,labelRectb.y+50,40, 40), "<size="+priceTextSize+">"+price.Value+" $</size>",centeredStyle);
						}
						GUI.Label (labelRect, "<size="+titleSize+">"+items[x].DisplayName+"</size>",centeredStyle);
						GUI.DrawTexture (gun2Rect, texture);
						GUI.Label (labelRectb, "<size="+textSize+">"+items[x].Description+"</size>",centeredStyle);
					
					};
				}
				if (drawCursor) {
					Rect cursorRect = new Rect (Input.mousePosition.x,Screen.height-Input.mousePosition.y,cursor.width,cursor.height );
					GUI.DrawTexture (cursorRect, cursor);
					PlayFabGameBridge.mouseOverGui = true;
				}
			}
		}
Пример #2
0
		/// <summary>
		/// Buys a single item with virtual currency. You must specify both the virtual currency to use to purchase, as well as what the client believes the price to be. This lets the server fail the purchase if the price has changed.
		/// </summary>
		public static void PurchaseItem(PurchaseItemRequest request, PurchaseItemCallback resultCallback, ErrorCallback errorCallback)
		{
			if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

			string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
			Action<string,string> callback = delegate(string responseStr, string errorStr)
			{
				PurchaseItemResult result = null;
				PlayFabError error = null;
				ResultContainer<PurchaseItemResult>.HandleResults(responseStr, errorStr, out result, out error);
				if(error != null && errorCallback != null)
				{
					errorCallback(error);
				}
				if(result != null)
				{
					
					if(resultCallback != null)
					{
						resultCallback(result);
					}
				}
			};
			PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/PurchaseItem", serializedJSON, "X-Authorization", AuthKey, callback);
		}
        /// <summary>
        /// Buys a single item with virtual currency. You must specify both the virtual currency to use to purchase, as well as what the client believes the price to be. This lets the server fail the purchase if the price has changed.
        /// </summary>
        public static void PurchaseItem(PurchaseItemRequest request, ProcessApiCallback<PurchaseItemResult> resultCallback, ErrorCallback errorCallback, object customData = null)
        {
            if (_authKey == null) throw new Exception("Must be logged in to call this method");

            string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy);
            Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
            {
                ResultContainer<PurchaseItemResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
            };
            PlayFabHTTP.Post("/Client/PurchaseItem", serializedJson, "X-Authorization", _authKey, callback, request, customData);
        }
Пример #4
0
		/// <summary>
		/// Buys a single item with virtual currency. You must specify both the virtual currency to use to purchase, as well as what the client believes the price to be. This lets the server fail the purchase if the price has changed.
		/// </summary>
        public static async Task<PlayFabResult<PurchaseItemResult>> PurchaseItemAsync(PurchaseItemRequest request)
        {
            if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

            object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/PurchaseItem", request, "X-Authorization", AuthKey);
            if(httpResult is PlayFabError)
            {
                PlayFabError error = (PlayFabError)httpResult;
                if (PlayFabSettings.GlobalErrorHandler != null)
                    PlayFabSettings.GlobalErrorHandler(error);
                return new PlayFabResult<PurchaseItemResult>
                {
                    Error = error,
                };
            }
            string resultRawJson = (string)httpResult;

            var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings);
            var resultData = serializer.Deserialize<PlayFabJsonSuccess<PurchaseItemResult>>(new JsonTextReader(new StringReader(resultRawJson)));
			
			PurchaseItemResult result = resultData.data;
			
			
            return new PlayFabResult<PurchaseItemResult>
                {
                    Result = result
                };
        }