2
0

GUIWidget.cs 3.0 KB

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