GenericInspector.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections.Generic;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// Default implementation of the inspector used when no specified inspector is provided for the type. Inspector
  7. /// displays GUI for all the inspectable fields in the object.
  8. /// </summary>
  9. internal sealed class GenericInspector : Inspector
  10. {
  11. private bool isEmpty = true;
  12. private List<InspectableField> inspectableFields = new List<InspectableField>();
  13. /// <inheritdoc/>
  14. protected internal override void Initialize()
  15. {
  16. if (InspectedObject != null)
  17. {
  18. int currentIndex = 0;
  19. SerializableObject serializableObject = new SerializableObject(InspectedObject.GetType(), InspectedObject);
  20. foreach (var field in serializableObject.Fields)
  21. {
  22. if (!field.Inspectable)
  23. continue;
  24. string path = field.Name;
  25. InspectableField inspectableField = InspectableField.CreateInspectable(this, field.Name, path,
  26. currentIndex, 0, new InspectableFieldLayout(Layout), field.GetProperty());
  27. inspectableFields.Add(inspectableField);
  28. isEmpty = false;
  29. currentIndex += inspectableField.GetNumLayoutElements();
  30. }
  31. base.SetVisible(!isEmpty);
  32. }
  33. }
  34. /// <inheritdoc/>
  35. protected internal override InspectableState Refresh()
  36. {
  37. InspectableState state = InspectableState.NotModified;
  38. int currentIndex = 0;
  39. foreach (var field in inspectableFields)
  40. {
  41. state |= field.Refresh(currentIndex);
  42. currentIndex += field.GetNumLayoutElements();
  43. }
  44. return state;
  45. }
  46. /// <inheritdoc/>
  47. internal override void SetVisible(bool visible)
  48. {
  49. base.SetVisible(!isEmpty && visible);
  50. }
  51. }
  52. }