UGUIHelper.cs 687 B

123456789101112131415161718192021222324
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace GFGGame
  4. {
  5. public static class UGUIHelper
  6. {
  7. public static InputField GetInputFieldByName(this GameObject gameObject, string inputFieldName)
  8. {
  9. InputField[] allInputFields = gameObject.GetComponentsInChildren<InputField>();
  10. // 遍历所有 InputField,找到名称匹配的
  11. foreach (InputField inputField in allInputFields)
  12. {
  13. if (inputField.gameObject.name == inputFieldName) // 替换为你的 InputField 名称
  14. {
  15. return inputField;
  16. }
  17. }
  18. return null;
  19. }
  20. }
  21. }