UE4 UDecalComponent用法
來(lái)源:
52vr |
責(zé)任編輯:傳說(shuō)的落葉 |
發(fā)布時(shí)間: 2019-06-06 08:25 | 瀏覽量:
4.11的TopDown Sample Project中,增加了一個(gè)新功能:用UDecalComponent顯示印花圖案,特點(diǎn)是可以在非平面的地形上,按照地面的凹凸地勢(shì)自動(dòng)貼緊地面。
定義:
- /** A decal that projects to the cursor location. */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
- class UDecalComponent* CursorToWorld;
構(gòu)造函數(shù)中對(duì)其初始化:
- // Create a decal in the world to show the cursor's location
- CursorToWorld = CreateDefaultSubobject<UDecalComponent>("CursorToWorld");
- CursorToWorld->AttachTo(RootComponent);
- static ConstructorHelpers::FObjectFinder<UMaterial> DecalMaterialAsset(TEXT("Material'/Game/TopDownCPP/Blueprints/M_Cursor_Decal.M_Cursor_Decal'"));
- if (DecalMaterialAsset.Succeeded())
- {
- CursorToWorld->SetDecalMaterial(DecalMaterialAsset.Object);
- }
- CursorToWorld->DecalSize = FVector(16.0f, 32.0f, 32.0f);
- CursorToWorld->SetRelativeRotation(FRotator(90.0f, 0.0f, 0.0f).Quaternion());
跟隨鼠標(biāo)位置在地面上繪制:
- void ANetworkTestCharacter::Tick(float DeltaSeconds)
- {
- if (CursorToWorld != nullptr)
- {
- if (APlayerController* PC = Cast<APlayerController>(GetController()))
- {
- FHitResult TraceHitResult;
- PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult);
- FVector CursorFV = TraceHitResult.ImpactNormal;
- FRotator CursorR = CursorFV.Rotation();
- CursorToWorld->SetWorldLocation(TraceHitResult.Location);
- CursorToWorld->SetWorldRotation(CursorR);
- }
- }
- }
-
分享到:
相關(guān)文章
網(wǎng)友評(píng)論
您需要登錄后才可以發(fā)帖 登錄 | 立即注冊(cè)
關(guān)閉
- 用戶名:
- 密 碼:
- 驗(yàn)證碼: 看不清? 點(diǎn)擊更換
- 忘記密碼?
全部評(píng)論:0條
推薦
熱門