Welcome to Unity Learning, unity training, Unity Enterprise training and education zone, there are many u3d resources, u3d training videos, u3d tutorials, U3d Frequently asked questions, U3d Project source code, we are committed to creating the industry Unity3d training, learning the first brand.
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
}
For more highlights, please click http://www.gopedu.com/
Unity3d Onapplicationpause and Onapplicationfocus judge whether the game is paused or restarted