| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System.Collections.Generic;
- using BansheeEngine;
- namespace BansheeEditor
- {
- /// <summary>
- /// Default implementation of the inspector used when no specified inspector is provided for the type. Inspector
- /// displays GUI for all the inspectable fields in the object.
- /// </summary>
- internal sealed class GenericInspector : Inspector
- {
- private bool isEmpty = true;
- private List<InspectableField> inspectableFields = new List<InspectableField>();
- /// <inheritdoc/>
- protected internal override void Initialize()
- {
- if (InspectedObject != null)
- {
- int currentIndex = 0;
- SerializableObject serializableObject = new SerializableObject(InspectedObject.GetType(), InspectedObject);
- foreach (var field in serializableObject.Fields)
- {
- if (!field.Inspectable)
- continue;
- InspectableField inspectableField = InspectableField.CreateInspectable(field.Name, currentIndex, 0,
- new InspectableFieldLayout(Layout), field.GetProperty());
- inspectableFields.Add(inspectableField);
- isEmpty = false;
- currentIndex += inspectableField.GetNumLayoutElements();
- }
- base.SetVisible(!isEmpty);
- }
- }
- /// <inheritdoc/>
- protected internal override InspectableState Refresh()
- {
- InspectableState state = InspectableState.NotModified;
- int currentIndex = 0;
- foreach (var field in inspectableFields)
- {
- state |= field.Refresh(currentIndex);
- currentIndex += field.GetNumLayoutElements();
- }
- return state;
- }
- /// <inheritdoc/>
- internal override void SetVisible(bool visible)
- {
- base.SetVisible(!isEmpty && visible);
- }
- }
- }
|