Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created June 8, 2017 08:46
Show Gist options
  • Save baba-s/f18ab57089be7ed9ca45da870e5ee6fd to your computer and use it in GitHub Desktop.
Save baba-s/f18ab57089be7ed9ca45da870e5ee6fd to your computer and use it in GitHub Desktop.
using UnityEngine;
namespace Cham
{
/// <summary>
/// ソフトウェアキーボードの表示領域を管理するクラス
/// </summary>
public static class SoftwareKeyboaryArea
{
/// <summary>
/// 高さを返します
/// </summary>
public static int Height
{
get
{
#if !UNITY_EDITOR && UNITY_ANDROID
using ( var unityPlayer = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" ) )
{
var view = unityPlayer
.GetStatic<AndroidJavaObject>( "currentActivity" )
.Get<AndroidJavaObject>( "mUnityPlayer" )
.Call<AndroidJavaObject>( "getView" )
;
using ( var rect = new AndroidJavaObject( "android.graphics.Rect" ) )
{
view.Call( "getWindowVisibleDisplayFrame", rect );
return Screen.height - rect.Call<int>( "height" );
}
}
#else
return ( int )TouchScreenKeyboard.area.height;
#endif
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment