GenericInspector.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. internal sealed class GenericInspector : Inspector
  10. {
  11. private bool isInitialized;
  12. private List<InspectableObjectBase> inspectableFields = new List<InspectableObjectBase>();
  13. private void Initialize()
  14. {
  15. if (referencedObject != null)
  16. {
  17. SerializableObject serializableObject = new SerializableObject(referencedObject.GetType(), referencedObject);
  18. foreach (var field in serializableObject.fields)
  19. {
  20. if (!field.Inspectable)
  21. continue;
  22. if (field.HasCustomInspector)
  23. inspectableFields.Add(InspectableObjectBase.CreateCustomInspectable(field.CustomInspectorType, field.Name, field.GetProperty()));
  24. else
  25. inspectableFields.Add(InspectableObjectBase.CreateDefaultInspectable(field.Name, field.GetProperty()));
  26. }
  27. }
  28. isInitialized = true;
  29. }
  30. internal override void Refresh()
  31. {
  32. if (!isInitialized)
  33. Initialize();
  34. foreach (var field in inspectableFields)
  35. {
  36. field.Refresh(layout);
  37. }
  38. }
  39. internal override int GetOptimalHeight()
  40. {
  41. return 200; // TODO - Implement properly
  42. }
  43. }
  44. }