GUIWidget.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. namespace BansheeEngine
  2. {
  3. /// <summary>
  4. /// Container of GUI elements that can be positioned in the scene, and can output the rendered GUI to a user defined
  5. /// camera.
  6. /// </summary>
  7. public class GUIWidget : Component
  8. {
  9. private NativeGUIWidget nativeGUIWidget;
  10. [SerializeField]
  11. private SerializableData serializableData = new SerializableData();
  12. /// <summary>
  13. /// Skin used for rendering all the GUI elements belonging to this widget.
  14. /// </summary>
  15. internal GUISkin Skin
  16. {
  17. get { return nativeGUIWidget.Skin; }
  18. set
  19. {
  20. serializableData.skin = value;
  21. nativeGUIWidget.Skin = value;
  22. }
  23. }
  24. /// <summary>
  25. /// Determines to which camera are the GUI elements belonong to this widget rendered. If null then they will be
  26. /// rendered on the main camera.
  27. /// </summary>
  28. internal Camera Camera
  29. {
  30. get { return nativeGUIWidget.Camera; }
  31. set
  32. {
  33. serializableData.camera = value;
  34. nativeGUIWidget.Camera = value;
  35. }
  36. }
  37. /// <summary>
  38. /// Container into which all GUI elements belonging to this widget should be placed.
  39. /// </summary>
  40. internal GUIPanel Panel
  41. {
  42. get { return nativeGUIWidget.Panel; }
  43. }
  44. private void OnReset()
  45. {
  46. if (nativeGUIWidget != null)
  47. nativeGUIWidget.Destroy();
  48. nativeGUIWidget = new NativeGUIWidget();
  49. // Restore saved values after reset
  50. nativeGUIWidget.Skin = serializableData.skin;
  51. nativeGUIWidget.Camera = serializableData.camera;
  52. }
  53. private void OnDestroy()
  54. {
  55. nativeGUIWidget.Destroy();
  56. }
  57. /// <summary>
  58. /// Holds all data the GUIWidget component needs to persist through serialization.
  59. /// </summary>
  60. [SerializeObject]
  61. private class SerializableData
  62. {
  63. public GUISkin skin;
  64. public Camera camera;
  65. }
  66. }
  67. }