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. 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, new InspectableFieldLayout(layout), field.GetProperty()));
  24. else
  25. inspectableFields.Add(InspectableObjectBase.CreateDefaultInspectable(field.Name, new InspectableFieldLayout(layout), field.GetProperty()));
  26. }
  27. }
  28. isInitialized = true;
  29. }
  30. internal override bool Refresh()
  31. {
  32. if (!isInitialized)
  33. Initialize();
  34. bool anythingModified = false;
  35. int currentIndex = 0;
  36. foreach (var field in inspectableFields)
  37. {
  38. anythingModified |= field.Refresh(currentIndex);
  39. currentIndex += field.GetNumLayoutElements();
  40. }
  41. return anythingModified;
  42. }
  43. internal override int GetOptimalHeight()
  44. {
  45. return GUILayoutUtility.CalculateOptimalSize(layout).y;
  46. }
  47. }
  48. }