using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; /* Http控制器-验证码 */ public class CaptchaController : Singleton { public IEnumerator GetCaptcha(Image targetRenderImage, Action cb) { int code = UnityEngine.Random.Range(1000, 10000); using (UnityWebRequest uwr = new UnityWebRequest(CommonConfig.businessServerURI + "/api/createCaptcha?code=" + code, UnityWebRequest.kHttpVerbGET)) { uwr.downloadHandler = new DownloadHandlerTexture(); yield return uwr.SendWebRequest(); Texture2D texture = DownloadHandlerTexture.GetContent(uwr); Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); targetRenderImage.sprite = sprite; if (cb != null) cb(code); } } }