using System; using System.Collections.Generic; using System.Linq; using System.Text; using BansheeEngine; namespace BansheeEditor { /// /// Displays GUI elements for all the inspectable fields in an object. /// public abstract class Inspector { public const short START_BACKGROUND_DEPTH = 50; /// /// Returns the main GUI layout for the inspector. /// protected GUILayoutY Layout { get { return layout; } } /// /// Returns the main GUI panel for the inspector. is a child of this panel. /// protected GUIPanel GUI { get { return mainPanel; } } /// /// Returns the object the inspector is currently displaying. /// protected object InspectedObject { get { return inspectedObject; } } private GUIPanel rootGUI; private GUIPanel mainPanel; private GUILayoutY layout; private object inspectedObject; /// /// Initializes the inspector. Must be called after construction. /// /// GUI panel to add the GUI elements to. /// Instance of the object whose fields to display GUI for. internal virtual void Initialize(GUIPanel gui, object instance) { rootGUI = gui; GUILayout contentLayoutX = gui.AddLayoutX(); contentLayoutX.AddSpace(5); GUILayout contentLayoutY = contentLayoutX.AddLayoutY(); contentLayoutY.AddSpace(5); GUIPanel contentPanel = contentLayoutY.AddPanel(); contentLayoutY.AddSpace(5); contentLayoutX.AddSpace(5); GUIPanel backgroundPanel = gui.AddPanel(START_BACKGROUND_DEPTH); GUITexture inspectorContentBg = new GUITexture(null, EditorStyles.InspectorContentBg); backgroundPanel.AddElement(inspectorContentBg); mainPanel = contentPanel; layout = GUI.AddLayoutY(); inspectedObject = instance; Initialize(); Refresh(); } /// /// Hides or shows the inspector GUI elements. /// /// True to make the GUI elements visible. internal virtual void SetVisible(bool visible) { rootGUI.Active = visible; } /// /// Destroys all inspector GUI elements. /// internal void Destroy() { Layout.Destroy(); GUI.Destroy(); } /// /// Called when the inspector is first created. /// protected internal abstract void Initialize(); /// /// Checks if contents of the inspector have been modified, and updates them if needed. /// protected internal abstract void Refresh(); } }