WrappedInputField.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using WebGLSupport.Detail;
  4. namespace WebGLSupport
  5. {
  6. /// <summary>
  7. /// Wrapper for UnityEngine.UI.InputField
  8. /// </summary>
  9. class WrappedInputField : IInputField
  10. {
  11. InputField input;
  12. RebuildChecker checker;
  13. public bool ReadOnly { get { return input.readOnly; } }
  14. public string text
  15. {
  16. get { return input.text; }
  17. set { input.text = value; }
  18. }
  19. public string placeholder
  20. {
  21. get
  22. {
  23. if (!input.placeholder) return "";
  24. var text = input.placeholder.GetComponent<Text>();
  25. return text ? text.text : "";
  26. }
  27. }
  28. public int fontSize
  29. {
  30. get { return input.textComponent.fontSize; }
  31. }
  32. public ContentType contentType
  33. {
  34. get { return (ContentType)input.contentType; }
  35. }
  36. public LineType lineType
  37. {
  38. get { return (LineType)input.lineType; }
  39. }
  40. public int characterLimit
  41. {
  42. get { return input.characterLimit; }
  43. }
  44. public int caretPosition
  45. {
  46. get { return input.caretPosition; }
  47. }
  48. public bool isFocused
  49. {
  50. get { return input.isFocused; }
  51. }
  52. public int selectionFocusPosition
  53. {
  54. get { return input.selectionFocusPosition; }
  55. set { input.selectionFocusPosition = value; }
  56. }
  57. public int selectionAnchorPosition
  58. {
  59. get { return input.selectionAnchorPosition; }
  60. set { input.selectionAnchorPosition = value; }
  61. }
  62. public bool OnFocusSelectAll
  63. {
  64. get { return true; }
  65. }
  66. public bool EnableMobileSupport
  67. {
  68. get
  69. {
  70. // return false to use unity mobile keyboard support
  71. return false;
  72. }
  73. }
  74. public WrappedInputField(InputField input)
  75. {
  76. this.input = input;
  77. checker = new RebuildChecker(this);
  78. }
  79. public void ActivateInputField()
  80. {
  81. input.ActivateInputField();
  82. }
  83. public void DeactivateInputField()
  84. {
  85. input.DeactivateInputField();
  86. }
  87. public void Rebuild()
  88. {
  89. if (checker.NeedRebuild())
  90. {
  91. input.textComponent.SetAllDirty();
  92. input.Rebuild(CanvasUpdate.LatePreRender);
  93. }
  94. }
  95. public Rect GetScreenCoordinates()
  96. {
  97. return Support.GetScreenCoordinates(input.GetComponent<RectTransform>());
  98. }
  99. }
  100. }