2
0

Inspector.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. private InspectorWindow parentWindow;
  19. /// <summary>
  20. /// Initializes the inspector. Must be called after construction.
  21. /// </summary>
  22. /// <param name="parentWindow">Parent window to render the GUI to.</param>
  23. /// <param name="gui">GUI panel to add the GUI elements to.</param>
  24. /// <param name="instance">Instance of the object whose fields to display GUI for.</param>
  25. internal virtual void Initialize(InspectorWindow parentWindow, GUIPanel gui, object instance)
  26. {
  27. RootGUI = gui;
  28. GUILayout contentLayoutX = gui.AddLayoutX();
  29. contentLayoutX.AddSpace(5);
  30. GUILayout contentLayoutY = contentLayoutX.AddLayoutY();
  31. contentLayoutY.AddSpace(5);
  32. GUIPanel contentPanel = contentLayoutY.AddPanel();
  33. contentLayoutY.AddSpace(5);
  34. contentLayoutX.AddSpace(5);
  35. GUIPanel backgroundPanel = gui.AddPanel(START_BACKGROUND_DEPTH);
  36. GUITexture inspectorContentBg = new GUITexture(null, EditorStyles.InspectorContentBg);
  37. backgroundPanel.AddElement(inspectorContentBg);
  38. GUI = contentPanel;
  39. layout = GUI.AddLayoutY();
  40. referencedObject = instance;
  41. this.parentWindow = parentWindow;
  42. }
  43. /// <summary>
  44. /// Hides or shows the inspector GUI elements.
  45. /// </summary>
  46. /// <param name="visible">True to make the GUI elements visible.</param>
  47. internal virtual void SetVisible(bool visible)
  48. {
  49. RootGUI.Visible = visible;
  50. }
  51. /// <summary>
  52. /// Destroys all inspector GUI elements.
  53. /// </summary>
  54. internal void Destroy()
  55. {
  56. layout.Destroy();
  57. GUI.Destroy();
  58. }
  59. /// <summary>
  60. /// Checks if contents of the inspector have been modified, and updates them if needed.
  61. /// </summary>
  62. /// <returns>True if there were any modifications, false otherwise.</returns>
  63. internal abstract bool Refresh();
  64. }
  65. }