[Unity]最近遇到的几个问题.(不间断更新)

1.隐藏虚拟键盘,即Navigation/System Bar.

原文:Hiding the navigation/system bar in Android

protected void onCreate(Bundle paramBundle)
{
    requestWindowFeature(1);

    super.onCreate(paramBundle);

    getWindow().takeSurface(null);
    setTheme(16973831);
    getWindow().setFormat(4);
    this.mUnityPlayer = new UnityPlayer(this);

    if (this.mUnityPlayer.getSettings().getBoolean("hide_status_bar", true))
    {
        getWindow().setFlags(1024, 1024);
    }

    setContentView(this.mUnityPlayer);
    this.mUnityPlayer.requestFocus();
}

另外一种解决方案(之前使用的这种)

private int currentApiVersion;

// 丢入OnCreate中用来隐藏虚拟按键
private void HideNavigationBar()
{
    // This work only for android 4.4+
    if (currentApiVersion >= Build.VERSION_CODES.KITKAT)
    {
        currentApiVersion = android.os.Build.VERSION.SDK_INT;

        final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | 
                          View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | 
                          View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | 
                          View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | 
                          View.SYSTEM_UI_FLAG_FULLSCREEN | 
                          View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        getWindow().getDecorView().setSystemUiVisibility(flags);

        // Code below is to handle presses of Volume up or Volume down.
        // Without this, after pressing volume buttons, the navigation bar
        // will
        // show up and won't hide
        final View decorView = getWindow().getDecorView();

        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
        {
            @Override
            public void onSystemUiVisibilityChange(int visibility)
            {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
                {
                    decorView.setSystemUiVisibility(flags);
                }
            }
        });
    }
}

// @SuppressLint("NewApi")
// @Override
public void onWindowFocusChanged(boolean hasFocus)
{
    super.onWindowFocusChanged(hasFocus);

    if(currentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
    {
        getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE       |
        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  |
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN   |
        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | 
        View.SYSTEM_UI_FLAG_FULLSCREEN  | 
        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}

2. Unsupported major.minor version 52.0.

出现这个问题的原因貌似是因为我更新了一下AndroidStudio….然后jdk出现了错误.
根据Google以及百度的答案是因为Jdk不匹配,所以解决方案是更新Jdk.

3.Unity用dll加载慢.

在dll的属性中加上
[assembly: UnityEngine.UnityAPICompatibilityVersion(“5.4.0f3”)]

4.获取某个方法执行时间.

using UnityEngine;
using System.Collections;
using System.Diagnostics;

public class NewBehaviourScript : MonoBehaviour 
{
    void Start () 
    {
        float t = Time.time;
        TestMethod();
        UnityEngine.Debug.Log(string.Format("total: {0} ms",Time.time - t));

        Stopwatch sw = new Stopwatch();
        sw.Start();
        TestMethod();
        sw.Stop();
        UnityEngine.Debug.Log(string.Format("total: {0} ms",sw.ElapsedMilliseconds));


        Profiler.BeginSample("TestMethod");
        TestMethod();
        Profiler.EndSample();
    }

    void TestMethod()
    {
        for(int i =0; i < 10000000; i++)
        {
        }
    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值