示例#1
0
    public void LoadItem()
    {
        Popup.Ins.PopupWaiting(true);

        countText.text = "0";
        int o = 0;

        while (item.transform.parent.childCount > 1)
        {
            Transform c = item.transform.parent.GetChild(o);
            if (c.name == item.name)
            {
                o++;
                continue;
            }
            c.parent = null;
            Destroy(c.gameObject);
        }

        for (int i = 0; i < web.m_ViewProfile.user.own.Length; i++)
        {
            GameObject clone         = Instantiate(item, item.transform.parent);
            RawImage   cloneRawImage = clone.GetComponentInChildren <RawImage>();
            //รับรูป
            StartCoroutine(GetTexture(web.m_ViewProfile.user.own[i].pic, cloneRawImage));
            //เซ็ตค่าตั้งต้น
            Text cloneText = clone.GetComponentInChildren <Text>();
            cloneText.text = web.m_ViewProfile.user.own[i].name;
            PetData petData = clone.AddComponent <PetData>();

            bool hasPet = false;
            for (int y = 0; y < webG.player.player.petList.Count; y++)
            {
                //ถ้าไม่มีในลิช
                if (webG.player.player.petList[y].gender.ToString() == web.m_ViewProfile.user.own[i].id)
                {
                    hasPet = true;
                    petData.ClonePetList(webG.player.player.petList[y]);
                    //เซ็ตอวตาร
                    if (petData.color >= 0)
                    {
                        Transform child = clone.transform.GetChild(2).GetChild(0);
                        child.gameObject.SetActive(true);
                        child.GetChild(0).GetComponent <Image>().sprite = Atlas.Ins.GetSprites(Atlas.Ins.cha.ear.color[petData.color])[petData.ear];
                        child.GetChild(1).GetComponent <Image>().sprite = Atlas.Ins.GetSprites(Atlas.Ins.cha.head.color[petData.color])[petData.head];
                        child.GetChild(2).GetComponent <Image>().sprite = Atlas.Ins.GetSprites(Atlas.Ins.cha.pattern.color[petData.color])[petData.pattern];
                        child.GetChild(3).GetComponent <Image>().sprite = Atlas.Ins.GetSprites(Atlas.Ins.cha.eye)[petData.eye];
                        child.GetChild(4).GetComponent <Image>().sprite = Atlas.Ins.GetSprites(Atlas.Ins.cha.eyebrow)[petData.eyebrow];
                        child.GetChild(5).GetComponent <Image>().sprite = Atlas.Ins.GetSprites(Atlas.Ins.cha.nose)[petData.nose];
                        child.GetChild(6).GetComponent <Image>().sprite = Atlas.Ins.GetSprites(Atlas.Ins.cha.mouth)[petData.mouth];
                    }
                    if (petData.selected && petData.status >= 0)
                    {
                        clone.transform.SetSiblingIndex(0);
                        clone.transform.GetChild(4).GetChild(0).gameObject.SetActive(true);
                        countText.text = (int.Parse(countText.text) + 1).ToString();
                    }
                    else
                    {
                        clone.transform.SetSiblingIndex(web.m_ViewProfile.user.own.Length - 1);
                    }
                    break;
                }
            }
            if (!hasPet)
            {
                API_Game.Ins.PostPetRequest(web.m_ViewProfile.user.own[i].name, web.m_ViewProfile.user.own[i].id, LoadItem);
                return;
            }

            //ถ้าไม่ถูกลบ
            if (petData.status >= 0)
            {
                clone.SetActive(true);
            }
        }
        Popup.Ins.PopupWaiting(false);
    }