Inspector.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. /// <summary>
  9. /// Displays GUI elements for all the inspectable fields in an object.
  10. /// </summary>
  11. public abstract class Inspector
  12. {
  13. public const short START_BACKGROUND_DEPTH = 50;
  14. protected GUIPanel GUI;
  15. protected GUILayoutY layout;
  16. protected object referencedObject;
  17. private GUIPanel RootGUI;
  18. /// <summary>
  19. /// Initializes the inspector. Must be called after construction.
  20. /// </summary>
  21. /// <param name="gui">GUI panel to add the GUI elements to.</param>
  22. /// <param name="instance">Instance of the object whose fields to display GUI for.</param>
  23. internal virtual void Initialize(GUIPanel gui, object instance)
  24. {
  25. RootGUI = gui;
  26. GUILayout contentLayoutX = gui.AddLayoutX();
  27. contentLayoutX.AddSpace(5);
  28. GUILayout contentLayoutY = contentLayoutX.AddLayoutY();
  29. contentLayoutY.AddSpace(5);
  30. GUIPanel contentPanel = contentLayoutY.AddPanel();
  31. contentLayoutY.AddSpace(5);
  32. contentLayoutX.AddSpace(5);
  33. GUIPanel backgroundPanel = gui.AddPanel(START_BACKGROUND_DEPTH);
  34. GUITexture inspectorContentBg = new GUITexture(null, EditorStyles.InspectorContentBg);
  35. backgroundPanel.AddElement(inspectorContentBg);
  36. GUI = contentPanel;
  37. layout = GUI.AddLayoutY();
  38. referencedObject = instance;
  39. Initialize();
  40. Refresh();
  41. }
  42. /// <summary>
  43. /// Hides or shows the inspector GUI elements.
  44. /// </summary>
  45. /// <param name="visible">True to make the GUI elements visible.</param>
  46. internal virtual void SetVisible(bool visible)
  47. {
  48. RootGUI.Enabled = visible;
  49. }
  50. /// <summary>
  51. /// Destroys all inspector GUI elements.
  52. /// </summary>
  53. internal void Destroy()
  54. {
  55. layout.Destroy();
  56. GUI.Destroy();
  57. }
  58. /// <summary>
  59. /// Called when the inspector is first created.
  60. /// </summary>
  61. protected internal abstract void Initialize();
  62. /// <summary>
  63. /// Checks if contents of the inspector have been modified, and updates them if needed.
  64. /// </summary>
  65. /// <returns>True if there were any modifications, false otherwise.</returns>
  66. protected internal abstract bool Refresh();
  67. }
  68. }