GenericInspector.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. InspectableField inspectableField = InspectableField.CreateInspectable(field.Name, currentIndex, 0,
  25. new InspectableFieldLayout(Layout), field.GetProperty());
  26. inspectableFields.Add(inspectableField);
  27. isEmpty = false;
  28. currentIndex += inspectableField.GetNumLayoutElements();
  29. }
  30. base.SetVisible(!isEmpty);
  31. }
  32. }
  33. /// <inheritdoc/>
  34. protected internal override InspectableState Refresh()
  35. {
  36. InspectableState state = InspectableState.NotModified;
  37. int currentIndex = 0;
  38. foreach (var field in inspectableFields)
  39. {
  40. state |= field.Refresh(currentIndex);
  41. currentIndex += field.GetNumLayoutElements();
  42. }
  43. return state;
  44. }
  45. /// <inheritdoc/>
  46. internal override void SetVisible(bool visible)
  47. {
  48. base.SetVisible(!isEmpty && visible);
  49. }
  50. }
  51. }