MultipleSpawnsFromSingleTicket.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 MultipleSpawnsFromSingleTicket =
  12. {
  13. Properties =
  14. {
  15. Prefab = { default=SpawnableScriptAssetRef(), description="Prefab to spawn" },
  16. SpawnCount = { default=3, description="How many prefabs to spawn" },
  17. Offset = { default=Vector3(0.0, 2.0, 0.0), description="Translation offset for each spawn" }
  18. },
  19. }
  20. function MultipleSpawnsFromSingleTicket:OnActivate()
  21. self.entityCount = 0
  22. self.spawnsRemaining = self.Properties.SpawnCount
  23. self.translation = Vector3(0.0, 0.0, 0.0)
  24. self.spawnableMediator = SpawnableScriptMediator()
  25. self.ticket = self.spawnableMediator:CreateSpawnTicket(self.Properties.Prefab)
  26. self.spawnableNotificationsBusHandler = SpawnableScriptNotificationsBus.Connect(self, self.ticket:GetId())
  27. self:Spawn()
  28. end
  29. function MultipleSpawnsFromSingleTicket:OnSpawn(spawnTicket, entityList)
  30. self.entityCount = self.entityCount + entityList.GetSize(entityList)
  31. if (self.spawnsRemaining > 0)
  32. then
  33. self:Spawn()
  34. else
  35. if (self.entityCount == 6)
  36. then
  37. self.spawnableNotificationsBusHandler:Disconnect()
  38. ConsoleRequestBus.Broadcast.ExecuteConsoleCommand([[quit]])
  39. end
  40. end
  41. end
  42. function MultipleSpawnsFromSingleTicket:Spawn()
  43. self.spawnsRemaining = self.spawnsRemaining - 1
  44. self.translation = self.translation + self.Properties.Offset
  45. self.spawnableMediator:SpawnAndParentAndTransform(self.ticket, self.entityId, self.translation, Vector3(0.0, 0.0, 0.0), 1.0 )
  46. end
  47. return MultipleSpawnsFromSingleTicket