zoukankan      html  css  js  c++  java
  • Unity3d OnApplicationPause与OnApplicationFocus

    在手机游戏其中,会碰到“强制暂停”,如:锁屏、接电话或短信之类的。假设“强制暂停”时间过长,网络游戏有时得又一次登录等事件。

    而Unity3d。Android Plugins中的UnityPlayer.UnitySendMessage,经測试在强制暂停时,OnPause、OnStop周期中UnitySendMessage无效。

    重点探索OnApplicationPause和OnApplicationFocus;

    OnApplicationPause,当程序暂停;

    OnApplicationFocus,当程序获得或失去焦点。

    经測试:

    强制暂停时,先 OnApplicationPause。后 OnApplicationFocus;

    又一次“启动”手机时,先OnApplicationFocus,后 OnApplicationPause;

    思路:

    1,定义两个bool

    isPause=false;

    isFocus=false;

    OnEnable();初始化:

    void OnEnable(){

    isPause=false;

    isFocus=false;

    }

    void OnApplicationPause(){

    #if UNITY_IPHONE || UNITY_ANDROID

    Debug.Log("OnApplicationPause  "+isPause+"  "+isFocus);

    if(!isPause)

    {

    // 强制暂停时。事件

    pauseTime();

    }

    else 

    {

    isFocus=true;

    }

    isPause=true;

    #endif

    }

    void OnApplicationFocus(){

    #if UNITY_IPHONE || UNITY_ANDROID

    Debug.Log("OnApplicationFocus  "+isPause+"  "+isFocus);

    if(isFocus)

    {

    // “启动”手机时。事件

    resumeList();

    isPause=false;

    isFocus=false;

    }

    if(isPause)

    {

    isFocus=true;

    }

    #endif

    }

  • 相关阅读:
    js MD5加密后的字符串
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    归并排序
    C#分解质因数
    C#找出第n到m个素数之间所有之和
    C#打印0到100的素数
    for循环练习
    express总结(一)
    Nodejs总结(一)
    Webpack配置及使用
  • 原文地址:https://www.cnblogs.com/lytwajue/p/6719442.html
Copyright © 2011-2022 走看看