Skip to content

Instantly share code, notes, and snippets.

@kazumalab
Last active October 4, 2019 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazumalab/704949bacc477a126381d3915625a329 to your computer and use it in GitHub Desktop.
Save kazumalab/704949bacc477a126381d3915625a329 to your computer and use it in GitHub Desktop.
sample class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestInput : MonoBehaviour
{
private Image image;
private Vector2 initPosition;
private InputField inputField;
private bool isActive = false;
private void Start()
{
image = GetComponent<Image>();
inputField = GetComponentInChildren<InputField>();
initPosition = image.rectTransform.anchoredPosition;
}
private void Update()
{
if(!isActive && this.inputField.isFocused)
{
isActive = true;
InputStart();
}
if(isActive && !this.inputField.isFocused)
{
isActive = false;
InputEnd();
}
}
public void InputStart()
{
TouchScreenKeyboard.hideInput = false;
float height = TouchScreenKeyboard.area.height;
Debug.Log("height >> " + height);
image.rectTransform.anchoredPosition = Vector2.up * height;
}
public void InputEnd()
{
image.rectTransform.anchoredPosition = initPosition;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment