unity, 模拟退后台
//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, 模拟退后台的更多相关文章
- flask设置cookie,设置session,模拟用户认证、模拟管理后台admin、模拟用户logout
设置cookie HTTP协议是无状态的,在一次请求响应结束后,服务器不会留下关于客户端状态的信息.但是对于某些web程序来说,客户端的信息有必要被记住,比如用户的登录状态,这样就可以根据用户的状态来 ...
- poj 1379 模拟退火法
/* 模拟退火法: 找到一些随机点,从这些点出发,随机的方向坐标向外搜索: 最后找到这些随机点的最大值: 坑://if(xx>-eps&&xx<x+eps&& ...
- [转]moveTaskToback退后台
http://blog.csdn.net/dacainiao007/article/details/17352367 方法:public boolean moveTaskToBack(boolean ...
- Ajax的post方法,模拟 从后台读取数据小demo
$(document).ready(function() { //定义一个函数 function timer() { $.post("1.json", function(data, ...
- Unity模拟龙之谷人物行走简单控制
我个人挺喜欢龙之谷(DN)的人物控制的(不是广告哈....),就是人物太萌了一点,动作.打击感都挺好的. 今天用Unity简单模仿了一下DN的人物控制,当然,游戏里面动作非常多,我这里仅仅做了简单的w ...
- 一次UNITY闪退问题的定位心得
最近项目测试发现,运行unity后不退出运行模式,玩了一局后点击 “再来一局”,反复十几局后unity崩掉. 经观察,发现在这十几局的过程中,unity占用内存不断上升,由3.2G左右上升到3.6G左 ...
- (一)微信小程序之模拟调用后台接口踩过的坑
如下图标记的三个点 在调试过程中出现问题,特此记录. 1. 之前在浏览器测试接口习惯省略 http:// ,是因为浏览器默认有一个检测,在你输入的网址前面加http://,如果有就不加. 然而在微信小 ...
- angular js 模拟获取后台的数据
在这里我们把后台的数据用一个.json文件进行代替. 项目的目录结构如下: puDongLibraryLearning----ui-router-learning ---- data-------pe ...
- 单元测试模拟request后台
编写测试单元 @RunWith(SpringJUnit4ClassRunner.class) 让测试运行于Spring测试环境 @WebAppConfiguration是一个类级别的注释,用于声明Ap ...
随机推荐
- JDK5.0 特性-线程任务执行架构 ScheduledExecutorService
来自:http://www.cnblogs.com/taven/archive/2011/12/17/2291469.html import java.util.concurrent.Callable ...
- 用python解析pdf中的文本与表格【pdfplumber的安装与使用】
我们接触到的很多文档资料都是以pdf格式存在的,比如:论文,技术文档,标准文件,书籍等.pdf格式使得用机器从中提取信息格外困难. 为了解决这个问题,我找到了几种解决方案,最后选择了python上的p ...
- 有关/proc/uptime这个文件里两个参数所代表的意义
有关/proc/uptime这个文件里两个参数所代表的意义: [root@app ~]#cat /proc/uptime 3387048.81 3310821.00 第一个参数是代表从系统启动到现在的 ...
- Aerospike系列:2:商业版和社区版的比较
http://www.aerospike.com/products-services
- 基于py3和pymysql的数据库查询,查询某几列的数据
#python3 #xiaodeng #基于py3和pymysql的数据库查询,查询某几列的数据 import pymysql conn=pymysql.connect(....) cur=conn. ...
- Dynamic Lotusscript
Introduction This short article gives an introduction to the underrated Execute method that is avail ...
- 转 解决:error: Cannot find libmysqlclient_r under /usr/local/mysql.
配置php的时候出现以下问题解决方案 checking for MySQL support... yeschecking for specified location of the MySQL UNI ...
- 文本diff算法Patience Diff
一般在使用 Myers diff算法及其变体时, 对于下面这种例子工作不是很好, 让变化不易阅读, 并且容易导致合并冲突 void Chunk_copy(Chunk *src, size_t src_ ...
- Android 百度鹰眼轨迹SDK(v2.1.6)
闲聊 看过<鹰眼追击>这部电影的读者一定对"鹰眼"这台巨无霸计算机印象深刻,如今我们能够实现自己的鹰眼. 效果图 本篇为百度地图SDK第三篇博文 第一篇实现:Andro ...
- JS中文转换(UTF-8),url传递中文乱码解决
来源于:http://blog.csdn.net/kuangfengbuyi/article/details/45557437 js合成url时,如果参数是中文,传到struts2中会乱码,解决办法如 ...