ScriptCanvas_TriggerEvents.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. # Test case ID : C6274125
  7. # Test Case Title : Verify ScriptCanvas Trigger Events.
  8. # fmt: off
  9. class Tests():
  10. enter_game_mode = ("Entered game mode", "Failed to enter game mode")
  11. find_box = ("Box entity found", "Box entity not found")
  12. find_sphere = ("Sphere entity found", "Sphere entity not found")
  13. sphere_enter_triggerarea = ("Sphere entered the trigger area", "Sphere did not entered trigger area")
  14. sphere_exit_triggerarea = ("Sphere exited the trigger area", "Sphere did not exited the trigger area")
  15. exit_game_mode = ("Exited game mode", "Couldn't exit game mode")
  16. # fmt: on
  17. class LogLines:
  18. """
  19. These lines are added to the expected lines in the test suite.
  20. """
  21. expected_lines = [
  22. "Scriptcanvas:Sphere entered the trigger Area",
  23. "Scriptcanvas:Sphere exited the trigger Area",
  24. ]
  25. def ScriptCanvas_TriggerEvents():
  26. """
  27. Summary:
  28. Verify ScriptCanvas Trigger Events.
  29. Level Description:
  30. BoxCollider (entity) - Entity contains PhysX Collider (Box shape) and trigger is enabled for it.
  31. ScriptCanvas is attached to the PhysX box shape collider entity. ScriptCanvas has two trigger events.
  32. ScriptCanvas trigger events are OnTriggerEnter and OnTriggerExit.
  33. Sphere (entity) - Entity contains PhysX Collider(Sphere shape) with PhysX Rigid Body.
  34. Expected Behavior:
  35. When game mode is entered, Sphere should enter and exit from ScriptCanvas Trigger area. ScriptCanvas prints
  36. the name of the entity when it enters and exits the ScriptCanvas trigger area.
  37. Test Steps:
  38. 1) Open level
  39. 2) Enter game mode
  40. 3) Retrieve and validate entities
  41. 4) Verify Sphere enter and exit from ScriptCanvas Trigger area
  42. 5) Exit game mode
  43. 6) Close the editor
  44. Note:
  45. - This test file must be called from the Open 3D Engine Editor command terminal
  46. - Any passed and failed tests are written to the Editor.log file.
  47. Parsing the file or running a log_monitor are required to observe the test results.
  48. :return: None
  49. """
  50. import os
  51. import sys
  52. import azlmbr.legacy.general as general
  53. import azlmbr.bus
  54. from editor_python_test_tools.utils import Report
  55. from editor_python_test_tools.utils import TestHelper as helper
  56. helper.init_idle()
  57. # Constants
  58. TIMEOUT = 2.5
  59. # 1) Open level
  60. helper.open_level("Physics", "ScriptCanvas_TriggerEvents")
  61. # 2) Enter game mode
  62. helper.enter_game_mode(Tests.enter_game_mode)
  63. # 3) Retrieve and validate entities
  64. box_id = general.find_game_entity("Box")
  65. Report.critical_result(Tests.find_box, box_id.IsValid())
  66. sphere_id = general.find_game_entity("Sphere")
  67. Report.critical_result(Tests.find_sphere, sphere_id.IsValid())
  68. # 4) Verify Sphere enter and exit from ScriptCanvas Trigger area
  69. class BoxTrigger:
  70. entered = False
  71. exited = False
  72. def on_enter(args):
  73. other_id = args[0]
  74. if other_id.Equal(sphere_id):
  75. Report.info("Trigger entered")
  76. BoxTrigger.entered = True
  77. def on_exit(args):
  78. other_id = args[0]
  79. if other_id.Equal(sphere_id):
  80. Report.info("Trigger exited")
  81. BoxTrigger.exited = True
  82. handler = azlmbr.physics.TriggerNotificationBusHandler()
  83. handler.connect(box_id)
  84. handler.add_callback("OnTriggerEnter", on_enter)
  85. handler.add_callback("OnTriggerExit", on_exit)
  86. helper.wait_for_condition(lambda: BoxTrigger.entered, TIMEOUT)
  87. Report.result(Tests.sphere_enter_triggerarea, BoxTrigger.entered)
  88. helper.wait_for_condition(lambda: BoxTrigger.exited, TIMEOUT)
  89. Report.result(Tests.sphere_exit_triggerarea, BoxTrigger.exited)
  90. # 5) Exit game mode
  91. helper.exit_game_mode(Tests.exit_game_mode)
  92. if __name__ == "__main__":
  93. from editor_python_test_tools.utils import Report
  94. Report.start_test(ScriptCanvas_TriggerEvents)