Unity3d loses focus, pauses

Source: Internet
Author: User
Tags lua

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

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.