mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
Callback to spawn actors from Redis event dispatcher WORKS!!!
This commit is contained in:
@@ -97,8 +97,7 @@ void AEventSourceActor::Subscribe(const FString& Channel)
|
|||||||
|
|
||||||
if (!redis->SubscribeReply.IsBound()) {
|
if (!redis->SubscribeReply.IsBound()) {
|
||||||
UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): binding event"));
|
UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): binding event"));
|
||||||
//redis->SubscribeReply.AddDynamic(this, "AEventSourceActor::SubscribeCallback(FString Channel, FString Message)");
|
redis->SubscribeReply.AddDynamic(this, &AEventSourceActor::InternalSubscribeCallback);
|
||||||
redis->SubscribeReply.AddDynamic(this, &AEventSourceActor::SubscribeCallback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,9 +112,14 @@ void AEventSourceActor::Unsubscribe(const FString& Channel)
|
|||||||
redis->Unsubscribe(Channel);
|
redis->Unsubscribe(Channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AEventSourceActor::SubscribeCallback(FString Channel, FString Message)
|
void AEventSourceActor::InternalSubscribeCallback(FString Channel, FString Message)
|
||||||
{
|
{
|
||||||
//UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): %s %s"), Channel, Message);
|
//UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): %s %s"), Channel, Message);
|
||||||
UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): called"));
|
UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): called"));
|
||||||
|
|
||||||
|
if (MyDelegate.IsBound()) {
|
||||||
|
MyDelegate.Broadcast(Channel, Message);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,3 +58,10 @@ void ASpawningActor::Spawn()
|
|||||||
spawnedActor->StartDestroyTimer(10.0);
|
spawnedActor->StartDestroyTimer(10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ASpawningActor::SpawnCallback(FString Channel, FString Message)
|
||||||
|
{
|
||||||
|
UE_LOG(EventSourceLog, Log, TEXT("SpawnCallback()"));
|
||||||
|
|
||||||
|
Spawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ DECLARE_LOG_CATEGORY_EXTERN(EventSourceLog, Log, All);
|
|||||||
* Manages an underlying Redis pubsub subscription and coordinates dispatch to other actors.
|
* Manages an underlying Redis pubsub subscription and coordinates dispatch to other actors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FMySubscriberDelegate, FString, Channel, FString, Message);
|
||||||
|
|
||||||
// NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes.
|
// NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes.
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class EVENTCENTERPLUGIN_API AEventSourceActor : public AActor
|
class EVENTCENTERPLUGIN_API AEventSourceActor : public AActor
|
||||||
@@ -61,6 +63,9 @@ public:
|
|||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FSubscribeReply SubscribeReplyy;
|
FSubscribeReply SubscribeReplyy;
|
||||||
|
|
||||||
|
/** Again, what do. */
|
||||||
|
UPROPERTY(BlueprintAssignable)
|
||||||
|
FMySubscriberDelegate MyDelegate;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
@@ -74,7 +79,7 @@ private:
|
|||||||
// Handle callbacks.
|
// Handle callbacks.
|
||||||
// NB(bt): Declared 'UFUNCTION()' so reflection enables as a delegate callback.
|
// NB(bt): Declared 'UFUNCTION()' so reflection enables as a delegate callback.
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void SubscribeCallback(FString Channel, FString Message);
|
void InternalSubscribeCallback(FString Channel, FString Message);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Called every frame
|
// Called every frame
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||||
void Spawn();
|
void Spawn();
|
||||||
|
|
||||||
|
/** Create actor with delegation callback. */
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||||
|
void SpawnCallback(FString Channel, FString Message);
|
||||||
|
|
||||||
/** Mesh to use */
|
/** Mesh to use */
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true"))
|
||||||
class UStaticMeshComponent* BaseMesh;
|
class UStaticMeshComponent* BaseMesh;
|
||||||
|
|||||||
Reference in New Issue
Block a user