|
@@ -1,3 +1,4 @@
|
|
|
|
|
+using System;
|
|
|
using System.Collections;
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
@@ -7,7 +8,7 @@ using UnityEngine.UI;
|
|
|
//验证码控制器
|
|
//验证码控制器
|
|
|
public class CaptchaController : Singleton<CaptchaController>
|
|
public class CaptchaController : Singleton<CaptchaController>
|
|
|
{
|
|
{
|
|
|
- public IEnumerator GetCaptcha(CaptchaType type, Image targetRenderImage)
|
|
|
|
|
|
|
+ public IEnumerator GetCaptcha(Image targetRenderImage, Action<int> cb)
|
|
|
{
|
|
{
|
|
|
int code = UnityEngine.Random.Range(1000, 10000);
|
|
int code = UnityEngine.Random.Range(1000, 10000);
|
|
|
UnityWebRequest uwr = new UnityWebRequest(CommonConfig.businessServerURI + "/api/createCaptcha?code=" + code, UnityWebRequest.kHttpVerbGET);
|
|
UnityWebRequest uwr = new UnityWebRequest(CommonConfig.businessServerURI + "/api/createCaptcha?code=" + code, UnityWebRequest.kHttpVerbGET);
|
|
@@ -15,25 +16,7 @@ public class CaptchaController : Singleton<CaptchaController>
|
|
|
yield return uwr.SendWebRequest();
|
|
yield return uwr.SendWebRequest();
|
|
|
Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
|
|
Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
|
|
|
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
|
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
|
|
- switch (type) {
|
|
|
|
|
- case CaptchaType.Login:
|
|
|
|
|
- captcha_Login = code;
|
|
|
|
|
- targetRenderImage.sprite = sprite;
|
|
|
|
|
- break;
|
|
|
|
|
- case CaptchaType.LoginPhone:
|
|
|
|
|
- captcha_LoginPhone = code;
|
|
|
|
|
- targetRenderImage.sprite = sprite;
|
|
|
|
|
- break;
|
|
|
|
|
- case CaptchaType.Register:
|
|
|
|
|
- captcha_Register = code;
|
|
|
|
|
- targetRenderImage.sprite = sprite;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ targetRenderImage.sprite = sprite;
|
|
|
|
|
+ if (cb != null) cb(code);
|
|
|
}
|
|
}
|
|
|
- public enum CaptchaType {
|
|
|
|
|
- Login, LoginPhone, Register
|
|
|
|
|
- }
|
|
|
|
|
- public int captcha_Login = -222222222;
|
|
|
|
|
- public int captcha_LoginPhone = -222222222;
|
|
|
|
|
- public int captcha_Register = -222222222;
|
|
|
|
|
}
|
|
}
|