PrefabNotifications_PropagationNotificationsReceived.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. propagationBegun = False
  7. propagationEnded = False
  8. def PrefabNotifications_PropagationNotificationsReceived():
  9. from pathlib import Path
  10. import azlmbr.prefab as prefab
  11. from editor_python_test_tools.editor_entity_utils import EditorEntity
  12. from editor_python_test_tools.prefab_utils import Prefab
  13. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  14. CAR_PREFAB_FILE_NAME = Path(__file__).stem + 'car_prefab'
  15. prefab_test_utils.open_base_tests_level()
  16. # Creates a new entity at the root level
  17. car_entity = EditorEntity.create_editor_entity("Car")
  18. car_prefab_entities = [car_entity]
  19. # Creates a prefab from the new entity
  20. _, car = Prefab.create_prefab(
  21. car_prefab_entities, CAR_PREFAB_FILE_NAME)
  22. # Connects PrefabPublicNotificationBusHandler and add callbacks for 'OnPrefabInstancePropagationBegin'
  23. # and 'OnPrefabInstancePropagationEnd'
  24. def OnPrefabInstancePropagationBegin(parameters):
  25. global propagationBegun
  26. propagationBegun = True
  27. def OnPrefabInstancePropagationEnd(parameters):
  28. global propagationEnded
  29. propagationEnded = True
  30. handler = prefab.PrefabPublicNotificationBusHandler()
  31. handler.connect()
  32. handler.add_callback('OnPrefabInstancePropagationBegin', OnPrefabInstancePropagationBegin)
  33. handler.add_callback('OnPrefabInstancePropagationEnd', OnPrefabInstancePropagationEnd)
  34. # Duplicates the prefab instance to trigger callbacks
  35. Prefab.duplicate_prefabs([car])
  36. handler.disconnect()
  37. assert propagationBegun, "Notification 'PrefabPublicNotifications::OnPrefabInstancePropagationBegin' is not sent."
  38. assert propagationEnded, "Notification 'PrefabPublicNotifications::OnPrefabInstancePropagationEnd' is not sent."
  39. if __name__ == "__main__":
  40. from editor_python_test_tools.utils import Report
  41. Report.start_test(PrefabNotifications_PropagationNotificationsReceived)