In mobile games, you will encounter a "forced pause", such as: lock screen, answer phone or text messages. If the "force pause" time is too long, online games sometimes have to log back in and other events.
In the case of Unity3d,android plugins, Unityplayer.unitysendmessage is tested on a forced pause, OnStop is invalid during OnPause and Unitysendmessage cycles.
Focus on exploring onapplicationpause and Onapplicationfocus;
Onapplicationpause, when the program is paused;
Onapplicationfocus, when the program gains or loses focus;
Tested By:
Forced suspension, first Onapplicationpause, after Onapplicationfocus;
Re-"Start" the phone, 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 a force is paused, the 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, the event
Resumelist ();
Ispause=false;
Isfocus=false;
}
if (ispause)
{
Isfocus=true;
}
#endif
}
Unity3d Onapplicationpause and Onapplicationfocus.