第一次提交

This commit is contained in:
不明不惑
2026-03-03 01:23:02 +08:00
commit 3e434877e8
1053 changed files with 102411 additions and 0 deletions

View File

@@ -0,0 +1,239 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GIS_LogChannels.h"
#include "Engine/TimerHandle.h"
#include "Engine/Engine.h"
#include "UObject/Object.h"
#include "Engine/CancellableAsyncAction.h"
#include "GIS_AsyncAction_Wait.generated.h"
/**
* Delegate triggered when an async wait action completes or is cancelled.
* 异步等待动作完成或取消时触发的委托。
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FGIS_AsyncAction_WaitSignature);
/**
* Base class for asynchronous wait actions on an actor.
* 在演员上执行异步等待动作的基类。
* @details Provides functionality to wait for specific conditions on an actor, with timer-based checks.
* @细节 提供在演员上等待特定条件的功能,通过定时器检查。
*/
UCLASS(Abstract)
class GENERICINVENTORYSYSTEM_API UGIS_AsyncAction_Wait : public UCancellableAsyncAction
{
GENERATED_BODY()
public:
/**
* Constructor for the async wait action.
* 异步等待动作的构造函数。
*/
UGIS_AsyncAction_Wait();
/**
* Delegate triggered when the wait action completes successfully.
* 等待动作成功完成时触发的委托。
*/
UPROPERTY(BlueprintAssignable)
FGIS_AsyncAction_WaitSignature OnCompleted;
/**
* Delegate triggered when the wait action is cancelled.
* 等待动作取消时触发的委托。
*/
UPROPERTY(BlueprintAssignable)
FGIS_AsyncAction_WaitSignature OnCancelled;
/**
* Gets the world associated with this action.
* 获取与此动作关联的世界。
* @return The world object, or nullptr if not set. 世界对象如果未设置则返回nullptr。
*/
virtual UWorld* GetWorld() const override;
/**
* Gets the target actor for the wait action.
* 获取等待动作的目标演员。
* @return The target actor, or nullptr if not set. 目标演员如果未设置则返回nullptr。
*/
virtual AActor* GetActor() const;
/**
* Activates the wait action, starting the timer.
* 激活等待动作,启动定时器。
*/
virtual void Activate() override;
/**
* Completes the wait action, triggering the OnCompleted delegate.
* 完成等待动作触发OnCompleted委托。
*/
virtual void Complete();
/**
* Cancels the wait action, triggering the OnCancelled delegate.
* 取消等待动作触发OnCancelled委托。
*/
virtual void Cancel() override;
/**
* Determines whether delegates should be broadcast.
* 确定是否应广播委托。
* @return True if delegates should be broadcast, false otherwise. 如果应广播委托则返回true否则返回false。
*/
virtual bool ShouldBroadcastDelegates() const override;
/**
* Called when the target actor is destroyed.
* 目标演员销毁时调用。
* @param DestroyedActor The actor that was destroyed. 被销毁的演员。
*/
UFUNCTION()
virtual void OnTargetDestroyed(AActor* DestroyedActor);
protected:
/**
* Creates a new wait action instance.
* 创建新的等待动作实例。
* @param WorldContext The world context object to get the world reference. 用于获取世界引用的世界上下文对象。
* @param TargetActor The target actor to wait for. 要等待的目标演员。
* @param WaitInterval The interval between checks (in seconds). 检查间隔(以秒为单位)。
* @param MaxWaitTimes The maximum number of checks before timeout (-1 for no limit). 最大检查次数,超时前(-1表示无限制
* @return The created wait action, or nullptr if invalid parameters. 创建的等待动作如果参数无效则返回nullptr。
* @details Logs warnings if the world context, world, target actor, or wait interval is invalid.
* @细节 如果世界上下文、世界、目标演员或等待间隔无效,则记录警告。
*/
template <typename ActionType = UGIS_AsyncAction_Wait>
static ActionType* CreateWaitAction(UObject* WorldContext, AActor* TargetActor, float WaitInterval, int32 MaxWaitTimes)
{
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(TargetActor))
{
GIS_LOG(Warning, "invalid target actor.");
return nullptr;
}
if (WaitInterval <= 0.f)
{
GIS_LOG(Warning, "WaitInterval %f must be greater than zero!", WaitInterval);
return nullptr;
}
ActionType* NewAction = Cast<ActionType>(NewObject<UGIS_AsyncAction_Wait>(GetTransientPackage(), ActionType::StaticClass()));
NewAction->SetWorld(World);
NewAction->SetTargetActor(TargetActor);
NewAction->SetWaitInterval(WaitInterval);
NewAction->SetMaxWaitTimes(MaxWaitTimes);
NewAction->RegisterWithGameInstance(World->GetGameInstance());
return NewAction;
}
/**
* Sets the world for the wait action.
* 设置等待动作的世界。
* @param NewWorld The world to set. 要设置的世界。
*/
void SetWorld(UWorld* NewWorld);
/**
* Sets the target actor for the wait action.
* 设置等待动作的目标演员。
* @param NewTargetActor The target actor to set. 要设置的目标演员。
*/
void SetTargetActor(AActor* NewTargetActor);
/**
* Sets the interval between checks.
* 设置检查间隔。
* @param NewWaitInterval The interval (in seconds). 间隔(以秒为单位)。
*/
void SetWaitInterval(float NewWaitInterval);
/**
* Sets the maximum number of checks before timeout.
* 设置超时前的最大检查次数。
* @param NewMaxWaitTimes The maximum number of checks (-1 for no limit). 最大检查次数(-1表示无限制
*/
void SetMaxWaitTimes(int32 NewMaxWaitTimes);
/**
* Stops the timer for the wait action.
* 停止等待动作的定时器。
*/
void StopWaiting();
/**
* Called when the timer ticks to check the wait condition.
* 定时器触发时调用以检查等待条件。
*/
UFUNCTION()
void OnTimer();
/**
* Cleans up resources used by the wait action.
* 清理等待动作使用的资源。
*/
virtual void Cleanup();
/**
* Executes the specific wait condition check.
* 执行特定的等待条件检查。
*/
UFUNCTION()
virtual void OnExecutionAction();
private:
/**
* Weak reference to the world for the wait action.
* 等待动作的世界的弱引用。
*/
TWeakObjectPtr<UWorld> WorldPtr{nullptr};
/**
* Weak reference to the target actor for the wait action.
* 等待动作的目标演员的弱引用。
*/
UPROPERTY()
TWeakObjectPtr<AActor> TargetActorPtr{nullptr};
/**
* Handle for the timer used to check the wait condition.
* 用于检查等待条件的定时器句柄。
*/
UPROPERTY()
FTimerHandle TimerHandle;
/**
* Interval between checks (in seconds).
* 检查间隔(以秒为单位)。
*/
float WaitInterval = 0.2f;
/**
* Current number of checks performed.
* 当前执行的检查次数。
*/
int32 WaitTimes = 0;
/**
* Maximum number of checks before timeout (-1 for no limit).
* 超时前的最大检查次数(-1表示无限制
*/
int32 MaxWaitTimes{-1};
};

View File

@@ -0,0 +1,84 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GIS_AsyncAction_Wait.h"
#include "GIS_AsyncAction_WaitEquipmentSystem.generated.h"
class UGIS_EquipmentSystemComponent;
/**
* Async action to wait for a valid equipment system component on an actor.
* 在演员上等待有效装备系统组件的异步动作。
*/
UCLASS()
class GENERICINVENTORYSYSTEM_API UGIS_AsyncAction_WaitEquipmentSystem : public UGIS_AsyncAction_Wait
{
GENERATED_BODY()
public:
/**
* Waits for a valid equipment system component on the target actor.
* 在目标演员上等待有效的装备系统组件。
* @param WorldContext The world context object to get the world reference. 用于获取世界引用的世界上下文对象。
* @param TargetActor The target actor to wait for. 要等待的目标演员。
* @return The created wait action. 创建的等待动作。
*/
UFUNCTION(BlueprintCallable, Category="GIS|Async", meta = (WorldContext = "WorldContext", DefaultToSelf="TargetActor", BlueprintInternalUseOnly = "true"))
static UGIS_AsyncAction_WaitEquipmentSystem* WaitEquipmentSystem(UObject* WorldContext, AActor* TargetActor);
protected:
/**
* Checks for the presence of a valid equipment system component.
* 检查是否存在有效的装备系统组件。
*/
virtual void OnExecutionAction() override;
};
/**
* Async action to wait for a valid and initialized equipment system component on an actor.
* 在演员上等待有效且已初始化的装备系统组件的异步动作。
*/
UCLASS()
class GENERICINVENTORYSYSTEM_API UGIS_AsyncAction_WaitEquipmentSystemInitialized : public UGIS_AsyncAction_WaitEquipmentSystem
{
GENERATED_BODY()
public:
/**
* Waits for a valid and initialized equipment system component on the target actor.
* 在目标演员上等待有效且已初始化的装备系统组件。
* @param WorldContext The world context object to get the world reference. 用于获取世界引用的世界上下文对象。
* @param TargetActor The target actor to wait for. 要等待的目标演员。
* @return The created wait action. 创建的等待动作。
*/
UFUNCTION(BlueprintCallable, Category="GIS|Async", meta = (WorldContext = "WorldContext", DefaultToSelf="TargetActor", BlueprintInternalUseOnly = "true"))
static UGIS_AsyncAction_WaitEquipmentSystem* WaitEquipmentSystemInitialized(UObject* WorldContext, AActor* TargetActor);
protected:
/**
* Checks for the presence and initialization of the equipment system component.
* 检查装备系统组件的存在和初始化状态。
*/
virtual void OnExecutionAction() override;
/**
* Cleans up resources and event bindings.
* 清理资源和事件绑定。
*/
virtual void Cleanup() override;
/**
* Called when the equipment system component is initialized.
* 装备系统组件初始化时调用。
*/
UFUNCTION()
virtual void OnSystemInitialized();
/**
* Weak reference to the equipment system component being waited for.
* 等待的装备系统组件的弱引用。
*/
TWeakObjectPtr<UGIS_EquipmentSystemComponent> EquipmentSystemPtr;
};

View File

@@ -0,0 +1,83 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GIS_AsyncAction_Wait.h"
#include "GIS_InventoryMeesages.h"
#include "GIS_AsyncAction_WaitInventorySystem.generated.h"
/**
* Async action to wait for a valid inventory system component on an actor.
* 在演员上等待有效库存系统组件的异步动作。
*/
UCLASS()
class GENERICINVENTORYSYSTEM_API UGIS_AsyncAction_WaitInventorySystem : public UGIS_AsyncAction_Wait
{
GENERATED_BODY()
public:
/**
* Waits for a valid inventory system component on the target actor.
* 在目标演员上等待有效的库存系统组件。
* @param WorldContext The world context object to get the world reference. 用于获取世界引用的世界上下文对象。
* @param TargetActor The target actor to wait for. 要等待的目标演员。
* @return The created wait action. 创建的等待动作。
*/
UFUNCTION(BlueprintCallable, Category="GIS|Async", meta = (WorldContext = "WorldContext", DefaultToSelf="TargetActor", BlueprintInternalUseOnly = "true"))
static UGIS_AsyncAction_WaitInventorySystem* WaitInventorySystem(UObject* WorldContext, AActor* TargetActor);
protected:
/**
* Checks for the presence of a valid inventory system component.
* 检查是否存在有效的库存系统组件。
*/
virtual void OnExecutionAction() override;
};
/**
* Async action to wait for a valid and initialized inventory system component on an actor.
* 在演员上等待有效且已初始化的库存系统组件的异步动作。
*/
UCLASS()
class GENERICINVENTORYSYSTEM_API UGIS_AsyncAction_WaitInventorySystemInitialized : public UGIS_AsyncAction_WaitInventorySystem
{
GENERATED_BODY()
public:
/**
* Waits for a valid and initialized inventory system component on the target actor.
* 在目标演员上等待有效且已初始化的库存系统组件。
* @param WorldContext The world context object to get the world reference. 用于获取世界引用的世界上下文对象。
* @param TargetActor The target actor to wait for. 要等待的目标演员。
* @return The created wait action. 创建的等待动作。
*/
UFUNCTION(BlueprintCallable, Category="GIS|Async", meta = (WorldContext = "WorldContext", DefaultToSelf="TargetActor", BlueprintInternalUseOnly = "true"))
static UGIS_AsyncAction_WaitInventorySystem* WaitInventorySystemInitialized(UObject* WorldContext, AActor* TargetActor);
protected:
/**
* Checks for the presence and initialization of the inventory system component.
* 检查库存系统组件的存在和初始化状态。
*/
virtual void OnExecutionAction() override;
/**
* Cleans up resources and event bindings.
* 清理资源和事件绑定。
*/
virtual void Cleanup() override;
/**
* Called when the inventory system component is initialized.
* 库存系统组件初始化时调用。
*/
UFUNCTION()
virtual void OnSystemInitialized();
/**
* Weak reference to the inventory system component being waited for.
* 等待的库存系统组件的弱引用。
*/
TWeakObjectPtr<UGIS_InventorySystemComponent> InventorySysPtr;
};

View File

@@ -0,0 +1,56 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Engine/CancellableAsyncAction.h"
#include "Templates/SubclassOf.h"
#include "Runtime/Launch/Resources/Version.h"
#if ENGINE_MINOR_VERSION < 5
#include "InstancedStruct.h"
#else
#include "StructUtils/InstancedStruct.h"
#endif
#include "GIS_AsyncAction_WaitItemFragmentDataChanged.generated.h"
class UGIS_ItemFragment;
class UGIS_ItemInstance;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FGIS_WaitFragmentStateChangedSignature, const UGIS_ItemFragment*, Fragment, const FInstancedStruct&, Data);
/**
* Async action to wait for a fragment data changed on an item instance.
* 在道具实例上等待指定道具片段的运行时数据变更。
*/
UCLASS()
class GENERICINVENTORYSYSTEM_API UGIS_AsyncAction_WaitItemFragmentDataChanged : public UCancellableAsyncAction
{
GENERATED_BODY()
public:
/**
* Wait for a fragment data changed on an item instance.
* 在道具实例上等待指定道具片段的运行时数据变更。
* @param WorldContext The world context object to get the world reference. 用于获取世界引用的世界上下文对象。
* @param ItemInstance The target item instance to wait for. 要等待的目标道具。
* @param FragmentClass The fragment type to wait for. 要等待的片段类型。
* @return The created wait action. 创建的等待动作。
*/
UFUNCTION(BlueprintCallable, Category="GIS|Async", meta = (WorldContext = "WorldContext", DefaultToSelf="ItemInstnace", BlueprintInternalUseOnly = "true"))
static UGIS_AsyncAction_WaitItemFragmentDataChanged* WaitItemFragmentStateChanged(UObject* WorldContext, UGIS_ItemInstance* ItemInstance, TSoftClassPtr<UGIS_ItemFragment> FragmentClass);
virtual void Activate() override;
virtual void Cancel() override;
UPROPERTY(BlueprintAssignable, Category="GIS|Async")
FGIS_WaitFragmentStateChangedSignature OnStateChanged;
protected:
UFUNCTION()
void OnFragmentStateChanged(const UGIS_ItemFragment* Fragment, const FInstancedStruct& State);
TWeakObjectPtr<UGIS_ItemInstance> ItemInstance;
TSubclassOf<UGIS_ItemFragment> FragmentClass;
};