unity3d - 使用正则表达式的 TextMesh Pro InputField 字符验证
问题描述
当 TextMesh Pro InputField 设置为使用 Regex 时,如何设置 Regex 字符串?
我已将其设置为使用正则表达式
inputfield.characterValidation = TMPro.TMP_InputField.CharacterValidation.Regex;
但我无法找出在哪里设置所述正则表达式字符串。
谢谢
解决方案
对于需要通过脚本设置输入字段值的,可以使用反射来设置私有变量值。
Type inputFieldType = Type.GetType("TMPro.TMP_InputField, Unity.TextMeshPro", true, true);
System.Reflection.FieldInfo regexValueFieldInfo = inputFieldType.GetField("m_RegexValue",System.Reflection.BindingFlags.NonPublic| System.Reflection.BindingFlags.Instance);
regexValueFieldInfo.SetValue(m_InputField, "your regex here");
推荐阅读
- scala - 有人可以解释下面的代码片段中发生了什么吗?我试图理解下面的 Scala 代码
- javascript - AceEditor 实例初始化后运行代码
- xml - 当使用 XPath 从 XML 中知道字段值时如何提取属性名称
- c# - 在使用 websockets 时,我可以在发送查询字符串时传入标头吗?
- c# - 在 Xamarin 中使用 MassTransit
- python - 找出列表中三个单词在给定文档中共同出现的频率
- python - 从其他 DataFrame 的对角线创建 DataFrame
- php - 为什么 CORS 在某些地方有效,而在其他地方无效?
- php - 为什么 Symfony 表单不使用约束注释验证我的 DTO?
- javascript - 如何将值保存到函数的变量中?