unity 项目强制退出通知服务器,MonoBehaviour.OnApplicationQuit() 当应用程序退出 - Unity5 中文 API 手册...

Description 描述

Sent to all game objects before the application is quit.

在应用退出之前发送给所有的游戏物体。

In the editor this is called when the user stops playmode. In the web player it is called when the web view is closed.

当用户停止运行模式时在编辑器中调用。当web被关闭时在网络播放器中被调用。

JavaScript:

function OnApplicationQuit() {

// Make sure prefs are saved before quitting.

PlayerPrefs.Save();

}

C#:

using UnityEngine;

using System.Collections;

public class ExampleClass : MonoBehaviour {

void OnApplicationQuit() {

PlayerPrefs.Save();

}

}

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.

注意,iOS程序通常暂停并不退出。你应该在Player settings中的iOS编译设置中选择Exit on Suspend(暂停时退出),这会使游戏退出并不会暂停,否则会看不到这个调用。如果Exit on Suspend不选择,应该使用OnApplicationPause替代。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值