Advertisement
Guest User

Untitled

a guest
May 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. IEnumerator GetVoucherImage()
  2. {
  3. Debug.LogAssertion ("Start");
  4. string voucher_id;
  5.  
  6. //Get the voucher index
  7. var voucherIndexRequest = new WWW("http://gametaiko.com/hungry/api.php?action=voucher_distribute");
  8. yield return voucherIndexRequest;
  9.  
  10. Debug.Log(voucherIndexRequest.text);
  11. int index = Int32.Parse(voucherIndexRequest.text);
  12. Debug.Log("INDEX IS " + index);
  13.  
  14. //Get the voucher id from the requested index
  15. voucher_id =PlayerData.Instance.GetAvailableVouchersList()[index].voucher_id;
  16.  
  17. //Check if the voucher_id is still available
  18. if(PlayerData.Instance.GetAvailableVoucherByID(voucher_id).amount <= 0)
  19. {
  20. //if amount is 0, start voucher image request again
  21. StartCoroutine(GetVoucherImage());
  22.  
  23. //break this coroutine
  24. yield break;
  25. }
  26.  
  27. /*VOUCHER REQUEST SUCCESSFUL*/
  28. //if successful
  29.  
  30. //get physical location of the voucher:
  31. //Mont Kiara, Solaris, Hartamas
  32. //Subang, Sunway, USJ
  33. //PJ Town
  34. //KL City
  35. string location = GetVoucherLocation (PlayerData.Instance.GetAvailableVouchersList()[index].location);
  36.  
  37. //check the location of the voucher
  38. if(!SceneManager.GetActiveScene().name.Contains(location))
  39. {
  40. if(!(SceneManager.GetActiveScene().name.Contains("Damansara") && location == "PJ"))
  41. {
  42. Debug.Log ("Trying again");
  43. StartCoroutine(GetVoucherImage());
  44. yield break;
  45. }
  46. }
  47.  
  48. Debug.Log ("Matched");
  49. Debug.Log("VOUCHER_ID IS " + voucher_id);
  50.  
  51. WWW voucherReceiveRequest = new WWW("http://gametaiko.com/hungry/api.php?action=analytic&event=received&parameter=" +
  52. voucher_id);
  53.  
  54. yield return voucherReceiveRequest;
  55.  
  56. // check for errors
  57. if (voucherReceiveRequest.text == null) {
  58. Debug.Log ("WWW Ok!: " + voucherReceiveRequest.text);
  59. } else {
  60. Debug.Log ("WWW Error: " + voucherReceiveRequest.text);
  61. }
  62.  
  63. Debug.Log("GETTING VOUCHER IMAGE");
  64. var voucherImageRequest = new WWW("http://gametaiko.com/hungry/api.php?action=voucher_image&voucher_id=" +
  65. voucher_id);
  66. yield return voucherImageRequest;
  67.  
  68. Texture2D temp = voucherImageRequest.texture;
  69. Sprite sprite = Sprite.Create(temp,new Rect(0,0,temp.width,temp.height),new Vector2(0.5f,0.5f));
  70. voucherButton.GetComponent<Image>().sprite = sprite;
  71.  
  72. GameObject.FindObjectOfType<InGameMenu>().voucher_id = voucher_id;
  73. PlayerData.Instance.SetInGameVoucher(voucher_id);
  74.  
  75. LogAnalytics(voucher_id);
  76.  
  77. voucherButton.GetComponent<Button> ().interactable = true;
  78. redeemNowImageButton.GetComponent<Button> ().interactable = true;
  79. keepPlayingButton.GetComponent<Button> ().interactable = true;
  80. Debug.LogAssertion ("END");
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement