박하의 나날

0607/그냥정리

프로그래밍/Unreal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
UCLASS()
class FPSGAMEMODE_API APickupItem: public AActor{
    GENERATED_BODY()
    
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
    FString Name;
 
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
    int32 Quantity; //얻는 개수
 
    UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Item)
    USphereComponent* ProxSphere; // 아이템을 줍는데 사용되는 충돌 구체
 
    UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Item)
    UStaticMeshComponent* Mesh; //아이템 메시
 
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Item)
    UTexture2D* Icon; 
 
    UFUNCTION(BlueprintNativeEvent, Category = Collision) //proxSphere 안으로 무언가 들어오면 이 함수가 실행된다.
    void Prox(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep const FHitResult *SweepResult);
    virtual void Prox(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep const FHitResult *SweepResult);
}
cs

 

1
2
3
4
5
6
7
8
9
10
11
12
13
APickupItem::APickupItem(){
    Name = "UNKNOWN ITEM";
    Quantity = 0
    //언리얼 객체 초기화
    ProxSphere = CreateDefaultSubobject<USphereComponent>(TEXT("Prox Sphere"));
    Mesh = CreateDefaultSubobject<UMeshComponent>(TEXT("Mesh"));
    //루트 객체를 메시로
    RootComponent = Mesh;
    Mesh->SetSimulatePhysics(true);
    //충돌 구체가 다른 액터랑 겹치면 Prox()함수 실행되게
    ProxSphere->OnComponentBeginOverlap.AddDynamic(this&APickupItem::Prox);
    ProxSphere->AttachTo(Mesh); 
}
cs

 

2,3) 이름이랑 수량 초기화

5,6) CreateDefaultSubobject를 사용해서 초기화.

초기화된 객체는 상속받은 기본값을 가지고 있을수는 있지만, mesh는 비어있는 채로 시작할 것이다.

나중에 블루프린트에서 실제 mesh 로드할것.

9)mesh에서 실제 물리 시뮬레이트. 습득 아이템을 버리거나 이동했을때 아이템이 굴러가거나 튀어가도록.

12)습득 아이템의 ProxSphere 컴포넌트가 mesh root 컴포넌트와 연결되었는 확인하는 것.

레벨상 mesh가 움직였을때 ProxSphere가 따라간다.

이부분 안하면 ProxSphere가 mesh움직일때 안따라감.