public override void OnShow()
    {
        scrollView.transform.gameObject.SetActive(false);
        scrollView.transform.gameObject.SetActive(true);
        scrollView.ResetPosition();

        textTix.text = PlayerPrefs.GetInt(PlayerPrefHandler.keyUserTiket, 0).ToString();
        for (int i = 0; i < scrollView.transform.childCount; i++)
        {
            ButtonReward button = (ButtonReward)scrollView.transform.GetChild(i).gameObject.GetComponent <ButtonReward>();
            if (button)
            {
                Transform trIcon = button.transform.Find("Icon");
                if (trIcon)
                {
                    WWW_Texture wwwTexture = trIcon.gameObject.GetComponent <WWW_Texture>();
                    wwwTexture.sender = button.gameObject;
                    if (wwwTexture)
                    {
                        //if ( !wwwTexture.IsDone() )
                        //{
                        wwwTexture.StartDownloadImage(button.gambar);
                        //}
                    }
                }
            }
        }
    }
    void OnRewardResponse(Restifizer.RestifizerResponse response)
    {
        ArrayList data = response.ResourceList;

        for (int i = 0; i < response.ResourceList.Count; i++)
        {
            Hashtable dataReward  = (Hashtable)response.ResourceList[i];
            Transform targetChild = null;
            if (scrollView)
            {
                for (int j = 0; j < scrollView.transform.childCount; j++)
                {
                    Transform child = scrollView.transform.GetChild(j);
                    //Debug.LogError("child.name="+child.name+" "+" kode="+nChild["kode"]);
                    if (child && child.name.Equals(dataReward["kode"]))
                    {
                        targetChild = child;
                        break;
                    }
                }
            }

            if (targetChild == null)
            {
                GameObject ob = Instantiate(prefabContent);

                ob.name     = dataReward["kode"].ToString();
                targetChild = ob.transform;
                ob.gameObject.SetActive(true);
                ob.transform.parent     = scrollView.transform;
                ob.transform.localScale = Vector3.one;
                ob.gameObject.SetActive(false);

                ButtonReward reward = targetChild.GetComponent <ButtonReward>();
                reward.nama   = dataReward["nama"].ToString();
                reward.kode   = dataReward["kode"].ToString();
                reward.des    = dataReward["des"].ToString();
                reward.gambar = dataReward["gambar"].ToString();
                reward.tiket  = int.Parse(dataReward["tiket"].ToString());
                targetChild.gameObject.SetActive(false);
                targetChild.gameObject.SetActive(true);

                UISprite sprite = ob.GetComponent <UISprite>();
                if (HorizontalAmount == 1)
                {
                    ob.transform.localPosition = new Vector3(-10, 100 - ((scrollView.transform.childCount - 1) * sprite.height), 0);
                }
                else if (HorizontalAmount == 2)
                {
                    if (i % HorizontalAmount == 0)
                    {
                        ob.transform.localPosition = new Vector3(-310, 80 - (int)(i / 2) * 400, 0);
                    }
                    else if (i % HorizontalAmount == 1)
                    {
                        ob.transform.localPosition = new Vector3(310, 80 - (int)(i / 2) * 400, 0);
                    }
                }

                UIButton buttonRedeem = ob.GetComponent <UIButton>();
                if (buttonRedeem)
                {
                    buttonRedeem.onClick.Add(new EventDelegate(this, "OnClickRedeem"));
                }

                Transform trIcon = ob.transform.Find("Icon");
                if (trIcon)
                {
                    WWW_Texture wwwTexture = trIcon.gameObject.GetComponent <WWW_Texture>();
                    wwwTexture.sender = ob;
                    if (wwwTexture)
                    {
                        wwwTexture.StartDownloadImage(dataReward["gambar"].ToString());
                    }
                }
            }
            if (targetChild)
            {
            }
        }
    }
Exemplo n.º 3
0
    public void OnGL1Done(JSONNode N)
    {
        if (GL1Connector.GetInstance().GetLastURL().Contains("reward"))
        {
            Debug.LogError("ProcessRewardList amount=" + N.Count);
            int indexReward = 0;
            foreach (JSONNode nChild in N.Childs)
            {
                Transform targetChild = null;
                for (int i = 0; i < scrollView.transform.childCount; i++)
                {
                    Transform child = scrollView.transform.GetChild(i);
                    //Debug.LogError("child.name="+child.name+" "+" kode="+nChild["kode"]);
                    if (child && child.name.Equals(nChild ["kode"]))
                    {
                        targetChild = child;
                        break;
                    }
                }

                if (targetChild == null)
                {
                    Debug.LogError("instantiate");
                    GameObject ob = (GameObject)Instantiate(prefabContent);
                    ob.name                    = nChild ["kode"];
                    targetChild                = ob.transform;
                    ob.transform.parent        = scrollView.transform;
                    ob.transform.localPosition = new Vector3(0, 230 - (indexReward * 230), 0);
                    ob.transform.localScale    = Vector3.one;

                    Transform trIcon = targetChild.Find("Icon");
                    if (trIcon)
                    {
                        UIButton buttonRedeem = trIcon.gameObject.GetComponent <UIButton> ();
                        if (buttonRedeem)
                        {
                            buttonRedeem.onClick.Add(new EventDelegate(this, "OnClickRedeem"));
                        }

                        WWW_Texture wwwTexture = trIcon.gameObject.GetComponent <WWW_Texture> ();
                        if (wwwTexture)
                        {
                            wwwTexture.StartDownloadImage(nChild ["gambar"]);
                        }
                    }

                    indexReward++;
                }

                if (targetChild)
                {
                    ButtonReward reward = targetChild.GetComponent <ButtonReward> ();
                    reward.nama   = nChild ["nama"];
                    reward.kode   = nChild ["kode"];
                    reward.des    = nChild ["des"];
                    reward.gambar = nChild ["gambar"];
                    reward.tiket  = int.Parse(nChild ["tiket"]);
                    GameManager.SetNGUILabel(targetChild.Find("Label Title"), nChild ["nama"]);
                    GameManager.SetNGUILabel(targetChild.Find("Label Desc"), nChild ["des"]);
                    GameManager.SetNGUILabel(targetChild.Find("Label Ticket Amount"), nChild ["tiket"]);
                }
            }
        }
        else if (GL1Connector.GetInstance().GetLastURL().Contains("redeem"))
        {
            if (N["errcode"].ToString() == "\"0\"")
            {
                guiDialogBox.Show("Info", "Redeem success", false, "", this.gameObject);
            }
            else
            {
                guiDialogBox.Show("Info", N["errdetail"], false, "", this.gameObject);
            }
        }
    }