美文网首页
Unity切入后台,切入前台,获取焦点,失去焦点等

Unity切入后台,切入前台,获取焦点,失去焦点等

作者: codingriver | 来源:发表于2018-01-11 15:09 被阅读112次

正常进:

OnApplicationFocus, isFocus=True

正常退:

OnApplicationQuit

Home出:

OnApplicationPause, isPause=True

OnApplicationFocus, isFocus=False

Home进:

OnApplicationPause, isPause=False
OnApplicationFocus, _isFocus=True

Kill进程:

当前应用双击Home,然后Kill:

OnApplicationQuit (IOS 有回调,android 没回调)

跳出当前应用,然后Kill:

OnApplicationQuit (IOS和Android都没回调)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameApp : MonoBehaviour {

    void Awake()
    {
        //Debug.Log("awake:::::::::");
    }
    // Use this for initialization
    void Start () {
    }
    
    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Dg.Log("Input.GetKeyDown:::KeyCode.Escape");
            //Application.Quit();  
            //ProviderService.Instance.OnBackPressedE("KeyCode.Escape");
        }
            
    }

    void LateUpdate()
    {
        //Debug.Log("LateUpdate^^^^^^^^^^^^^");
    }

    void FixedUpdate()
    {
        //Debug.Log("FixedUpdate^^^^^^^^^^^^^");
    }
    void OnDestroy()
    {

    }


    void OnApplicationFocus(bool hasFocus)
    {
        //Dg.Log("OnApplicationFocus,hasFocus:", hasFocus);
    }


    void OnApplicationPause(bool pauseStatus)
    {
        Dg.Log("OnApplicationPause,pauseStatus:", pauseStatus);
    }


    void OnApplicationQuit()
    {
        Dg.Log("OnApplicationQuit");

    }
}

相关文章

网友评论

      本文标题:Unity切入后台,切入前台,获取焦点,失去焦点等

      本文链接:https://www.haomeiwen.com/subject/dsttoxtx.html