Jelajahi Sumber

Change `ApplePickingNotifications` to have BusId.

Michał Pełka 2 tahun lalu
induk
melakukan
6c006cef2b

+ 1 - 1
Project/Gem/Source/ApplePicker/ApplePickerComponent.cpp

@@ -150,7 +150,7 @@ namespace AppleKraken
             AZ_Warning("ApplePicker", false, "Effector entity not set, assuming same entity");
             m_effectorEntityId = GetEntityId();
         }
-        ApplePickingNotificationBus::Handler::BusConnect();
+        ApplePickingNotificationBus::Handler::BusConnect(GetEntityId());
         AZ::TickBus::Handler::BusConnect();
 
         auto ros2Node = ROS2Interface::Get()->GetNode();

+ 4 - 0
Project/Gem/Source/ApplePicker/ApplePickingNotifications.h

@@ -16,6 +16,10 @@ namespace AppleKraken
     class ApplePickingNotifications : public AZ::EBusTraits
     {
     public:
+        static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
+        static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
+        // Messages are addressed by EntityId.
+        using BusIdType = AZ::EntityId;
         //! The effector is ready for picking
         virtual void EffectorReadyForPicking() = 0;
 

+ 5 - 5
Project/Gem/Source/ApplePicker/KrakenEffectorComponent.cpp

@@ -63,7 +63,7 @@ namespace AppleKraken
                 if (m_currentTask.m_appleEntityId == collideToEntityId)
                 {
                     AZ_TracePrintf("m_onTriggerHandleBeginHandler", "=================m_onTriggerHandle to Apple!====================");
-                    ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::ApplePicked);
+                    ApplePickingNotificationBus::Event(this->GetEntityId(),&ApplePickingNotifications::ApplePicked);
                     if (m_effectorState == EffectorState::PICKING)
                     {
                         // start picking the apple
@@ -361,7 +361,7 @@ namespace AppleKraken
                   if (m_currentStateTransitionTime > m_maxPickingTime)
                   {
                       AZ_Printf("m_onTriggerHandleBeginHandler", "---------------Failed to retrieve apple--------------------\n");
-                      ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::PickingFailed, "Timeout");
+                      ApplePickingNotificationBus::Event(this->GetEntityId(),&ApplePickingNotifications::PickingFailed, "Timeout");
                   }
               } },
             { EffectorState::PICKING_STABILIZE,
@@ -401,7 +401,7 @@ namespace AppleKraken
                 [this]()
                 {
                     LockManipulator(false);
-                    ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::EffectorReadyForPicking);
+                    ApplePickingNotificationBus::Event(GetEntityId(),&ApplePickingNotifications::EffectorReadyForPicking);
                 },
             },
             {
@@ -443,9 +443,9 @@ namespace AppleKraken
             },
             {
                 { EffectorState::RETRIEVING_STABILIZE, EffectorState::PREPARED },
-                []()
+                [this]()
                 {
-                    ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::AppleRetrieved);
+                    ApplePickingNotificationBus::Event(GetEntityId(),&ApplePickingNotifications::AppleRetrieved);
                 },
             },