Hi, I can’t figure out how to convert keyboard height to real size in game. I got keyboard height by native plugin and send it to Unity, smth like that:
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int screenHeight = rootView.getRootView().getHeight();
keyboardHeight = screenHeight - r.bottom;
boolean bKeyOpen = (keyboardHeight > screenHeight * 0.15);
float fKeyHeight = (float) keyboardHeight / (float) screenHeight;
JSONObject json = new JSONObject();
try {
json.put("msg", MSG_SHOW_KEYBOARD);
json.put("show", bKeyOpen);
json.put("keyheight", fKeyHeight);
} catch (JSONException e) {
}
SendUnityMessage(json);
}
});
When plugin receive message, it converts to:
nKeyHeight = (int)( jsonMsg["keyheight"] * (float) Screen.height);
And after that, I want to set my gameobject above keyboard, but size is not correct. For example, I got keyboard height 746 on my Nexus 5. And when I set gameobject on it (vector2 (0, 746)) it appears not above keyboard.
So, pls, explain me how can I convert that value correctly?
