using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[RequireComponent(typeof(RectTransform))]
public class AdapterKeyboardLayout : UIBehaviour
{
///
/// 必须设置值,判断是由哪个InputField发起的
///
public InputField m_InputField;
///
/// 在适配虚拟键盘时,对齐的点, 默认为InputField
///
public RectTransform anchorTransform;
///
/// 在适配虚拟键盘时,做偏移的对象, , 默认为Self
///
public RectTransform offsetTransform;
private Canvas m_Canvas;
private RectTransform m_OffsetParentTransform;
private Vector3 m_AnchorPos;
private Vector3 m_OffsetInitPos;
private Vector2 m_OffsetScreePos = Vector2.zero;
private bool m_LastVisible = false;
private bool IsNeedGetHight = true;
private int m_KeyboardHeight_int = 0;
public Canvas canvas
{
get
{
if (this.m_Canvas == null)
{
this.CacheCanvas();
}
return this.m_Canvas;
}
}
protected override void OnEnable()
{
base.OnEnable();
if (!m_InputField)
{
enabled = false;
Debug.LogError("InputField is Null", gameObject);
return;
}
if (!anchorTransform) anchorTransform = (RectTransform)m_InputField.transform;
if (!offsetTransform) offsetTransform = (RectTransform)transform;
Transform parent = offsetTransform.parent;
if (!parent)
{
enabled = false;
Debug.LogError("offsetTransform's parent is Null", gameObject);
return;
}
m_OffsetParentTransform = (RectTransform)parent;
}
protected override void OnTransformParentChanged()
{
base.OnTransformParentChanged();
m_Canvas = null;
}
protected override void OnCanvasHierarchyChanged()
{
m_Canvas = null;
}
private void CacheCanvas()
{
List