Exemple #1
0
    private void GetColorAndSize(string color, string size)
    {
        string value    = color + " / " + size;
        var    variants = (List <Shopify.Unity.ProductVariant>)CurrentProduct.variants();

        foreach (var item in variants)
        {
            if (item.title() == value)
            {
                CurrentVariant = item;
            }
        }

        cartButton.interactable = true;
        foreach (var item in sizes)
        {
            item.transform.GetChild(1).GetComponent <UnityEngine.UI.Image>().enabled = false;
        }

        for (int i = 0; i < sizes.Count; i++)
        {
            if (size == sizes[i].name)
            {
                sizes[i].gameObject.transform.GetChild(1).GetComponent <UnityEngine.UI.Image>().enabled = true;
            }
        }
    }
Exemple #2
0
    private void SearchHat(List <ColorsAndSizes> colorsAndSizes, Product product, ProductVariant productVariant)
    {
        for (int i = 0; i < m_ListContentHatPanel.Count; i++)
        {
            if (m_ListContentHatPanel[i].GetComponent <HatPanelArPrefab>().m_HatId == product.title())
            {
                Vector2 size  = Content.GetComponent <RectTransform>().sizeDelta;
                float   Value = size.x / m_ListContentHatPanel.Count;
                float   Pos   = Value * i;
                float   V     = (Value / 2);
                float   S     = (Pos + V);

                ValueContent = (S);
                Content.GetComponent <RectTransform>().DOLocalMoveX(-ValueContent, 0.01f);
                indexInstruction = i;
                currentIndexHat  = i;
                one = true;

                CurrentProduct = product;
                OnSetHatName(product.title().ToLower());
                CurrentVariant = productVariant;

                hatNameCapturePhoto.text = product.title();

                if (colorsAndSizes != null)
                {
                    for (int j = 0; j < colorsAndSizes.Count; j++)
                    {
                        Transform  parent           = m_ListContentHatPanel[i].GetComponent <HatPanelArPrefab>().m_ColorOptionPrefab.transform.parent;
                        GameObject colorButton      = m_ListContentHatPanel[i].GetComponent <HatPanelArPrefab>().m_ColorOptionPrefab;
                        GameObject sizePrefabButton = m_ListContentHatPanel[i].GetComponent <HatPanelArPrefab>().m_SizeOptionPrefab;
                        cartButton = m_ListContentHatPanel[i].GetComponent <HatPanelArPrefab>().cart;
                        Sprite IconColor = colorsAndSizes[j].HatImage;
                        UnityEngine.UI.Image hatPhoto = m_ListContentHatPanel[i].GetComponent <HatPanelArPrefab>().m_HatPhoto;
                        var objC = Instantiate(colorButton, parent);

                        NewMethod(IconColor, objC);

                        objC.name = colorsAndSizes[j].NameColor;
                        int indexHat = j;
                        objC.SetActive(true);
                        colors.Add(objC);
                        objC.GetComponent <Button>().onClick.RemoveAllListeners();

                        objC.GetComponent <Button>().onClick.AddListener(delegate
                        {
                            InstantiateSizes(sizePrefabButton, hatPhoto, colorsAndSizes,
                                             objC.name, indexHat);
                        });

                        InstantiateSizes(sizePrefabButton, hatPhoto, colorsAndSizes, colorsAndSizes[0].NameColor, 0);

                        if (colorsAndSizes.Count <= 1)
                        {
                            objC.SetActive(false);
                        }
                    }

                    if (colorsAndSizes.Count > 0)
                    {
                        m_ListContentHatPanel[i].GetComponent <HatPanelArPrefab>().m_HatPhoto.sprite = colorsAndSizes[0].HatImage;
                    }
                }

                if (cartButton != null)
                {
                    cartButton.interactable = true;
                    cartButton.onClick.RemoveAllListeners();
                    cartButton.onClick.AddListener(() =>
                    {
                        m_informationPanel.OnAddProductToCart.Invoke(CurrentProduct, CurrentVariant);
                        OnViewCart.Invoke();
                        AppController.OnShoopingCartPanelAR();
                    });
                }
                else
                {
                    cartButton.interactable = false;
                }
            }
        }
    }