Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator GetVoucherImage()
- {
- Debug.LogAssertion ("Start");
- string voucher_id;
- //Get the voucher index
- var voucherIndexRequest = new WWW("http://gametaiko.com/hungry/api.php?action=voucher_distribute");
- yield return voucherIndexRequest;
- Debug.Log(voucherIndexRequest.text);
- int index = Int32.Parse(voucherIndexRequest.text);
- Debug.Log("INDEX IS " + index);
- //Get the voucher id from the requested index
- voucher_id =PlayerData.Instance.GetAvailableVouchersList()[index].voucher_id;
- //Check if the voucher_id is still available
- if(PlayerData.Instance.GetAvailableVoucherByID(voucher_id).amount <= 0)
- {
- //if amount is 0, start voucher image request again
- StartCoroutine(GetVoucherImage());
- //break this coroutine
- yield break;
- }
- /*VOUCHER REQUEST SUCCESSFUL*/
- //if successful
- //get physical location of the voucher:
- //Mont Kiara, Solaris, Hartamas
- //Subang, Sunway, USJ
- //PJ Town
- //KL City
- string location = GetVoucherLocation (PlayerData.Instance.GetAvailableVouchersList()[index].location);
- //check the location of the voucher
- if(!SceneManager.GetActiveScene().name.Contains(location))
- {
- if(!(SceneManager.GetActiveScene().name.Contains("Damansara") && location == "PJ"))
- {
- Debug.Log ("Trying again");
- StartCoroutine(GetVoucherImage());
- yield break;
- }
- }
- Debug.Log ("Matched");
- Debug.Log("VOUCHER_ID IS " + voucher_id);
- WWW voucherReceiveRequest = new WWW("http://gametaiko.com/hungry/api.php?action=analytic&event=received¶meter=" +
- voucher_id);
- yield return voucherReceiveRequest;
- // check for errors
- if (voucherReceiveRequest.text == null) {
- Debug.Log ("WWW Ok!: " + voucherReceiveRequest.text);
- } else {
- Debug.Log ("WWW Error: " + voucherReceiveRequest.text);
- }
- Debug.Log("GETTING VOUCHER IMAGE");
- var voucherImageRequest = new WWW("http://gametaiko.com/hungry/api.php?action=voucher_image&voucher_id=" +
- voucher_id);
- yield return voucherImageRequest;
- Texture2D temp = voucherImageRequest.texture;
- Sprite sprite = Sprite.Create(temp,new Rect(0,0,temp.width,temp.height),new Vector2(0.5f,0.5f));
- voucherButton.GetComponent<Image>().sprite = sprite;
- GameObject.FindObjectOfType<InGameMenu>().voucher_id = voucher_id;
- PlayerData.Instance.SetInGameVoucher(voucher_id);
- LogAnalytics(voucher_id);
- voucherButton.GetComponent<Button> ().interactable = true;
- redeemNowImageButton.GetComponent<Button> ().interactable = true;
- keepPlayingButton.GetComponent<Button> ().interactable = true;
- Debug.LogAssertion ("END");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement