StringControl.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using SRF;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. namespace SRDebugger.UI.Controls.Data
  6. {
  7. public class StringControl : DataBoundControl
  8. {
  9. protected override void Start()
  10. {
  11. base.Start();
  12. this.InputField.onValueChanged.AddListener(new UnityAction<string>(this.OnValueChanged));
  13. }
  14. private void OnValueChanged(string newValue)
  15. {
  16. base.UpdateValue(newValue);
  17. }
  18. protected override void OnBind(string propertyName, Type t)
  19. {
  20. base.OnBind(propertyName, t);
  21. this.Title.text = propertyName;
  22. this.InputField.text = string.Empty;
  23. this.InputField.interactable = !base.IsReadOnly;
  24. }
  25. protected override void OnValueUpdated(object newValue)
  26. {
  27. string text = (newValue != null) ? ((string)newValue) : string.Empty;
  28. this.InputField.text = text;
  29. }
  30. public override bool CanBind(Type type, bool isReadOnly)
  31. {
  32. return type == typeof(string) && !isReadOnly;
  33. }
  34. [RequiredField]
  35. public InputField InputField;
  36. [RequiredField]
  37. public Text Title;
  38. }
  39. }