//simulateSwitchToBackground.cs

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class simulateSwitchToBackground : MonoBehaviour {
void sendApplicationPauseMessage(bool isPause){
Transform[] transList= GameObject.FindObjectsOfType<Transform>(); 
for (int i = 0; i < transList.Length; i++) {
Transform trans = transList [i];
//Note that messages will not be sent to inactive objects
trans.SendMessage ("OnApplicationPause",isPause,SendMessageOptions.DontRequireReceiver);
}
}
void sendApplicationFocusMessage(bool isFocus){
Transform[] transList= GameObject.FindObjectsOfType<Transform>(); 
for (int i = 0; i < transList.Length; i++) {
Transform trans = transList [i];
//Note that messages will not be sent to inactive objects
trans.SendMessage ("OnApplicationFocus",isFocus,SendMessageOptions.DontRequireReceiver);
}
}

public void sendEnterBackgroundMessage(){
sendApplicationPauseMessage (true);
sendApplicationFocusMessage (false);

}
public void sendEnterFoegroundMessage(){
sendApplicationFocusMessage (true);
sendApplicationPauseMessage (false);

}

}

//simulateSwitchToBackgroundEditor.cs

using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(simulateSwitchToBackground))]
public class simulateSwitchToBackgroundEditor : Editor
{

void OnEnable(){
}

public override void OnInspectorGUI()
{

DrawDefaultInspector();
serializedObject.Update ();

serializedObject.ApplyModifiedProperties ();//now varibles in script have been updated

if (GUILayout.Button ("send enter background message")) {
if (Application.isPlaying) {
((simulateSwitchToBackground)target).sendEnterBackgroundMessage ();
}
}
if (GUILayout.Button ("send enter foeground message")) {
if (Application.isPlaying) {
((simulateSwitchToBackground)target).sendEnterFoegroundMessage ();
}
}
}

}

把simulateSwitchToBackground.cs挂到场景中的一个gameObject上,其inspector面板如下:

在游戏运行过程中点“send endter background message”按钮,即模拟游戏退到后台。再点"send enter foeground message"按钮,模拟游戏从后台切回到前台。

参考:

http://www.voidcn.com/blog/goodai007/article/p-5804722.html

unity, 模拟退后台的更多相关文章

  1. flask设置cookie,设置session,模拟用户认证、模拟管理后台admin、模拟用户logout

    设置cookie HTTP协议是无状态的,在一次请求响应结束后,服务器不会留下关于客户端状态的信息.但是对于某些web程序来说,客户端的信息有必要被记住,比如用户的登录状态,这样就可以根据用户的状态来 ...

  2. poj 1379 模拟退火法

    /* 模拟退火法: 找到一些随机点,从这些点出发,随机的方向坐标向外搜索: 最后找到这些随机点的最大值: 坑://if(xx>-eps&&xx<x+eps&& ...

  3. [转]moveTaskToback退后台

    http://blog.csdn.net/dacainiao007/article/details/17352367 方法:public boolean moveTaskToBack(boolean ...

  4. Ajax的post方法,模拟 从后台读取数据小demo

    $(document).ready(function() { //定义一个函数 function timer() { $.post("1.json", function(data, ...

  5. Unity模拟龙之谷人物行走简单控制

    我个人挺喜欢龙之谷(DN)的人物控制的(不是广告哈....),就是人物太萌了一点,动作.打击感都挺好的. 今天用Unity简单模仿了一下DN的人物控制,当然,游戏里面动作非常多,我这里仅仅做了简单的w ...

  6. 一次UNITY闪退问题的定位心得

    最近项目测试发现,运行unity后不退出运行模式,玩了一局后点击 “再来一局”,反复十几局后unity崩掉. 经观察,发现在这十几局的过程中,unity占用内存不断上升,由3.2G左右上升到3.6G左 ...

  7. (一)微信小程序之模拟调用后台接口踩过的坑

    如下图标记的三个点 在调试过程中出现问题,特此记录. 1. 之前在浏览器测试接口习惯省略 http:// ,是因为浏览器默认有一个检测,在你输入的网址前面加http://,如果有就不加. 然而在微信小 ...

  8. angular js 模拟获取后台的数据

    在这里我们把后台的数据用一个.json文件进行代替. 项目的目录结构如下: puDongLibraryLearning----ui-router-learning ---- data-------pe ...

  9. 单元测试模拟request后台

    编写测试单元 @RunWith(SpringJUnit4ClassRunner.class) 让测试运行于Spring测试环境 @WebAppConfiguration是一个类级别的注释,用于声明Ap ...

随机推荐

  1. nginx做负载均衡,验证码总是不对(2台服务器)

    问题原因:页面中有错误链接,导致跳转到另一台服务器,验证码显示的确是刚开始访问的 (有的静态文件一边没有,就需要去另外一边找,然后就跳了.) 解决方法:把静态文件都提取到了nginx上就解决了.

  2. 跟踪 Ring3 - Ring0 的运行流程

    理论知识 SYSENTER 指令是在 Inter Pentium(R) Ⅱ 处理器上作为"高速系统调用"功能的一部分被首次引用的. SYSENTER 指令进行过专门的优化,能够以最 ...

  3. 顺利编译 binutiles-gcc-glibc

    恩,前面一篇弃了,先知道怎么能成功,还有要避开哪些坑,然后再去仔细研究到底咋回事. 这里顺利编译 arm-lfs-linux-gnueabi , 参考了下面的资料: 1. <Linux From ...

  4. Mysql查询优化之 触发器加中间表 方法优化count()统计大数据量总数问题

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6138288.html 在上一篇博文我们提到,分页有三种方法.其中,第三种是我们最常用的.然而,在实际应用过程中 ...

  5. not available in automatic reference counting mode

    UncaughtExceptionHandler.m:156:47: 'autorelease' is unavailable: not available in automatic referenc ...

  6. iOS中TableView小技巧

    摘要: TableView是ios开发中经经常使用到的控件,这里统一记录一下开发中遇到的经常使用小技巧,不断探索更新.也希望大家能够告诉我很多其它经常使用的小技巧啦~一起进步 1.去除多余的列表线条 ...

  7. Unbound服务的安装与运行管理

    一.Unbound服务的安装与运行管理 1.获取Unbound软件包 RHEL7.x自带了Bind和Unbound两种DNS服务包,Unbound是红帽公司推荐使用的DNS服务器.目前,虽然Bind在 ...

  8. springboot自定义jdbc操作库+基于注解切点AOP

    发布时间:2018-11-08   技术:springboot+aop   概述 springBoot集成了自定义的jdbc操作类及AOP,因为spring自带的JdbcTemplate在实际项目中并 ...

  9. HTML5 Audio标签方法和函数API介绍

    问说网 > 文章教程 > 网页制作 > HTML5 Audio标签方法和函数API介绍 Audio APIHTML5HTML5 Audio预加载 HTML5 Audio标签方法和函数 ...

  10. iOS UILabel设置行间距和字间距

    实现UILabel的文字,设置行间距和字间距. 效果图: 代码: let lblTitle = UILabel(frame: CGRect(x: , y: , width: KScreenWidth- ...