本人最近几天一直想写一个赛道构建的例子,一下使用UnrealReal4中spline,splinemesh组件。具体怎么用大家去看官方的wiki就行了,这里直接贴代码`。
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "RoadSpline.generated.h"
class USplineComponent;
class USplineMeshComponent;
class UTextRenderComponent;
USTRUCT()
struct FSplineRoadData
{
GENERATED_USTRUCT_BODY()
UPROPERTY( )
bool LeftGuardRail;
UPROPERTY()
bool RightGuardRail;
UPROPERTY( )
float TrackBank;
UPROPERTY( )
float TrackWidth;
UPROPERTY( )
float TrackThickness;
FSplineRoadData()
: LeftGuardRail(true)
, RightGuardRail(true)
, TrackBank(0.0f)
, TrackWidth(1.0f)
, TrackThickness(1.0f)
{
}
};
UCLASS()
class RACER_API ARoadSpline : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ARoadSpline();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
virtual void OnConstruction(const FTransform& Transform);
USplineMeshComponent* AddTrackElement(int index,UStaticMesh* mesh);
virtual void UpdateSplineMesh(TArray<USplineMeshComponent*>& splineArray);
virtual UTextRenderComponent* DrawTrackNumber( int index );
public:
UPROPERTY(EditDefaultsOnly, Category = "Road Components")
USplineComponent* mSplineComponent;
UPROPERTY( )