In mobile games, there will be "forced pauses", such as: lock screen, answer phone or text messages. Suppose that the "forced pause" is too long, the online game sometimes has to log in again and other events.
and Unity3d. Unityplayer.unitysendmessage in Android plugins, tested on a forced pause, OnPause, OnStop period unitysendmessage invalid.
Focus on exploring onapplicationpause and Onapplicationfocus;
Onapplicationpause, when the program is paused;
Onapplicationfocus, when the program Gets or loses focus.
Tested:
Onapplicationpause is forced to pause first. After Onapplicationfocus;
Once again "starts" the handset, first onapplicationfocus, after Onapplicationpause;
Ideas:
1, definition of two bool
Ispause=false;
Isfocus=false;
In
Onenable (); Initialize:
void Onenable () {
Ispause=false;
Isfocus=false;
}
void Onapplicationpause () {
#if Unity_iphone | | Unity_android
Debug. Log ("Onapplicationpause"+ispause+ ""+isfocus);
if (!ispause)
{
When the force is paused. Event
Pausetime ();
}
else
{
Isfocus=true;
}
Ispause=true;
#endif
}
void Onapplicationfocus () {
#if Unity_iphone | | Unity_android
Debug. Log ("Onapplicationfocus"+ispause+ ""+isfocus);
if (Isfocus)
{
When you start the phone. Event
Resumelist ();
Ispause=false;
Isfocus=false;
}
if (Ispause)
{
Isfocus=true;
}
#endif
}
Unity3d Onapplicationpause and Onapplicationfocus