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 ...
随机推荐
- MobX快速入门教程(重要概念讲解)
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7372119.html 一:Mobx工作流程图 二:MobX涉及到的概念 1:状态state 组件中的数据. 2 ...
- cocos2d-js 3.0 rc0 编译release报错 value for keystore is not valid. it must resolve to a single path
第一次编译是好好的,需要手工输入keystore文件地址和密码等等.第二次不需要输入,然后就直接出错了. 找了一下,发现第一步之后,cocos会记录ant信息到\frameworks\runtim ...
- Selenium 的基础框架类
个人写的一个selenium的base类,应该所有使用selenium的同事都会使用到: package com.hx.baserunner; import static java.io.File.s ...
- jQuery get selected text from SELECT (or DROPDOWN) list box
Most of the time in JavaScript we want to do following things with Select (or dropdown) list box. – ...
- ios中键盘处理(二)
设置UIscrollview的背景代码 - (UIImage *) ImageWithColor: (UIColor *) color frame:(CGRect)aFrame { UIGraphic ...
- (原)ubuntnu中anaconda的g++提示crtbeginS.o:unrecognized relocation
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6950263.html 自从使用anaconda后,方便是方便了,也遇到了很多蛋疼的问题. 这次使用an ...
- Struts2常见配置(草稿)
Struts2框架配置文件加载的顺序(了解加载配置文件的顺序,重点掌握struts.xml配置文件) 1.Struts2框架的核心是StrutsPrepareAndExecuteFilter过滤器,该 ...
- [转]NLP Tasks
Natural Language Processing Tasks and Selected References I've been working on several natural langu ...
- 最新CoreData封装Demo
1.创建CoreData文件 2. 3. 4. UploadCoreDataAPI.h // // UploadCoreDataAPI.h // dsafsda // // Created by 冯敏 ...
- Fedora23 chrome 安装
添加FZUG源终端:进入到root1.下载google-chrome.repo并保存$wget http://repo.fdzh.org/chrome/google-chrome-mirrors.re ...