Files
PHY/Plugins/GIS/Source/GenericInventorySystem/Public/Pickups/GIS_ItemPickupComponent.h
2026-03-03 01:23:02 +08:00

75 lines
2.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "GIS_PickupComponent.h"
#include "GIS_ItemPickupComponent.generated.h"
class UGIS_InventorySystemComponent;
class UGIS_WorldItemComponent;
class UGIS_ItemCollection;
/**
* Component for picking up a single item, requiring a WorldItemComponent on the same actor.
* 用于拾取单个道具的组件需要与GIS_WorldItemComponent共存于同一演员。
*/
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
class GENERICINVENTORYSYSTEM_API UGIS_ItemPickupComponent : public UGIS_PickupComponent
{
GENERATED_BODY()
public:
/**
* Performs the pickup logic, adding the item to the picker's inventory.
* 执行拾取逻辑,将道具添加到拾取者的库存。
* @param Picker The inventory system component of the actor performing the pickup. 执行拾取的演员的库存系统组件。
* @return True if the pickup was successful, false otherwise. 如果拾取成功则返回true否则返回false。
*/
virtual bool Pickup(UGIS_InventorySystemComponent* Picker) override;
/**
* Gets the associated world item component.
* 获取关联的世界道具组件。
* @return The world item component, or nullptr if not found. 世界道具组件如果未找到则返回nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GIS|Pickup")
UGIS_WorldItemComponent* GetWorldItem() const;
protected:
/**
* Specifies the collection in the picker's inventory to add the item to (defaults to Item.Collection.Main if not set).
* 指定拾取者库存中要添加道具的集合如果未设置默认为Item.Collection.Main
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Pickup", meta=(Categories="GIS.Collection"))
FGameplayTag CollectionTag;
/**
* If true, the pickup fails if the full amount cannot be added to the inventory.
* 如果为true当无法将全部数量添加到库存集合时拾取失败。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Pickup")
bool bFailIfFullAmountNotFit = false;
/**
* Called when the game starts to initialize the component.
* 游戏开始时调用以初始化组件。
*/
virtual void BeginPlay() override;
/**
* Attempts to add the item to the picker's inventory collection.
* 尝试将道具添加到拾取者的库存集合。
* @param Picker The inventory system component of the actor performing the pickup. 执行拾取的演员的库存系统组件。
* @return True if the addition was successful, false otherwise. 如果添加成功则返回true否则返回false。
*/
bool TryAddToCollection(UGIS_InventorySystemComponent* Picker);
/**
* The associated world item component.
* 关联的世界道具组件。
*/
UPROPERTY()
TObjectPtr<UGIS_WorldItemComponent> WorldItemComponent;
};