Unity Application 前后台切换调用关系

Unity Application 前后台切换调用关系

1、OnApplicationPause

  Sent to all GameObjects when the application pauses.

  On Android, when the on-screen keyboard is enabled, it causes a OnApplicationFocus( false ) event. Additionally, if you press "Home" at the moment the keyboard is enabled, the OnApplicationFocus() event is not called, but OnApplicationPause() is called instead.

2、OnApplicationFocus

  Sent to all GameObjects when the player gets or loses focus.

  OnApplicationFocus is called when the application loses or gains focus. Alt-tabbing or Cmd-tabbing can take focus away from the Unity application to another desktop application. This causes the GameObjects to receive an OnApplicationFocus call with the argument set to false. When the user switches back to the Unity application, the GameObjects receive anOnApplicationFocus call with the argument set to true.

  On Android, when the on-screen keyboard is enabled, it causes a OnApplicationFocus( false ) event. Additionally, if you pressHome at the moment the keyboard is enabled, the OnApplicationFocus() event is not called, but OnApplicationPause() is called instead.

3、OnApplicationQuit

  Sent to all game objects before the application is quit.

  In the editor this is called when the user stops playmode.

  Note that iOS applications are usually suspended and do not quit. You should tick "Exit on Suspend" in Player settings for iOS builds to cause the game to quit and not suspend, otherwise you may not see this call. If "Exit on Suspend" is not ticked then you will see calls to OnApplicationPause instead.

参考:http://blog.csdn.net/aa4790139/article/details/48087877