3
0

LoadUnloadCanvasButton.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ----------------------------------------------------------------------------------------------------
  2. --
  3. -- Copyright (c) Contributors to the Open 3D Engine Project.
  4. -- For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. --
  6. -- SPDX-License-Identifier: Apache-2.0 OR MIT
  7. --
  8. --
  9. --
  10. ----------------------------------------------------------------------------------------------------
  11. local LoadUnloadCanvasButton =
  12. {
  13. Properties =
  14. {
  15. canvasName = ""
  16. },
  17. }
  18. function LoadUnloadCanvasButton:OnActivate()
  19. self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
  20. self.canvasId = EntityId()
  21. end
  22. function LoadUnloadCanvasButton:OnDeactivate()
  23. self.buttonHandler:Disconnect()
  24. if (self.canvasId:IsValid()) then
  25. UiCanvasManagerBus.Broadcast.UnloadCanvas(self.canvasId)
  26. self.canvasId = EntityId()
  27. end
  28. end
  29. function LoadUnloadCanvasButton:OnButtonClick()
  30. if (self.canvasId:IsValid()) then
  31. UiCanvasManagerBus.Broadcast.UnloadCanvas(self.canvasId)
  32. self.canvasId = EntityId()
  33. else
  34. self.canvasId = UiCanvasManagerBus.Broadcast.LoadCanvas(self.Properties.canvasName)
  35. end
  36. end
  37. return LoadUnloadCanvasButton