仅获取 InputField 的 OnValueChanged 的​​静态字符串

Only Getting a Static String for OnValueChanged of InputField

我有一个 InputField,我将我的 "FindSoftware" 函数作为 OnValueChanged 的​​目标,但它不会传递 InputField 的字符串。我可以在 select 要调用的函数(下例中的 "This_is_Static_Boo..." )旁边手动输入它将传递的内容,但这并不好,因为我想要我当前正在输入的文本。如何使其动态化?

public void FindSoftware(String s)
{
    Debug.Log("Updated string = " + s); // Always blank or whatever I statically tell it to be
}

UnityEvents

有两种回调

When configuring a UnityEvent in the Inspector there are two types of function calls that are supported:

  • Static. Static calls are preconfigured calls, with preconfigured values that are set in the UI. This means that when the callback is invoked, the target function is invoked with the argument that has been entered into the UI.

  • Dynamic. Dynamic calls are invoked using an argument that is sent from code, and this is bound to the type of UnityEvent that is being invoked. The UI filters the callbacks and only shows the dynamic calls that are valid for the UnityEvent.

因此,在设置方法调用时,只需确保 select 顶部 Dynamic 部分中列出的所有可调用方法采用 string(或给定类型)作为参数。