我正在为我创建的虚拟键盘编写键盘管理器。我正在使用 UnityAction 返回调用对象并处理键盘输入。然而,不知何故,我的 UnityAction 丢失了其订阅的事件,我得到一个“对象引用未设置到对象实例。
我检查了调用函数,看看 UnityAction 到达脚本后是否不为空,事实并非如此。然而,检查关闭中的其他地方都会返回 null。您将在我的所有调试代码下面找到我检查 UnityAction 不为空的位置。代码中唯一不为 null 的地方是 ReadUserInput 函数。所有其他均为空。
我在很多地方都使用过这种编码方法,没有出现任何问题。不知道为什么这个这么粘!
调用代码:
VRKeyboard.ProcessInput += AddKbdInputToInputline;
VRKeyboard.ReadUserInput();
VR键盘代码:
public TMPro.TMP_Text InputLine;
public GameObject VRKeyboard;
public UnityAction ProcessInput;
private bool isdone = false;
// Update is called once per frame
void Update()
{
if (ProcessInput == null) Debug.Log("ProcessInput is null at update"); else Debug.Log("ProcessInput is NOT null at update");
if (isdone) CloseKeyboard();
}
public void ReadUserInput()
{
InputLine.text = "";
VRKeyboard.SetActive(true);
if (ProcessInput == null) Debug.Log("ProcessInput is null at open"); else Debug.Log("ProcessInput is NOT null at open");
}
public void OnPointerDown(PointerEventData p)
{
Text ButtonPressed;
ButtonPressed = GetComponentInChildren<Text>(this);
switch (ButtonPressed.text)
{
case "Clear All":
InputLine.text = "";
break;
case "Backsp":
InputLine.text = InputLine.text.Substring(0, InputLine.text.Length - 1);
break;
case "Enter":
isdone = true;
break;
default:
InputLine.text += ButtonPressed.text;
break;
}
if (ProcessInput == null) Debug.Log("ProcessInput is null at pointerdown"); else Debug.Log("ProcessInput is NOT null at pointerdown");
}
public void OnPointerUp(PointerEventData p)
{
}
public void CloseKeyboard()
{
GameObject VRKeyboard = transform.parent.parent.parent.gameObject;
VRKeyboard.SetActive(false);
if (ProcessInput == null) Debug.Log("ProcessInput is null at close");
//This line below is where I get the error:
ProcessInput();
}
qq_花开花谢_0
相关分类