lvjincheng 3 жил өмнө
parent
commit
e455dac749

+ 11 - 7
Assets/BowArrow/Scripts/Manager/LoginView/LoginView.cs

@@ -27,6 +27,10 @@ public class LoginView : MonoBehaviour
 
     int loginMode = 1;
 
+    //状态记录
+    public int captcha_Login = -222222222;
+    public int captcha_LoginPhone = -222222222;
+
     void Start()
     {
         InitInputLimit();
@@ -70,10 +74,10 @@ public class LoginView : MonoBehaviour
             loginInCode.SetActive(false);
             loginValidTime.SetActive(false);
             loginInCaptcha2.SetActive(false);
-            if (CaptchaController.ins.captcha_Login < 0) {
+            if (captcha_Login < 0) {
                 StartCoroutine(CaptchaController.ins.GetCaptcha(
-                    CaptchaController.CaptchaType.Login,
-                    loginInCaptcha1.transform.Find("CodeImage").GetComponent<Image>()
+                    loginInCaptcha1.transform.Find("CodeImage").GetComponent<Image>(),
+                    (code) => { captcha_Login = code; }
                 ));
             }
         }
@@ -87,10 +91,10 @@ public class LoginView : MonoBehaviour
             loginInCode.SetActive(true);
             loginValidTime.SetActive(true);
             loginInCaptcha2.SetActive(true);
-            if (CaptchaController.ins.captcha_LoginPhone < 0) {
+            if (captcha_LoginPhone < 0) {
                 StartCoroutine(CaptchaController.ins.GetCaptcha(
-                    CaptchaController.CaptchaType.LoginPhone,
-                    loginInCaptcha2.transform.Find("CodeImage").GetComponent<Image>()
+                    loginInCaptcha2.transform.Find("CodeImage").GetComponent<Image>(),
+                    (code) => { captcha_LoginPhone = code; }
                 ));
             }
         }
@@ -123,7 +127,7 @@ public class LoginView : MonoBehaviour
             return;
         }
         InputField captcha = GetInputField(loginInCaptcha1);
-        if (!captcha.text.Equals(CaptchaController.ins.captcha_Login.ToString())) {
+        if (!captcha.text.Equals(captcha_Login.ToString())) {
             Debug.Log("验证码错误");
             return;
         }

+ 8 - 7
Assets/BowArrow/Scripts/Manager/LoginView/RegisterView.cs

@@ -24,6 +24,9 @@ public class RegisterView : MonoBehaviour
     [SerializeField] GameObject btnSave;
     [SerializeField] Text registerTip;
 
+    //状态记录
+    public int captcha_Register = -222222222;
+
     void OnEnable() 
     {
         InitPage();
@@ -59,12 +62,10 @@ public class RegisterView : MonoBehaviour
         registerInLocation.SetActive(isNext);
         btnSave.SetActive(isNext);
         if (!isNext) {
-            if (CaptchaController.ins.captcha_Register < 0) {
-                StartCoroutine(CaptchaController.ins.GetCaptcha(
-                    CaptchaController.CaptchaType.Register,
-                    registerInCaptcha.transform.Find("CodeImage").GetComponent<Image>()
-                ));
-            }
+            StartCoroutine(CaptchaController.ins.GetCaptcha(
+                registerInCaptcha.transform.Find("CodeImage").GetComponent<Image>(),
+                (code) => { captcha_Register = code; }
+            ));
         }
     }
 
@@ -95,7 +96,7 @@ public class RegisterView : MonoBehaviour
             return;
         }
         InputField captcha = GetInputField(registerInCaptcha);
-        if (!captcha.text.Equals(CaptchaController.ins.captcha_Register.ToString())) {
+        if (!captcha.text.Equals(captcha_Register.ToString())) {
             Debug.Log("验证码错误");
             return;
         }

+ 4 - 21
Assets/BowArrow/Scripts/Network/HttpController/CaptchaController.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
@@ -7,7 +8,7 @@ using UnityEngine.UI;
 //验证码控制器
 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);
         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();
         Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
         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;
 }

+ 9 - 5
Assets/BowArrow/Scripts/Network/UserPlayer.cs

@@ -2,6 +2,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using JCEngineCore;
+using UnityEngine.SceneManagement;
 
 public class UserPlayer : JCEntity
 {
@@ -35,11 +36,11 @@ public class UserPlayer : JCEntity
     //向服务端发送的请求
     public void authToken() {
         string p0 = PlayerPrefs.GetString("IdAndToken", "");
-        #if UNITY_EDITOR
-            if (string.IsNullOrEmpty(p0)) {
-                p0 = "10&185fa8f92dfe4a55bf35e7ff604c519b";
-            } 
-        #endif
+        // #if UNITY_EDITOR
+        //     if (string.IsNullOrEmpty(p0)) {
+        //         p0 = "10&185fa8f92dfe4a55bf35e7ff604c519b";
+        //     } 
+        // #endif
         call("authToken", p0);
     }
 
@@ -58,6 +59,9 @@ public class UserPlayer : JCEntity
                     HomeMgr.ins.ShowAuthLoginMask(false);
                 }
             });            
+        } else {
+            PlayerPrefs.DeleteKey("IdAndToken");
+            SceneManager.LoadScene("Login", LoadSceneMode.Single);
         }
     }
 }

+ 1 - 0
Assets/BowArrow/Scripts/View/SetUpView.cs

@@ -106,6 +106,7 @@ public class SetUpView : MonoBehaviour
     public void Quit() 
     {
         AudioMgr.ins.PlayBtn();
+        PlayerPrefs.DeleteKey("IdAndToken");
         SceneManager.LoadScene("Login", LoadSceneMode.Single);
     }
 

+ 23 - 0
Assets/JC/JCLib.cs

@@ -44,6 +44,29 @@ namespace JC.CS
 }
 namespace JC.Unity
 {
+    public class AppRestartUtil {
+        public void Restart()
+        {
+            if (Application.platform != RuntimePlatform.Android) return;
+
+            using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
+            {
+                const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
+                const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
+
+                var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
+                var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
+                var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
+
+                intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
+                currentActivity.Call("startActivity", intent);
+                currentActivity.Call("finish");
+                var process = new AndroidJavaClass("android.os.Process");
+                int pid = process.CallStatic<int>("myPid");
+                process.CallStatic("killProcess", pid);
+            }
+        }
+    }
     public class TouchChecker
     {   
         bool hasTouch;