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++)
{
}
}
}