@@ -24,6 +24,8 @@ public class UI : MonoBehaviour
2424 private UInt64 selAvatarDBID = 0 ;
2525 public bool showReliveGUI = false ;
2626
27+ bool startRelogin = false ;
28+
2729 void Awake ( )
2830 {
2931 inst = this ;
@@ -51,6 +53,8 @@ void installEvents()
5153 KBEngine . Event . registerOut ( "onScriptVersionNotMatch" , this , "onScriptVersionNotMatch" ) ;
5254 KBEngine . Event . registerOut ( "onLoginBaseappFailed" , this , "onLoginBaseappFailed" ) ;
5355 KBEngine . Event . registerOut ( "onLoginSuccessfully" , this , "onLoginSuccessfully" ) ;
56+ KBEngine . Event . registerOut ( "onReloginBaseappFailed" , this , "onReloginBaseappFailed" ) ;
57+ KBEngine . Event . registerOut ( "onReloginBaseappSuccessfully" , this , "onReloginBaseappSuccessfully" ) ;
5458 KBEngine . Event . registerOut ( "onLoginBaseapp" , this , "onLoginBaseapp" ) ;
5559 KBEngine . Event . registerOut ( "Loginapp_importClientMessages" , this , "Loginapp_importClientMessages" ) ;
5660 KBEngine . Event . registerOut ( "Baseapp_importClientMessages" , this , "Baseapp_importClientMessages" ) ;
@@ -348,6 +352,18 @@ public void onLoginBaseapp()
348352 info ( "connect to loginBaseapp, please wait...(连接到网关, 请稍后...)" ) ;
349353 }
350354
355+ public void onReloginBaseappFailed ( UInt16 failedcode )
356+ {
357+ err ( "relogin is failed(重连网关失败), err=" + KBEngineApp . app . serverErr ( failedcode ) ) ;
358+ startRelogin = false ;
359+ }
360+
361+ public void onReloginBaseappSuccessfully ( )
362+ {
363+ info ( "relogin is successfully!(重连成功!)" ) ;
364+ startRelogin = false ;
365+ }
366+
351367 public void onLoginSuccessfully ( UInt64 rndUUID , Int32 eid , Account accountEntity )
352368 {
353369 info ( "login is successfully!(登陆成功!)" ) ;
@@ -407,5 +423,19 @@ public void onRemoveAvatar(UInt64 dbid, Dictionary<UInt64, Dictionary<string, ob
407423
408424 public void onDisconnected ( )
409425 {
426+ err ( "disconnect! will try to reconnect...(你已掉线,尝试重连中!)" ) ;
427+ startRelogin = true ;
428+ Invoke ( "onReloginBaseappTimer" , 1.0f ) ;
429+ }
430+
431+ public void onReloginBaseappTimer ( )
432+ {
433+ if ( ui_state == 0 )
434+ return ;
435+
436+ KBEngineApp . app . reloginBaseapp ( ) ;
437+
438+ if ( startRelogin )
439+ Invoke ( "onReloginBaseappTimer" , 3.0f ) ;
410440 }
411441}
0 commit comments