zoukankan      html  css  js  c++  java
  • UE4静态网格体一些操作

    0.头

    #include "Components/StaticMeshComponent.h"

    1.定义

    UPROPERTY(VisibleAnywhere, Category = Body)
    UStaticMeshComponent* EnemyBody;

    2.创建

    EnemyBody = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Body"));

    这个括号里接受的是FName类型,注意转换

    例如:

    FString BlockName = TEXT("block") + FString::FromInt(i);
    Block[i] = CreateDefaultSubobject<UStaticMeshComponent>(FName(*BlockName));

    3.找

    static ConstructorHelpers::FObjectFinder<UStaticMesh>CylinderObj(TEXT("'/Game/StarterContent/Shapes/Shape_Cylinder'"));//#include "UObject/ConstructorHelpers.h"
        
    if (CylinderObj.Succeeded()) {
        EnemyBody->SetStaticMesh(CylinderObj.Object);
    }

    4.设置

    EnemyBody->SetRelativeScale3D(FVector(0.7f, 0.7f, 1.0f));
    EnemyBody->SetRelativeLocation(FVector(0, 0, -50));
    EnemyBody->SetupAttachment(RootComponent);
    //EnemyBody->SetVisibility(false);     wow这个方法可以控制staticmesh组件的可见哈哈哈终于找到了!

    5.关于材质

    5.1声明

    class UMaterialInterface* DefaultMaterial;
    class UMaterialInterface* VulnerableMaterial;

    5.2赋值

    5.2.1从Actor实例上获取

    DefaultMaterial = EnemyBody->GetMaterial(0);

    5.2.2从本地文件获取

    static ConstructorHelpers::FObjectFinder<UMaterial>VulnerableMat(TEXT("Material'/Game/Materials/M_Enemy_Vulnerable.M_Enemy_Vulnerable'"));

     if (VulnerableMat.Succeeded()) {
       VulnerableMaterial = Cast< UMaterialInterface>(VulnerableMat.Object);
     }

    5.3使用

    EnemyBody->SetMaterial(0, VulnerableMaterial);
    EnemyBody->SetMaterial(0, DefaultMaterial);

    以上

  • 相关阅读:
    Understanding performance, load and stress testing
    添加查看原型的插件
    Navicat Premium 15安装破解
    APP 测试 与 WEB 测试的本质区别
    app专项测试(稳定性测试、安全性测试)
    ubantu在登录界面一致循环的问题
    Ubuntu虚拟机安装
    装WIN7
    Linux线程模型浅析
    django中常用的数据查询方法
  • 原文地址:https://www.cnblogs.com/2017SSY/p/13700998.html
Copyright © 2011-2022 走看看