zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    autoLayout适配
    iOS FMDB 无法更新二进制数据的问题
    iOS 数据库操作崩溃提示“ int rc = sqlite3_step([_statement statement]);”或者提示“ rc = sqlite3_step(pStmt);”
    iOS点击cell时,控件背景色消失的解决方法
    UISegmentedControl 的使用
    自定义cell侧滑删除
    iOS设置cell选中时文字颜色的变化
    iOS 如何在Label中显示html的文本
    iOS 单例的销毁
    类似微信聊天界面加载历史记录的样式
  • 原文地址:https://www.cnblogs.com/wantnon/p/6283867.html
Copyright © 2011-2022 走看看