表现
主场景第一次打开后点击text正常打开键盘,跳转场景后在第二个场景或者再跳转回主场景都无法打开vr键盘
问题所在
ImeManager下的OnApplicationFocus只在第一次进入场景聚焦时触发,导致开关mIsFocus在跳转场景后无法设置true,删除该参数,调整一下即可
关于该OnApplicationFocus函数的官方解释链接:https://docs.unity.cn/cn/current/ScriptReference/MonoBehaviour.OnApplicationFocus.html
修改后脚本如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ImeManager : MonoBehaviour
{
public ImeDelegateBase mDelegate;
private ImeBase mIme;
private Vector2 mSize;
private bool mIsStart = false;
//MonoBehaviour
void Start()
{
if (null != mDelegate)
{
#if UNITY_EDITOR
mIme = new DummyIme();
#else
mIme = new SGIme();
#endif
mIme.Create(mDelegate);
}
mIsStart = true;
}
void Update()
{
if (null == mIme)
{
return;
}
if (mIsStart)
{
mIme.UpdateData();
}
}
//export
public void Show(SGImeInputType typeInput, SGImeTextType typeText)
{
mIme.Show(typeInput, typeText);
mIme.GetSize(ref mSize);
}
public void Hide()
{
mIme.Hide();
mDelegate.OnIMEHide();
}
public void Draw(Texture2D tex)
{
mIme.Draw(tex);
}
public void OnTouch(float x, float y, SGImeMotionEventType type)
{
mIme.OnTouch(x, y, type);
}
private void OnDestroy()
{
mIsStart = false;
mIme = null;
}
void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
Hide();
}
}
}