InspectableInt.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BansheeEngine;
  7. namespace BansheeEditor
  8. {
  9. public class InspectableInt : InspectableObjectBase
  10. {
  11. private int propertyValue;
  12. private GUIIntField guiIntField;
  13. private bool isInitialized;
  14. public InspectableInt(string title, InspectableFieldLayout layout, SerializableProperty property)
  15. : base(title, layout, property)
  16. {
  17. }
  18. private void Initialize(int layoutIndex)
  19. {
  20. if (property.Type == SerializableProperty.FieldType.Int)
  21. {
  22. guiIntField = new GUIIntField(new GUIContent(title));
  23. guiIntField.OnChanged += OnFieldValueChanged;
  24. layout.AddElement(layoutIndex, guiIntField);
  25. }
  26. isInitialized = true;
  27. }
  28. protected override bool IsModified()
  29. {
  30. if (!isInitialized)
  31. return true;
  32. int newPropertyValue = property.GetValue<int>();
  33. if (propertyValue != newPropertyValue)
  34. return true;
  35. return base.IsModified();
  36. }
  37. protected override void Update(int layoutIndex)
  38. {
  39. base.Update(layoutIndex);
  40. if (!isInitialized)
  41. Initialize(layoutIndex);
  42. propertyValue = property.GetValue<int>();
  43. if (guiIntField != null)
  44. {
  45. if (guiIntField.HasInputFocus())
  46. return;
  47. guiIntField.Value = propertyValue;
  48. }
  49. }
  50. private void OnFieldValueChanged(int newValue)
  51. {
  52. property.SetValue(newValue);
  53. }
  54. }
  55. }