pressed.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 pressed =
  12. {
  13. Properties =
  14. {
  15. IncomingInputEventName = "",
  16. OutgoingGameplayEventName = "",
  17. },
  18. }
  19. function pressed:OnActivate()
  20. local inputBusId = InputEventNotificationId(self.Properties.IncomingInputEventName)
  21. self.inputBus = InputEventNotificationBus.Connect(self, inputBusId)
  22. end
  23. function pressed:OnPressed(floatValue)
  24. GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
  25. end
  26. function pressed:OnHeld(floatValue)
  27. end
  28. function pressed:OnReleased(floatValue)
  29. GameplayNotificationBus.Event.OnEventEnd(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
  30. end
  31. function pressed:OnDeactivate()
  32. self.inputBus:Disconnect()
  33. end
  34. return pressed