加载网络图片到UI界面中

        /// <summary>
        /// 等待图片加载
        /// </summary>
        /// <returns></returns>
        IEnumerator WaitingForImage()
        {

            //_Str_Url:图片的网络地址  GlobalParameter.STR_URL:是IP

            _Str_Url = GlobalParameter.STR_URL + _Str_Url;

            WWW www = new WWW(_Str_Url);
            yield return www;
            if (image != null)
            {
                if (www != null && string.IsNullOrEmpty(www.error))
                {
                    //常见一个图片,将网络端获取的图片赋值
                    Texture2D texture2D = www.texture;
                    //常见精灵图
                    Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f));
                    //将网络端获取的图片存放到UI界面上
                    image.sprite = sprite;
                }
            }

        }

猜你喜欢

转载自blog.csdn.net/qq_34444468/article/details/88420302