Parcourir la source

节流器修改

lvjincheng il y a 3 ans
Parent
commit
313e660b8e

+ 2 - 4
Assets/BowArrow/Scripts/Manager/LoginView/LoginView.cs

@@ -145,7 +145,7 @@ public class LoginView : MonoBehaviour
         }
     }
 
-    long _lastLoginNormalTime = 0;
+    JC.CS.Throttler throttlerLoginNormal = new JC.CS.Throttler(2000);
     void LoginNormal() {
         InputField user = GetInputField(loginInUser);
         if (user.text.Trim().Length == 0) {
@@ -166,11 +166,9 @@ public class LoginView : MonoBehaviour
             PopupMgr.ins.ShowTip("登录需要勾选同意App协议");
             return;
         }
-        if (JC.CS.Utility.GetTimestamp() - _lastLoginNormalTime < 2000) {
+        if (throttlerLoginNormal.CanPass() == false) {
             PopupMgr.ins.ShowTip("操作过于频繁");
             return;
-        } else {
-            _lastLoginNormalTime = JC.CS.Utility.GetTimestamp();
         }
         StartCoroutine(LoginController.ins.LoginNormal(
             user.text, pwd.text, (res) => {

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

@@ -85,7 +85,7 @@ public class RegisterView : MonoBehaviour
 
     private string usrRecord = "";
     private string pwdRecord = "";
-    long _lastRegisterNextTime = 0;
+    JC.CS.Throttler throttlerRegisterNext = new JC.CS.Throttler(2000);
     public void RegisterNext()
     {
         InputField user = GetInputField(registerInUser);
@@ -108,11 +108,9 @@ public class RegisterView : MonoBehaviour
             PopupMgr.ins.ShowTip("验证码错误");
             return;
         }
-        if (JC.CS.Utility.GetTimestamp() - _lastRegisterNextTime < 2000) {
+        if (throttlerRegisterNext.CanPass() == false) {
             PopupMgr.ins.ShowTip("操作过于频繁");
             return;
-        } else {
-            _lastRegisterNextTime = JC.CS.Utility.GetTimestamp();
         }
         usrRecord = user.text;
         pwdRecord = pwd1.text;
@@ -127,7 +125,7 @@ public class RegisterView : MonoBehaviour
         ));
     }
 
-    long _lastRegisterSaveTime = 0;
+    JC.CS.Throttler throttlerRegisterSave = new JC.CS.Throttler(2000);
     public void RegisterSave() {
         InputField nickname = GetInputField(registerInNickname);
         if (nickname.text.Trim().Length == 0) {
@@ -152,11 +150,9 @@ public class RegisterView : MonoBehaviour
             PopupMgr.ins.ShowTip("未填写所在地区");
             return;
         }
-        if (JC.CS.Utility.GetTimestamp() - _lastRegisterSaveTime < 2000) {
+        if (throttlerRegisterSave.CanPass() == false) {
             PopupMgr.ins.ShowTip("操作过于频繁");
             return;
-        } else {
-            _lastRegisterSaveTime = JC.CS.Utility.GetTimestamp();
         }
         StartCoroutine(LoginController.ins.CompleteUserInfo(
             usrRecord, pwdRecord, nickname.text, gender, birthday.text,

+ 2 - 4
Assets/BowArrow/Scripts/View/MeView.cs

@@ -21,7 +21,7 @@ public class MeView : MonoBehaviour
         Destroy(this.gameObject);
     }
 
-    long _lastSaveTime = 0;
+    JC.CS.Throttler throttlerSave = new JC.CS.Throttler(2000);
     public void Save() 
     {
         AudioMgr.ins.PlayBtn();
@@ -40,11 +40,9 @@ public class MeView : MonoBehaviour
             }
             texts[i] = inputField.text.Trim();
         }
-        if (JC.CS.Utility.GetTimestamp() - _lastSaveTime < 2000) {
+        if (throttlerSave.CanPass() == false) {
             PopupMgr.ins.ShowTip("操作过于频繁");
             return;
-        } else {
-            _lastSaveTime = JC.CS.Utility.GetTimestamp();
         }
         LoginMgr.myUserInfo.nickname = texts[1];
         LoginMgr.myUserInfo.phone = texts[2];