Esempio n. 1
0
    IEnumerator GetProductDetail_API(int v)
    {
        s = API_PRODUCT_DETAIL + "" + v;
        WWWForm         form = new WWWForm();
        UnityWebRequest www  = UnityWebRequest.Get(s);

        www.chunkedTransfer = false;

        yield return(www.SendWebRequest());

        if (www.isHttpError)
        {
            Show("HTTP Error", www.error, false);
            yield break;
        }
        if (www.isNetworkError)
        {
            Show("Network Error", www.error, false);
            yield break;
        }
        if (string.IsNullOrEmpty(www.downloadHandler.text))
        {
            Show("No Response", www.error, false);
            yield break;
        }


        string jsonString = www.downloadHandler.text;

        Debug.Log("JSON STRING :: " + jsonString);

        _productDetail = JsonUtility.FromJson <RootObject_ProductDetail>(jsonString);
        _panelProductDetail.SetProductDetail(_productDetail);
    }
    internal void SetProductDetail(RootObject_ProductDetail productDetail)
    {
        productCategoryText.text = API_Manager.INSTANCE.selectedCategory;
        typeText.text            = API_Manager.INSTANCE.selectedType;

        nameText.text        = productDetail.englishProductName;
        descriptionText.text = productDetail.englishProductDescription;


        // Delete child of attachments
        foreach (Transform t in attachmentContainer.transform)
        {
            Destroy(t.gameObject);
        }


        if (productDetail.attachments.Count > 0)
        {
            foreach (Attachment a in productDetail.attachments)
            {
                GameObject attach = Instantiate(attachmentPrefab, attachmentContainer.transform);
                attach.GetComponent <RawImage>().texture = Decode(a.pic);
            }
        }
        else
        {
            // Show No Image Found
            GameObject attach = Instantiate(attachmentPrefab, attachmentContainer.transform);
        }

        foreach (Transform t in videoContainer.transform)
        {
            Destroy(t.gameObject);
        }

        if (productDetail.productVideos.Count > 0)
        {
            foreach (ProductVideo a in productDetail.productVideos)
            {
                GameObject video = Instantiate(videoPrefab, videoContainer.transform);
                video.GetComponent <VideoContent>().uTubeURL = a.videoUrl;
            }
        }
        else
        {
        }

        verticalScroll.value = 1;
        OrthographicZoom.instance.bgLines.SetActive(true);
        API_Manager.INSTANCE._panelProductDetail.GetComponent <UIPanelMover>().MoveIn();
    }