TextField.cs 897 B

12345678910111213141516171819202122232425
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class TextField : BaseControl
  6. {
  7. private static int textFieldID = 961;
  8. private static int ID => ++textFieldID;
  9. private readonly string controlName = $"textField{ID}";
  10. public string Value { get; set; } = string.Empty;
  11. public void Draw(GUIStyle textFieldStyle, params GUILayoutOption[] layoutOptions)
  12. {
  13. if (!Visible) return;
  14. GUI.SetNextControlName(controlName);
  15. Value = GUILayout.TextField(Value, textFieldStyle, layoutOptions);
  16. if (Event.current.isKey && Event.current.keyCode == KeyCode.Return) OnControlEvent(EventArgs.Empty);
  17. }
  18. public override void Draw(params GUILayoutOption[] layoutOptions)
  19. {
  20. Draw(new GUIStyle(GUI.skin.textField), layoutOptions);
  21. }
  22. }
  23. }