Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 언리얼
- VUE
- 언리얼뮤지컬
- Express
- 정글사관학교
- 스터디
- node
- 언리얼프로그래머
- Ajax
- 마인크래프트뮤지컬
- Unseen
- Bootstrap4
- EnhancedInput
- 카렌
- 프메
- 미니프로젝트
- 프린세스메이커
- 레베카
- Enhanced Input System
- 으
- 디자드
- 게임개발
- 알고풀자
- flask
- 파이썬서버
- 데이터베이스
- Jinja2
- R
- 스마일게이트
- JWT
Archives
- Today
- Total
Today, I will
[Unreal] UI Change Control 본문
언리얼에서 게임 상황에 따라서 viewport 다른 UI가 보여질 수 있도록 ui change 기능을 구현해보도록 한다.
(1) score이 보여지는 화면
(2) Enemy한테 닿아 Game Over 화면
게임모드에서 UI들을 들고 있고 다른 액터 클래스들에서 게임모드의 함수들을 불러 결국 게임모드 안에서 UI를 change하도록 짤 수 있다.
게임모드베이스.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "ShootingGameModeBase.generated.h"
/**
*
*/
UCLASS()
class GIT_TEMP_API AShootingGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category ="UMG_Game")
void ChangeMenuWidget(TSubclassOf<UUserWidget> NewWidgetClass);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UMG_Game")
int CurrentScore;
UFUNCTION(BlueprintCallable, Category = "UMG_Game")
void AddScore(int score);
UFUNCTION(BlueprintCallable, Category = "UMG_Game")
void GameOver();
protected:
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="UMG_Game")
TSubclassOf<UUserWidget> StartingWidgeteClass;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UMG_Game")
TSubclassOf<UUserWidget> GameEndWidgeteClass;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UMG_Game")
UUserWidget* CurrentWidget;
};
미리 위젯 블루프린트를 제작해두었다.
게임모드 베이스의 umg위젯 카테고리에 적절한 ui를 넣어준다.
게임모드 베이스.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "ShootingGameModeBase.h"
#include <Blueprint/UserWidget.h>
void AShootingGameModeBase::AddScore(int score)
{
CurrentScore += score;
}
void AShootingGameModeBase::BeginPlay()
{
Super::BeginPlay();
ChangeMenuWidget(StartingWidgeteClass);
}
void AShootingGameModeBase::GameOver()
{
ChangeMenuWidget(GameEndWidgeteClass);
}
void AShootingGameModeBase::ChangeMenuWidget(TSubclassOf<UUserWidget> NewWidgetClass)
{
if (CurrentWidget!= nullptr) {
CurrentWidget->RemoveFromViewport();
CurrentWidget = nullptr;
}
if (NewWidgetClass != nullptr)
{
CurrentWidget = CreateWidget(GetWorld(), NewWidgetClass);
if (CurrentWidget!=nullptr) {
CurrentWidget->AddToViewport();
}
}
}
'Unreal' 카테고리의 다른 글
[Unreal] enum을 이용한 enemy 이름짓기 (0) | 2023.10.27 |
---|---|
[Unreal] 이중 포문을 활용한 총알 패턴 적용 (1) | 2023.10.27 |
[Unreal] 델리게이트를 활용하여 Bullet으로 enemy 제거 (1) | 2023.10.24 |
[Unreal] 언리얼 좌표계 Pitch, Roll, Yaw 이해와 짐벌락 이슈 해결 (0) | 2023.10.23 |
[Unreal] Meta Human 제작 후 언리얼 3D 캐릭터에 입히기 (0) | 2023.10.20 |