Currently in the project development with Tolua, C # and LUA to interact with the part of the message using registered listening processing, the listener method is put into the Update method to deal with, the problem is that the Update method will not continue to execute after the loss of focus, which led to the interception method is not timely call.
For example: AB player card Game, a received a call and lost focus, update does not execute caused the message failed to notify the server, at this time B failed to receive a status mistakenly thought A is still playing cards.
In addition to the Unityplayer.unitysendmessage in Android plugins, tested on forced pauses, unitysendmessage is not valid in OnPause, OnStop cycles. (Individual not tested)
Therefore, the special treatment of these two methods, is now changed to C # Direct call Lua method, remove the listener push this step.
C#: /// <summary> /// when the program Gets or goes to focus /// </summary> /// <param name= "Focus" ></param> public void onapplicationfocus (Bool focus) { try { luamanager.callfunc_void ( "Minemessagecenter.onapplicationfocus", focus); } catch (System.Exception) { throw; } //debug.logger.log ("Focus:" + focus); //if (Focus) //{ // messagecenter.getinstance (). Postevent (eventnamedefine.getfocusevent); //} //else //{ // messagecenter.getinstance (). Postevent (eventnamedefine.lostfocusevent); //} } /// <summary> /// when the program pauses /// </summary> /// <param name= "Focus" ></param> public void onapplicAtionpause (Bool ispause) { try { luamanager.callfunc_void ("Minemessagecenter.onapplicationpause", ispause); } catch (System.Exception) { throw; } //debug.logger.log ("pause:" + ispause); //if (Ispause) //{ // messagecenter.getinstance (). Postevent (Eventnamedefine.getpauseeveNT); //} //else //{ // messagecenter.getinstance (). Postevent (eventnamedefine.lostpauseevent); //} }
lua:--function Minemessagecenter.onapplicationfocus (focus) Print when the program Gets or goes to focus: ToString (focus); end--When the program pauses function minemessagecenter.onapplicationpause (ispause)--print ("Pause:"). ToString (Ispause)); end
This article is from the "Wo Love Money" blog, please be sure to keep this source http://mozhenrui.blog.51cto.com/11845221/1977067
Unity3d loses focus, pauses