TextField.cs 861 B

123456789101112131415161718192021222324
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public 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. GUI.SetNextControlName(controlName);
  14. Value = GUILayout.TextField(Value, textFieldStyle, layoutOptions);
  15. if (Event.current.isKey && Event.current.keyCode == KeyCode.Return) OnControlEvent(EventArgs.Empty);
  16. }
  17. public override void Draw(params GUILayoutOption[] layoutOptions)
  18. {
  19. Draw(new GUIStyle(GUI.skin.textField), layoutOptions);
  20. }
  21. }
  22. }