Created
March 11, 2023 02:45
-
-
Save CoffeeVampir3/ca8e53665a26ec8f2cc7d396d516ed4a to your computer and use it in GitHub Desktop.
part of an inventory example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill out your copyright notice in the Description page of Project Settings. | |
#include "InventoryComponent.h" | |
// Sets default values for this component's properties | |
UInventoryComponent::UInventoryComponent() | |
{ | |
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features | |
// off to improve performance if you don't need them. | |
PrimaryComponentTick.bCanEverTick = true; | |
// ... | |
} | |
// Called when the game starts | |
void UInventoryComponent::BeginPlay() | |
{ | |
Super::BeginPlay(); | |
// ... | |
} | |
// Called every frame | |
void UInventoryComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) | |
{ | |
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); | |
// ... | |
} | |
FGuid UInventoryComponent::AddInventoryItem(UInventoryItem* ItemTemplate) | |
{ | |
const FItemInstance Inst {ItemTemplate, FGuid::NewGuid()}; | |
IdToItem.Add(Inst.ItemId, Inst); | |
return Inst.ItemId; | |
} | |
void UInventoryComponent::RemoveInventoryItem(FGuid ItemId) | |
{ | |
IdToItem.Remove(ItemId); | |
} | |
void UInventoryComponent::SwapInventoryItem(FGuid ItemIdLeft, FGuid ItemIdRight) | |
{ | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill out your copyright notice in the Description page of Project Settings. | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "InventoryItem.h" | |
#include "Components/ActorComponent.h" | |
#include "InventoryComponent.generated.h" | |
USTRUCT(BlueprintType) | |
struct FItemInstance | |
{ | |
GENERATED_BODY() | |
UPROPERTY(BlueprintReadOnly) | |
UInventoryItem* ItemTemplate; | |
UPROPERTY(BlueprintReadOnly) | |
FGuid ItemId; | |
}; | |
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) | |
class GRIMFUTURE_API UInventoryComponent : public UActorComponent | |
{ | |
GENERATED_BODY() | |
public: | |
// Sets default values for this component's properties | |
UInventoryComponent(); | |
protected: | |
// Called when the game starts | |
virtual void BeginPlay() override; | |
UPROPERTY(BlueprintReadOnly) | |
TMap<FGuid, FItemInstance> IdToItem; | |
public: | |
// Called every frame | |
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; | |
UFUNCTION(BlueprintCallable) | |
FGuid AddInventoryItem(UInventoryItem* ItemTemplate); | |
UFUNCTION(BlueprintCallable) | |
void RemoveInventoryItem(FGuid ItemId); | |
UFUNCTION(BlueprintCallable) | |
void SwapInventoryItem(FGuid ItemIdLeft, FGuid ItemIdRight); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill out your copyright notice in the Description page of Project Settings. | |
#include "InventoryItem.h" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill out your copyright notice in the Description page of Project Settings. | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "Engine/DataAsset.h" | |
#include "InventoryItem.generated.h" | |
/** | |
* | |
*/ | |
UCLASS() | |
class GRIMFUTURE_API UInventoryItem : public UDataAsset | |
{ | |
GENERATED_BODY() | |
public: | |
UPROPERTY(EditAnywhere, BlueprintReadOnly) | |
FString ItemName; | |
UPROPERTY(EditAnywhere, BlueprintReadOnly) | |
FString ItemDescription; | |
UPROPERTY(EditAnywhere, BlueprintReadOnly) | |
int Value; | |
UPROPERTY(EditAnywhere, BlueprintReadOnly) | |
int Rarity; | |
UPROPERTY(EditAnywhere, BlueprintReadOnly) | |
UTexture2D* ItemThumbnail; | |
UPROPERTY(EditAnywhere, BlueprintReadOnly) | |
USkeletalMesh* ItemMesh; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment