Last active
September 23, 2016 16:34
-
-
Save ydakoukn/7550d8076ecc7cf4a25ddafcdb7ea581 to your computer and use it in GitHub Desktop.
[UE4]キューブを表示できるデバッグコマンドの追加方法
This file contains 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
// Sets default values | |
AMyCubeActorTest::AMyCubeActorTest() | |
{ | |
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. | |
PrimaryActorTick.bCanEverTick = true; | |
// ダミーのルートコンポーネントを追加 | |
DummyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent")); | |
RootComponent = DummyRoot; | |
// メッシュコンポーネント作成 | |
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh")); | |
// メッシュデータ読み込み | |
const ConstructorHelpers::FObjectFinder<UStaticMesh> MeshObj(TEXT("/Game/StarterContent/Shapes/Shape_Cube")); | |
// メッシュ設定 | |
MeshComp->SetStaticMesh(MeshObj.Object); | |
// ルートコンポーネントにアタッチの | |
MeshComp->AttachTo(RootComponent); | |
} |
This file contains 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
AMyPlayerController::AMyPlayerController() { | |
// ブループリントを読み込む | |
ConstructorHelpers::FObjectFinder<UBlueprint> blueprintObject(TEXT("/Game/Blueprints/Actors/Test/Cube.Cube")); | |
if (blueprintObject.Succeeded()) { | |
UE_LOG(LogTemp, Warning, TEXT("ブループリント読み込み")); | |
} | |
else { | |
UE_LOG(LogTemp, Warning, TEXT("失敗")); | |
} | |
m_actorBaseClass = (UClass*)blueprintObject.Object->GeneratedClass; | |
} | |
// この関数がでばっぐデバッグコマンドとなりう追加される | |
// コンソールで打ち込んだ時この中の処理が実行される | |
void AMyPlayerController::ChangeBoxNum(int32 x, int32 y, int32 z) { | |
UCustomGameInstance* gameInstance = static_cast<UCustomGameInstance*>(UGameplayStatics::GetGameInstance(this)); | |
if (!gameInstance) return; | |
AMyPlayerController* pc = Cast<AMyPlayerController>(gameInstance->GetFirstLocalPlayerController()); | |
UWorld* world = gameInstance->GetWorld(); | |
if (pc == nullptr)return; | |
// 削除 | |
for (int i = 0; i < m_cubeList.Num();++i) | |
{ | |
world->DestroyActor(m_cubeList[i]); | |
} | |
// コマンド呼び出し | |
//pc->ConsoleCommand(TEXT("ce Cube"), false); | |
// 空にする | |
m_cubeList.Empty(); | |
if (pc != nullptr&&world != nullptr) { | |
const int RangeValue = 150; // キューブ間の間隔 | |
// オブジェクトの生成 | |
// キューブを縦、横、奥に決められた数だけ等間隔に配置 | |
for (int lx = 0; lx < x; ++lx) { | |
for (int ly = 0; ly < y; ++ly) { | |
for (int lz = 0; lz < z; ++lz) { | |
FTransform trans; | |
FVector position; | |
position.X = lx *RangeValue; | |
position.Y = ly *RangeValue; | |
position.Z = lz *RangeValue; | |
pc->m_cubeList.Add(world->SpawnActor<AActor>(m_actorBaseClass, position, FRotator::ZeroRotator)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment