├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── Scripts.meta ├── Scripts ├── SoftwareKeyboardArea.cs ├── SoftwareKeyboardArea.cs.meta ├── UniSoftwareKeyboardArea.asmdef └── UniSoftwareKeyboardArea.asmdef.meta ├── package.json └── package.json.meta /LICENSE.md: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 633fbcef9d507f14d9ee1ac87a2716e4 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Uni Software Keyboard Area 2 | 3 | Android でもソフトウェアキーボードの表示領域を取得できるパッケージ 4 | 5 | ## 使用例 6 | 7 | ```cs 8 | using UniSoftwareKeyboardArea; 9 | using UnityEngine; 10 | using UnityEngine.UI; 11 | 12 | public class Test : MonoBehaviour 13 | { 14 | public CanvasScaler m_canvasScaler; 15 | public RectTransform m_rectTransform; 16 | 17 | private void Update() 18 | { 19 | var rate = m_canvasScaler.referenceResolution.y / Screen.height; 20 | var pos = m_rectTransform.anchoredPosition; 21 | pos.y = SoftwareKeyboardArea.GetHeight( true ) * rate; 22 | m_rectTransform.anchoredPosition = pos; 23 | } 24 | 25 | private void OnGUI() 26 | { 27 | GUILayout.Label( SoftwareKeyboardArea.GetHeight( true ).ToString() ); 28 | } 29 | } 30 | ``` 31 | 32 | ![Image (18)](https://user-images.githubusercontent.com/6134875/81075696-a56a7200-8f25-11ea-8c95-d91cc3af8cb9.gif) 33 | 34 | ## 謝辞 35 | 36 | * このリポジトリは下記のサイト様を参考にさせていただいております 37 | * https://forum.unity.com/threads/keyboard-height.291038/ -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 829281d79f4be4c4ca6aefa747d65bdf 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df5ce41333332ac4db6c48a144086511 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/SoftwareKeyboardArea.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace UniSoftwareKeyboardArea 4 | { 5 | /// 6 | /// ソフトウェアキーボードの表示領域を管理するクラス 7 | /// 8 | public static class SoftwareKeyboardArea 9 | { 10 | //================================================================================ 11 | // プロパティ(static) 12 | //================================================================================ 13 | /// 14 | /// 高さを返します 15 | /// 16 | public static int GetHeight() 17 | { 18 | return GetHeight( false ); 19 | } 20 | 21 | /// 22 | /// 高さを返します 23 | /// 24 | public static int GetHeight( bool includeInput ) 25 | { 26 | #if !UNITY_EDITOR && UNITY_ANDROID 27 | using ( var unityClass = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" ) ) 28 | { 29 | var currentActivity = unityClass.GetStatic( "currentActivity" ); 30 | var unityPlayer = currentActivity.Get( "mUnityPlayer" ); 31 | var view = unityPlayer.Call( "getView" ); 32 | 33 | if ( view == null ) return 0; 34 | 35 | int result; 36 | 37 | using ( var rect = new AndroidJavaObject( "android.graphics.Rect" ) ) 38 | { 39 | view.Call( "getWindowVisibleDisplayFrame", rect ); 40 | result = Screen.height - rect.Call( "height" ); 41 | } 42 | 43 | if ( !includeInput ) return result; 44 | 45 | var softInputDialog = unityPlayer.Get( "mSoftInputDialog" ); 46 | var window = softInputDialog?.Call( "getWindow" ); 47 | var decorView = window?.Call( "getDecorView" ); 48 | 49 | if ( decorView == null ) return result; 50 | 51 | var decorHeight = decorView.Call( "getHeight" ); 52 | result += decorHeight; 53 | 54 | return result; 55 | } 56 | #else 57 | var area = TouchScreenKeyboard.area; 58 | var height = Mathf.RoundToInt( area.height ); 59 | return Screen.height <= height ? 0 : height; 60 | #endif 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Scripts/SoftwareKeyboardArea.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d78078277a035940ae63fb532ded08d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/UniSoftwareKeyboardArea.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "UniSoftwareKeyboardArea" 3 | } 4 | -------------------------------------------------------------------------------- /Scripts/UniSoftwareKeyboardArea.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c78fad5ffa090e4d9969bafdfb2d70d 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.baba-s.uni-software-keyboard-area", 3 | "displayName": "UniSoftwareKeyboardArea", 4 | "version": "1.0.0", 5 | "unity": "2019.2", 6 | "author": "baba-s" 7 | } -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b10add5bb67e7749a19cf7357572057 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------