unity隐藏android机的虚拟按钮

启动时 将下面有脚本挂载某个物件就行:

 

using UnityEngine;
using System.Collections;

public class HideAndroidButtons : MonoBehaviour
{
	#if UNITY_ANDROID && !UNITY_EDITOR
	const int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 4096;
	const int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 2;
	const int SYSTEM_UI_FLAG_FULLSCREEN = 4;
	
	AndroidJavaObject decorView;
	
	void Start()
	{
		AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
		AndroidJavaObject activity = jc.GetStatic("currentActivity");
		AndroidJavaObject window = activity.Call("getWindow");
		decorView = window.Call("getDecorView");
		
		TurnImmersiveModeOn();
	}
	void OnApplicationFocus(bool focusStatus) {
		if(focusStatus){
			TurnImmersiveModeOn();
		}
	}
	void TurnImmersiveModeOn()
	{
		decorView.Call("setSystemUiVisibility", SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
	}
	void OnDestroy()
	{
		decorView.Dispose();
	}
	#endif
}

你可能感兴趣的:(unity隐藏android机的虚拟按钮)