InspectableObject.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 GUILayoutY guiContentLayout;
  16. private bool isInitialized;
  17. public InspectableObject(string title, InspectableFieldLayout layout, SerializableProperty property)
  18. : base(title, layout, property)
  19. {
  20. }
  21. protected void Initialize(int layoutIndex)
  22. {
  23. if (property.Type != SerializableProperty.FieldType.Object)
  24. return;
  25. guiLabel = new GUILabel(title);
  26. layout.AddElement(layoutIndex, guiLabel);
  27. guiChildLayout = layout.AddLayoutX(layoutIndex);
  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, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
  37. else
  38. AddChild(CreateDefaultInspectable(field.Name, new InspectableFieldLayout(guiContentLayout), field.GetProperty()));
  39. }
  40. isInitialized = true;
  41. }
  42. protected override bool IsModified()
  43. {
  44. if (!isInitialized)
  45. return true;
  46. object newPropertyValue = property.GetValue<object>();
  47. if (oldPropertyValue != newPropertyValue)
  48. {
  49. oldPropertyValue = newPropertyValue;
  50. return true;
  51. }
  52. return base.IsModified();
  53. }
  54. protected override void Update(int index)
  55. {
  56. base.Update(index);
  57. if (!isInitialized)
  58. Initialize(index);
  59. // TODO - Update GUI element(s) with value from property
  60. }
  61. }
  62. }