GenericInspector.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /// <summary>
  10. /// Default implementation of the inspector used when no specified inspector is provided for the type. Inspector
  11. /// displays GUI for all the inspectable fields in the object.
  12. /// </summary>
  13. internal sealed class GenericInspector : Inspector
  14. {
  15. private bool isInitialized;
  16. private List<InspectableField> inspectableFields = new List<InspectableField>();
  17. /// <summary>
  18. /// Initializes required data the first time <see cref="Refresh"/> is called.
  19. /// </summary>
  20. private void Initialize()
  21. {
  22. if (referencedObject != null)
  23. {
  24. SerializableObject serializableObject = new SerializableObject(referencedObject.GetType(), referencedObject);
  25. foreach (var field in serializableObject.Fields)
  26. {
  27. if (!field.Inspectable)
  28. continue;
  29. inspectableFields.Add(InspectableField.CreateInspectable(field.Name, 0, new InspectableFieldLayout(layout), field.GetProperty()));
  30. }
  31. }
  32. isInitialized = true;
  33. }
  34. /// <inheritdoc/>
  35. internal override bool Refresh()
  36. {
  37. if (!isInitialized)
  38. Initialize();
  39. bool anythingModified = false;
  40. int currentIndex = 0;
  41. foreach (var field in inspectableFields)
  42. {
  43. anythingModified |= field.Refresh(currentIndex);
  44. currentIndex += field.GetNumLayoutElements();
  45. }
  46. return anythingModified;
  47. }
  48. }
  49. }