第一次提交
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "Async/GIS_AsyncAction_Wait.h"
|
||||
#include "TimerManager.h"
|
||||
#include UE_INLINE_GENERATED_CPP_BY_NAME(GIS_AsyncAction_Wait)
|
||||
|
||||
|
||||
UGIS_AsyncAction_Wait::UGIS_AsyncAction_Wait()
|
||||
{
|
||||
}
|
||||
|
||||
bool UGIS_AsyncAction_Wait::ShouldBroadcastDelegates() const
|
||||
{
|
||||
return Super::ShouldBroadcastDelegates() && IsValid(GetActor());
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::StopWaiting()
|
||||
{
|
||||
const UWorld* World = GetWorld();
|
||||
if (TimerHandle.IsValid() && IsValid(World))
|
||||
{
|
||||
FTimerManager& TimerManager = World->GetTimerManager();
|
||||
TimerManager.ClearTimer(TimerHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::Cleanup()
|
||||
{
|
||||
AActor* Actor = GetActor();
|
||||
|
||||
if (IsValid(Actor))
|
||||
{
|
||||
Actor->OnDestroyed.RemoveDynamic(this, &ThisClass::OnTargetDestroyed);
|
||||
}
|
||||
|
||||
StopWaiting();
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::Activate()
|
||||
{
|
||||
const UWorld* World = GetWorld();
|
||||
AActor* Actor = GetActor();
|
||||
if (IsValid(World) && IsValid(Actor))
|
||||
{
|
||||
FTimerManager& TimerManager = World->GetTimerManager();
|
||||
TimerManager.SetTimer(TimerHandle, this, &ThisClass::OnTimer, WaitInterval, true, 0);
|
||||
Actor->OnDestroyed.AddDynamic(this, &ThisClass::OnTargetDestroyed);
|
||||
}
|
||||
else
|
||||
{
|
||||
Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
UWorld* UGIS_AsyncAction_Wait::GetWorld() const
|
||||
{
|
||||
if (WorldPtr.IsValid() && WorldPtr->IsValidLowLevelFast())
|
||||
{
|
||||
return WorldPtr.Get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AActor* UGIS_AsyncAction_Wait::GetActor() const
|
||||
{
|
||||
if (TargetActorPtr.IsValid() && TargetActorPtr->IsValidLowLevelFast())
|
||||
{
|
||||
return TargetActorPtr.Get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::Cancel()
|
||||
{
|
||||
Super::Cancel();
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::OnTargetDestroyed(AActor* DestroyedActor)
|
||||
{
|
||||
Cancel();
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::SetWorld(UWorld* NewWorld)
|
||||
{
|
||||
WorldPtr = NewWorld;
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::SetTargetActor(AActor* NewTargetActor)
|
||||
{
|
||||
TargetActorPtr = NewTargetActor;
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::SetWaitInterval(float NewWaitInterval)
|
||||
{
|
||||
WaitInterval = NewWaitInterval;
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::SetMaxWaitTimes(int32 NewMaxWaitTimes)
|
||||
{
|
||||
MaxWaitTimes = NewMaxWaitTimes;
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::OnTimer()
|
||||
{
|
||||
AActor* Actor = GetActor();
|
||||
if (!IsValid(Actor))
|
||||
{
|
||||
Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
OnExecutionAction();
|
||||
|
||||
if (MaxWaitTimes > 0)
|
||||
{
|
||||
WaitTimes++;
|
||||
if (WaitTimes > MaxWaitTimes)
|
||||
{
|
||||
Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::OnExecutionAction()
|
||||
{
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_Wait::Complete()
|
||||
{
|
||||
Super::Cancel();
|
||||
OnCompleted.Broadcast();
|
||||
Cleanup();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "Async/GIS_AsyncAction_WaitEquipmentSystem.h"
|
||||
|
||||
#include "GIS_EquipmentSystemComponent.h"
|
||||
|
||||
#include UE_INLINE_GENERATED_CPP_BY_NAME(GIS_AsyncAction_WaitEquipmentSystem)
|
||||
|
||||
UGIS_AsyncAction_WaitEquipmentSystem* UGIS_AsyncAction_WaitEquipmentSystem::WaitEquipmentSystem(UObject* WorldContext, AActor* TargetActor)
|
||||
{
|
||||
return CreateWaitAction<UGIS_AsyncAction_WaitEquipmentSystem>(WorldContext, TargetActor, 0.5, -1);
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitEquipmentSystem::OnExecutionAction()
|
||||
{
|
||||
AActor* Actor = GetActor();
|
||||
|
||||
if (UGIS_EquipmentSystemComponent* EquipmentSystem = UGIS_EquipmentSystemComponent::GetEquipmentSystemComponent(Actor))
|
||||
{
|
||||
Complete();
|
||||
}
|
||||
}
|
||||
|
||||
UGIS_AsyncAction_WaitEquipmentSystem* UGIS_AsyncAction_WaitEquipmentSystemInitialized::WaitEquipmentSystemInitialized(UObject* WorldContext, AActor* TargetActor)
|
||||
{
|
||||
return CreateWaitAction<UGIS_AsyncAction_WaitEquipmentSystemInitialized>(WorldContext, TargetActor, 0.5, -1);
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitEquipmentSystemInitialized::OnExecutionAction()
|
||||
{
|
||||
// Already found.
|
||||
UGIS_EquipmentSystemComponent* ExistingOne = EquipmentSystemPtr.IsValid() ? EquipmentSystemPtr.Get() : nullptr;
|
||||
if (IsValid(ExistingOne))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AActor* Actor = GetActor();
|
||||
if (UGIS_EquipmentSystemComponent* EquipmentSys = UGIS_EquipmentSystemComponent::GetEquipmentSystemComponent(Actor))
|
||||
{
|
||||
if (EquipmentSys->IsEquipmentSystemInitialized())
|
||||
{
|
||||
Complete();
|
||||
return;
|
||||
}
|
||||
EquipmentSystemPtr = EquipmentSys;
|
||||
EquipmentSystemPtr->OnEquipmentSystemInitializedEvent.AddDynamic(this, &ThisClass::OnSystemInitialized);
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitEquipmentSystemInitialized::Cleanup()
|
||||
{
|
||||
Super::Cleanup();
|
||||
UGIS_EquipmentSystemComponent* ExistingOne = EquipmentSystemPtr.IsValid() ? EquipmentSystemPtr.Get() : nullptr;
|
||||
|
||||
if (IsValid(ExistingOne))
|
||||
{
|
||||
ExistingOne->OnEquipmentSystemInitializedEvent.RemoveAll(this);
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitEquipmentSystemInitialized::OnSystemInitialized()
|
||||
{
|
||||
Complete();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "Async/GIS_AsyncAction_WaitInventorySystem.h"
|
||||
|
||||
#include "GIS_InventorySystemComponent.h"
|
||||
#include "GameFramework/PlayerState.h"
|
||||
|
||||
#include UE_INLINE_GENERATED_CPP_BY_NAME(GIS_AsyncAction_WaitInventorySystem)
|
||||
|
||||
UGIS_AsyncAction_WaitInventorySystem* UGIS_AsyncAction_WaitInventorySystem::WaitInventorySystem(UObject* WorldContext, AActor* TargetActor)
|
||||
{
|
||||
return CreateWaitAction<UGIS_AsyncAction_WaitInventorySystem>(WorldContext, TargetActor, 0.5, -1);
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitInventorySystem::OnExecutionAction()
|
||||
{
|
||||
AActor* Actor = GetActor();
|
||||
|
||||
if (UGIS_InventorySystemComponent* Inventory = UGIS_InventorySystemComponent::GetInventorySystemComponent(Actor))
|
||||
{
|
||||
Complete();
|
||||
}
|
||||
}
|
||||
|
||||
UGIS_AsyncAction_WaitInventorySystem* UGIS_AsyncAction_WaitInventorySystemInitialized::WaitInventorySystemInitialized(UObject* WorldContext, AActor* TargetActor)
|
||||
{
|
||||
return CreateWaitAction<UGIS_AsyncAction_WaitInventorySystemInitialized>(WorldContext, TargetActor, 0.5, -1);
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitInventorySystemInitialized::OnExecutionAction()
|
||||
{
|
||||
// Already found.
|
||||
UGIS_InventorySystemComponent* ExistingOne = InventorySysPtr.IsValid() ? InventorySysPtr.Get() : nullptr;
|
||||
if (IsValid(ExistingOne))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AActor* Actor = GetActor();
|
||||
if (UGIS_InventorySystemComponent* InventorySys = UGIS_InventorySystemComponent::GetInventorySystemComponent(Actor))
|
||||
{
|
||||
if (InventorySys->IsInventoryInitialized())
|
||||
{
|
||||
Complete();
|
||||
return;
|
||||
}
|
||||
InventorySysPtr = InventorySys;
|
||||
InventorySysPtr->OnInventorySystemInitializedEvent.AddDynamic(this, &ThisClass::OnSystemInitialized);
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitInventorySystemInitialized::Cleanup()
|
||||
{
|
||||
Super::Cleanup();
|
||||
UGIS_InventorySystemComponent* ExistingOne = InventorySysPtr.IsValid() ? InventorySysPtr.Get() : nullptr;
|
||||
if (IsValid(ExistingOne))
|
||||
{
|
||||
ExistingOne->OnInventorySystemInitializedEvent.RemoveAll(this);
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitInventorySystemInitialized::OnSystemInitialized()
|
||||
{
|
||||
Complete();
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "Async/GIS_AsyncAction_WaitItemFragmentDataChanged.h"
|
||||
#include "Engine/Engine.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "GIS_ItemFragment.h"
|
||||
#include "GIS_ItemInstance.h"
|
||||
#include "GIS_LogChannels.h"
|
||||
|
||||
#include UE_INLINE_GENERATED_CPP_BY_NAME(GIS_AsyncAction_WaitItemFragmentDataChanged)
|
||||
|
||||
UGIS_AsyncAction_WaitItemFragmentDataChanged* UGIS_AsyncAction_WaitItemFragmentDataChanged::WaitItemFragmentStateChanged(UObject* WorldContext, UGIS_ItemInstance* ItemInstance,
|
||||
TSoftClassPtr<UGIS_ItemFragment> FragmentClass)
|
||||
{
|
||||
if (!IsValid(WorldContext))
|
||||
{
|
||||
GIS_LOG(Warning, "invalid world context!")
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UWorld* World = GEngine->GetWorldFromContextObject(WorldContext, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (!IsValid(World))
|
||||
{
|
||||
GIS_LOG(Warning, "can't get world from context:%s", *GetNameSafe(WorldContext));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!IsValid(ItemInstance))
|
||||
{
|
||||
GIS_LOG(Warning, "invalid item instance");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TSubclassOf<UGIS_ItemFragment> Class = FragmentClass.LoadSynchronous();
|
||||
if (Class == nullptr)
|
||||
{
|
||||
GIS_LOG(Warning, "invalid fragment class");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UGIS_AsyncAction_WaitItemFragmentDataChanged* NewAction = NewObject<UGIS_AsyncAction_WaitItemFragmentDataChanged>(GetTransientPackage(), StaticClass());
|
||||
NewAction->ItemInstance = ItemInstance;
|
||||
NewAction->FragmentClass = Class;
|
||||
NewAction->RegisterWithGameInstance(World->GetGameInstance());
|
||||
return NewAction;
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitItemFragmentDataChanged::Activate()
|
||||
{
|
||||
UGIS_ItemInstance* Item = ItemInstance.IsValid() ? ItemInstance.Get() : nullptr;
|
||||
if (IsValid(Item))
|
||||
{
|
||||
Item->OnFragmentStateAddedEvent.AddDynamic(this, &ThisClass::OnFragmentStateChanged);
|
||||
Item->OnFragmentStateUpdatedEvent.AddDynamic(this, &ThisClass::OnFragmentStateChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitItemFragmentDataChanged::Cancel()
|
||||
{
|
||||
Super::Cancel();
|
||||
UGIS_ItemInstance* Item = ItemInstance.IsValid() ? ItemInstance.Get() : nullptr;
|
||||
if (IsValid(Item))
|
||||
{
|
||||
Item->OnFragmentStateAddedEvent.RemoveAll(this);
|
||||
Item->OnFragmentStateUpdatedEvent.RemoveAll(this);
|
||||
ItemInstance.Reset();
|
||||
FragmentClass = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void UGIS_AsyncAction_WaitItemFragmentDataChanged::OnFragmentStateChanged(const UGIS_ItemFragment* Fragment, const FInstancedStruct& State)
|
||||
{
|
||||
if (ShouldBroadcastDelegates())
|
||||
{
|
||||
if (Fragment != nullptr && Fragment->GetClass() == FragmentClass)
|
||||
{
|
||||
OnStateChanged.Broadcast(Fragment, State);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user