TextField.cs 792 B

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