InspectableInt.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 oldPropertyValue;
  12. private GUILabel guiLabel;
  13. private bool isInitialized = false;
  14. public InspectableInt(string title, SerializableProperty property)
  15. :base(title, property)
  16. {
  17. }
  18. protected void Initialize(GUILayout layout)
  19. {
  20. if(property.Type == SerializableProperty.FieldType.Int)
  21. {
  22. guiLabel = new GUILabel(title);
  23. layout.AddElement(guiLabel); // TODO - Use an IntEditorField
  24. }
  25. isInitialized = true;
  26. }
  27. protected override bool IsModified()
  28. {
  29. if (!isInitialized)
  30. return true;
  31. int newPropertyValue = property.GetValue<int>();
  32. if (oldPropertyValue != newPropertyValue)
  33. {
  34. oldPropertyValue = newPropertyValue;
  35. return true;
  36. }
  37. return base.IsModified();
  38. }
  39. protected override void Update(GUILayout layout)
  40. {
  41. base.Update(layout);
  42. if (!isInitialized)
  43. Initialize(layout);
  44. // TODO - Update GUI element(s) with value from property
  45. }
  46. public override void Destroy()
  47. {
  48. if (guiLabel != null)
  49. guiLabel.Destroy();
  50. base.Destroy();
  51. }
  52. }
  53. }