Example #1
0
    public IEnumerator Start()
    {
        foreach (Transform child in BannerGrid)
        {
            Destroy(child.gameObject);
        }

        foreach (Transform child in PaginationGrid)
        {
            Destroy(child.gameObject);
        }

        foreach (var banner in Banners)
        {
            var instance = Instantiate(BannerPrefab, BannerGrid);
            var button   = instance.GetComponent <Button>();

            button.onClick.RemoveAllListeners();

            if (string.IsNullOrEmpty(banner.Url))
            {
                if (banner.data != null)
                {
                    Banner b = banner;
                    button.onClick.AddListener(delegate { PushData(b); });
                }
                else
                {
                    button.onClick.AddListener(() => { StartCoroutine(ForceScrollDown()); });
                }
            }
            else
            {
                button.onClick.AddListener(() => {
                    Debug.Log(banner.Url);


                    var safeBrowsing = UniWebViewSafeBrowsing.Create(banner.Url);

                    // Show it on screen.
                    safeBrowsing.Show();
                });
            }

            instance.GetComponent <Image>().sprite = banner.Sprite;

            if (Banners.Count > 1)
            {
                var toggle = Instantiate(PagePrefab, PaginationGrid);

                toggle.group = PaginationGrid.GetComponent <ToggleGroup>();
            }
        }

        yield return(null);

        HorizontalScrollSnap.Initialize(Random);
        HorizontalScrollSnap.GetComponent <ScrollRect>().movementType = Elastic ? ScrollRect.MovementType.Elastic : ScrollRect.MovementType.Clamped;
    }