InspectableObject.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using BansheeEngine;
  7. namespace BansheeEditor
  8. {
  9. public class InspectableObject : InspectableObjectBase
  10. {
  11. private const int IndentAmount = 15;
  12. private object oldPropertyValue;
  13. private GUILabel guiLabel;
  14. private GUILayout guiChildLayout;
  15. private GUILayout guiContentLayout;
  16. private bool isInitialized;
  17. public InspectableObject(string title, SerializableProperty property)
  18. : base(title, property)
  19. {
  20. }
  21. protected void Initialize(GUILayout layout)
  22. {
  23. if (property.Type != SerializableProperty.FieldType.Object)
  24. return;
  25. guiLabel = new GUILabel(title);
  26. layout.AddElement(guiLabel);
  27. guiChildLayout = layout.AddLayoutX();
  28. guiChildLayout.AddSpace(IndentAmount);
  29. guiContentLayout = guiChildLayout.AddLayoutY();
  30. SerializableObject serializableObject = property.GetObject();
  31. foreach (var field in serializableObject.fields)
  32. {
  33. if (!field.Inspectable)
  34. continue;
  35. if (field.HasCustomInspector)
  36. AddChild(CreateCustomInspectable(field.CustomInspectorType, field.Name, field.GetProperty()));
  37. else
  38. AddChild(CreateDefaultInspectable(field.Name, field.GetProperty()));
  39. }
  40. isInitialized = true;
  41. }
  42. protected override bool IsModified()
  43. {
  44. object newPropertyValue = property.GetValue<object>();
  45. if (oldPropertyValue != newPropertyValue)
  46. {
  47. oldPropertyValue = newPropertyValue;
  48. return true;
  49. }
  50. return base.IsModified();
  51. }
  52. protected override void Update(GUILayout layout)
  53. {
  54. base.Update(layout);
  55. if (!isInitialized)
  56. Initialize(layout);
  57. // TODO - Update GUI element(s) with value from property
  58. }
  59. public override void Destroy()
  60. {
  61. if (guiLabel != null)
  62. guiLabel.Destroy();
  63. if (guiContentLayout != null)
  64. guiContentLayout.Destroy();
  65. if (guiChildLayout != null)
  66. guiChildLayout.Destroy();
  67. base.Destroy();
  68. }
  69. }
  70. }