GUIWidget.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. namespace BansheeEngine
  4. {
  5. /** @addtogroup GUI_Engine
  6. * @{
  7. */
  8. /// <summary>
  9. /// Container of GUI elements that can be positioned in the scene, and can output the rendered GUI to a user defined
  10. /// camera.
  11. /// </summary>
  12. public class GUIWidget : ManagedComponent
  13. {
  14. private NativeGUIWidget nativeGUIWidget;
  15. [SerializeField]
  16. private SerializableData serializableData = new SerializableData();
  17. /// <summary>
  18. /// Skin used for rendering all the GUI elements belonging to this widget.
  19. /// </summary>
  20. public GUISkin Skin
  21. {
  22. get { return serializableData.skin; }
  23. set
  24. {
  25. serializableData.skin = value;
  26. nativeGUIWidget.Skin = value;
  27. }
  28. }
  29. /// <summary>
  30. /// Determines to which camera are the GUI elements belonong to this widget rendered. If null then they will be
  31. /// rendered on the main camera.
  32. /// </summary>
  33. public Camera Camera
  34. {
  35. get { return serializableData.camera; }
  36. set
  37. {
  38. serializableData.camera = value;
  39. nativeGUIWidget.Camera = value;
  40. }
  41. }
  42. /// <summary>
  43. /// Container into which all GUI elements belonging to this widget should be placed.
  44. /// </summary>
  45. public GUIPanel Panel
  46. {
  47. get { return nativeGUIWidget.Panel; }
  48. }
  49. /// <summary>
  50. /// Depth that determines in which order are GUI widgets rendered. Widgets with lower depth are rendered in front
  51. /// of widgets with higher depth.
  52. /// </summary>
  53. public short Depth
  54. {
  55. set { nativeGUIWidget.Depth = value; }
  56. get { return nativeGUIWidget.Depth; }
  57. }
  58. private void OnReset()
  59. {
  60. if (nativeGUIWidget != null)
  61. nativeGUIWidget.Destroy();
  62. nativeGUIWidget = new NativeGUIWidget();
  63. // Restore saved values after reset
  64. nativeGUIWidget.Skin = serializableData.skin;
  65. nativeGUIWidget.Camera = serializableData.camera;
  66. }
  67. private void OnUpdate()
  68. {
  69. nativeGUIWidget.UpdateTransform(SceneObject);
  70. if (serializableData.camera == null)
  71. nativeGUIWidget.UpdateMainCamera(Scene.Camera);
  72. }
  73. private void OnDestroy()
  74. {
  75. nativeGUIWidget.Destroy();
  76. }
  77. /// <summary>
  78. /// Holds all data the GUIWidget component needs to persist through serialization.
  79. /// </summary>
  80. [SerializeObject]
  81. private class SerializableData
  82. {
  83. public GUISkin skin;
  84. public Camera camera;
  85. }
  86. }
  87. /** @} */
  88. }