Unity3d Onapplicationpause and Onapplicationfocus

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.