instance_counter_blender.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 InstanceCounterBlender =
  12. {
  13. Properties =
  14. {
  15. }
  16. }
  17. function InstanceCounterBlender:OnActivate()
  18. self.tickBusHandler = TickBus.CreateHandler(self)
  19. self.tickBusHandler:Connect()
  20. self.elapsed = 0
  21. end
  22. function InstanceCounterBlender:OnTick(deltaTime, timePoint)
  23. self.elapsed = self.elapsed + deltaTime
  24. if self.elapsed >= 3 then
  25. self:ValidateInstances()
  26. end
  27. end
  28. function InstanceCounterBlender:ValidateInstances(instances)
  29. self.tickBusHandler:Disconnect()
  30. Debug.Log("Verifying instances have properly spawned...")
  31. num_instances_found = 0
  32. while num_instances_found ~= 400 do
  33. num_instances_found = AreaBlenderRequestBus.Broadcast.GetAreaProductCount(self.entityId)
  34. Debug.Log("Number of instances found = " .. num_instances_found)
  35. end
  36. box = ShapeComponentRequestsBus.Event.GetEncompassingAabb(self.entityId)
  37. instances = AreaSystemRequestBus.Broadcast.GetInstancesInAabb(box)
  38. if num_instances_found == #instances then
  39. purple_count = 0
  40. pink_count = 0
  41. Debug.Log("Number of instances found in Aabb = " .. #instances)
  42. for idx=1, #instances do
  43. local purple_path = "slices/purpleflower.dynamicslice"
  44. local pink_path = "slices/pinkflower.dynamicslice"
  45. local instance_asset_path = instances[idx].descriptor.spawner:GetSliceAssetPath()
  46. if instance_asset_path == purple_path then
  47. purple_count = purple_count + 1
  48. elseif instance_asset_path == pink_path then
  49. pink_count = pink_count + 1
  50. end
  51. end
  52. else
  53. Debug.Log("Number of instances found does not match expected instances! Expected: " .. num_instances_found .. ", Found:" .. #instances)
  54. end
  55. local success = purple_count == pink_count
  56. Debug.Log("Test Success = " .. tostring(success))
  57. if success then
  58. ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("quit")
  59. end
  60. end
  61. function InstanceCounterBlender:OnDeactivate()
  62. end
  63. return InstanceCounterBlender