Exemple #1
0
    private IEnumerator ImageViewWithFrame(
        CardData card,
        ImageViewWithFrame frame,
        int imageSize,
        string resourcePath,
        float leftMargin   = 0,
        float topMargin    = 0,
        float rightMargin  = 0,
        float bottomMargin = 0)
    {
        Texture texture;

        if (!string.IsNullOrEmpty(resourcePath))
        {
            texture = Resources.Load <Texture>(resourcePath);
        }
        else
        {
            string path = WebCache.GetCachedPath(card);
            WWW    www  = new WWW(path);
            yield return(www);

            texture = www.texture;
        }

        frame.BigSize      = imageSize;
        frame.FrameTexture = FrameObject;
        frame.ImageTexture = texture;
        frame.LeftMargin   = leftMargin;
        frame.TopMargin    = topMargin;
        frame.RightMargin  = rightMargin;
        frame.BottomMargin = bottomMargin;

        frame.MeasureSize();
    }
        private IEnumerator LoadImages(IEnumerable <string> results)
        {
            Vector3 startPosition = Camera.main.WorldToScreenPoint(SpawnStartLocation.transform.position);

            startPosition.y = Screen.height - startPosition.y;

            Vector3 endPosition = Camera.main.WorldToScreenPoint(SpawnEndLocation.transform.position);

            endPosition.y = Screen.height - endPosition.y;

            float width           = endPosition.x - startPosition.x;
            int   boxWidth        = (int)(width * 0.8f);
            float leftRightMargin = width * 0.2f;
            float topBottomMargin = width * 0.05f;

            searchScrollContentHeight = 0;

            int i = DataMessenger.LastSetsQuery.GetHashCode();

            foreach (var result in results)
            {
                CardData data = new CardData();
                data.Image = result;
                data.Id    = i;
                data.Title = DataMessenger.LastSetsQuery;

                yield return(StartCoroutine(WebCache.Cache(data)));

                string path = WebCache.GetCachedPath(data);

                WWW www = new WWW(path);
                yield return(www);

                var image = AddToSearchResults(www.texture, boxWidth, leftRightMargin, topBottomMargin);
                image.Tag = data;

                searchItems.Items.Add(image);

                searchItems.MeasureSize();
                searchScrollContentHeight = searchItems.Rect.height;
                ++i;
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets card image asynchronous.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>Returns enumerator Unity async pattern.</returns>
        private IEnumerator SetCardAsync(CardData data)
        {
            string    path; // = "Decks/" + data.Title + "/" + Path.GetFileNameWithoutExtension(data.Image);
            Texture2D texture;

            if (data.Image.StartsWith("res://"))
            {
                path    = data.Image.Substring(6);
                texture = Resources.Load <Texture2D>(path);
            }
            else
            {
                path = WebCache.GetCachedPath(data);
                WWW www = new WWW(path);
                yield return(www);

                texture = www.texture;
            }

            CardData.Texture = data.Texture = texture;

            // First child must be front image.
            var cardObject     = gameObject.transform.GetChild(0);
            var spriteRenderer = cardObject.renderer as SpriteRenderer;

            if (spriteRenderer != null)
            {
                // This math will crop image to target aspect ratio and scale game object rather than texture.
                float scale;
                Rect  rect = MathHelper.ScaleAndCrop(texture.width, texture.height, 277, 274, out scale);
                scale *= .84f;

                cardObject.transform.localScale = new Vector3(scale, scale);
                var sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f));

                spriteRenderer.sprite = sprite;
            }

            // NOTE: This method uses Unity async pattern because image can be on the Internet in future versions.
            // We're forced to use yield break because there is no yield return.
            yield break;
        }