RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Unity3d失去获取焦点,暂停-创新互联

目前在用tolua进行项目开发,C#与lua交互的部分消息使用了注册监听处理,监听方法均放到Update方法里面进行处理,问题在于失去焦点后Update方法将不继续执行,这就导致了监听方法未能及时调用。

创新互联致力于网站制作、成都网站建设,成都网站设计,集团网站建设等服务标准化,推过标准化降低中小企业的建站的成本,并持续提升建站的定制化服务水平进行质量交付,让企业网站从市场竞争中脱颖而出。 选择创新互联,就选择了安全、稳定、美观的网站建设服务!

   例如:AB玩家进行纸牌游戏,A接到电话并失去焦点,Update不执行导致消息未能及时通知服务器,此时B未能及时收到A的状态误以为A还在打牌状态。

   此外Android Plugins中的UnityPlayer.UnitySendMessage,经测试在强制暂停时,OnPause、OnStop周期中UnitySendMessage无效。(个人未测)

   故要特殊处理这两个方法,现改成C#直接调用lua方法,去掉监听推送这一步。

   C#:
   /// 
    /// 当程序获得或者是去焦点时
    /// 
    /// 
    public void OnApplicationFocus(bool focus)
    {
        try
        {
            LuaManager.CallFunc_Void("MineMessageCenter.OnApplicationFocus", focus);
        }
        catch (System.Exception)
        {
            
            throw;
        }

        //Debug.logger.Log("焦点:" + focus);
        //if (focus)
        //{
        //    MessageCenter.GetInstance().PostEvent(EventNameDefine.GetFocusEvent);
        //}
        //else
        //{
        //    MessageCenter.GetInstance().PostEvent(EventNameDefine.LostFocusEvent);
        //}
    }
    
       /// 
    /// 当程序暂停
    /// 
    /// 
    public void OnApplicationPause(bool isPause)
    {
        try
        {
            LuaManager.CallFunc_Void("MineMessageCenter.OnApplicationPause", isPause);
        }
        catch (System.Exception)
        {

            throw;
        }
       
        //Debug.logger.Log("暂停:" + isPause);
        //if (isPause)
        //{
        //    MessageCenter.GetInstance().PostEvent(EventNameDefine.GetPauseEvent);
        //}
        //else
        //{
        //    MessageCenter.GetInstance().PostEvent(EventNameDefine.LostPauseEvent);
        //}
    }
Lua:
--当程序获得或者是去焦点时
function MineMessageCenter.OnApplicationFocus(focus)
print("焦点:"..tostring(focus));
end 

--当程序暂停
function MineMessageCenter.OnApplicationPause(isPause)
--print("暂停:"..tostring(isPause));
end

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:Unity3d失去获取焦点,暂停-创新互联
文章出自:http://sczitong.cn/article/gdehc.html