1、解决dropdown只有点击选项时能够关闭下拉框的问题
a、让dropdown点击自己时能够关闭下拉框
修改TMP_DropDowm.cs:741行
public virtual void OnPointerClick(PointerEventData eventData)
{
if (!IsActive() || !IsInteractable() || m_Dropdown != null)
Hide();
else
Show();
}
b、点击其他位置时关闭下拉框
修改 Pointer3DInputModule.cs增加控件用于记录上一次点击的控件
private static GameObject lastPress = null;
点击时调用上一个控件的onCancel.修改 Pointer3DInputModule.cs:468行
// PointerClick and Drop events
if (eventData.pointerPress == pointerUpHandler && eventData.eligibleForClick)
{
if(lastPress != null)
ExecuteEvents.Execute(lastPress, eventData, ExecuteEvents.cancelHandler);
lastPress = eventData.pointerPress;
ExecuteEvents.Execute(eventData.pointerPress, eventData, ExecuteEvents.pointerClickHandler);
}
else if (eventData.pointerDrag != null && eventData.dragging)
{
ExecuteEvents.ExecuteHierarchy(currentOverGo, eventData, ExecuteEvents.dropHandler);
}
2、解决InputField使用软键盘无法删除最后一个字符的问题
软键盘删除掉所有字符后,调用activeKeyboard.text发现会获取到最后一个字符。
a.在弹出软键盘时,插入一个空格:修改“OverLay Keyboard Sample.cs”
public static void ShowKeyboard(OverlayKeyboardSample caller)
{
if (activeKeyboard != null)
{
HideKeyboard();
}
if (activeKeyboard == null)
{
var vr = SteamVR.instance;
if (vr != null)
{
caller.text = caller.textEntry.text;
#if VIU_STEAMVR_2_6_0_OR_NEWER
uint flag = 0;
if (caller.minimalMode)
{
flag = (uint)EKeyboardFlags.KeyboardFlag_Minimal;
}
vr.overlay.ShowKeyboard(0, 0, flag, "Description", 256, " "+caller.text, 0);
#else
vr.overlay.ShowKeyboard(0, 0, "Description", 256, caller.text, caller.minimalMode, 0);
#endif
}
activeKeyboard = caller;
}
}
b.关闭软键盘时将插入的空格删除
private static void OnKeyboardClosed(Valve.VR.VREvent_t arg)
{
var vr = SteamVR.instance;
if (vr != null)
{
if (strBuilder == null) { strBuilder = new System.Text.StringBuilder(1024); }
vr.overlay.GetKeyboardText(strBuilder, 1024);
activeKeyboard.text = strBuilder.ToString();
if(activeKeyboard.text == " ")
{
activeKeyboard.text = "";
activeKeyboard.textEntry.text = activeKeyboard.text;
}
else if (activeKeyboard.text.StartsWith(" "))
{
activeKeyboard.textEntry.text = activeKeyboard.text.Remove(0,1);
}
strBuilder.Length = 0;
}
activeKeyboard = null;
}