StringControl.cs 1.2 KB

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