コード例 #1
0
        private IEnumerator DisplayPreviews(List <Toggle> previewToggles)
        {
            foreach (Toggle t in previewToggles)
            {
                if (!t.IsDestroyed())
                {
                    Text   statusText     = Utils.FindSubobjectByName(t.gameObject, "StatusText").GetComponentInChildren <Text>();
                    string haircutId      = t.GetComponentInChildren <ToggleId>().Id;
                    var    previewRequest = avatarProvider.GetHaircutPreviewAsync(avatarCode, haircutId);
                    yield return(previewRequest);

                    if (previewRequest.IsError || previewRequest.Result == null)
                    {
                        Debug.LogErrorFormat("Unable to get preview image for haircut: {0}", haircutId);
                        statusText.text = "Not found";
                    }
                    else
                    {
                        Texture2D texture = new Texture2D(1, 1);
                        texture.LoadImage(previewRequest.Result);
                        if (!t.IsDestroyed())
                        {
                            GameObject backgroundObject = Utils.FindSubobjectByName(t.gameObject, "Background");
                            Image      image            = backgroundObject.GetComponentInChildren <Image>();
                            image.sprite    = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
                            statusText.text = string.Empty;
                        }
                    }
                }
            }
        }