Files
UnrealEngineUWP/Engine/Documentation/Source/Programming/QuickStart/4/QuickStart_4.CHN.udn
Jian Zhang d944c5833a #loc UE4DocCHN
[CL 2598589 by Jian Zhang in Main branch]
2015-06-24 04:13:09 -04:00

117 lines
3.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Availability: Public
Title:4. 测试您的代码
Crumbs:%ROOT%, Programming, Programming/QuickStart
Description:在您的关卡中创建测试对象
[VAR:Steps]
[OBJECT:Navigation]
[PARAM:previous]
[上一步](Programming\QuickStart\3 "%Programming\QuickStart\3:title%")
[/PARAM]
[PARAM:current]
[/PARAM]
[PARAM:home]
[编程主页](Programming)
[/PARAM]
[PARAM:next]
[下一步](Programming\QuickStart\5 "%Programming\QuickStart\5:title%")
[/PARAM]
[/OBJECT]
[/VAR]
%Steps%
1. 在 **虚幻编辑器** 中,找到 **Content Browser内容浏览器** ,并展开名称为"C++类"的文件夹、 在该文件夹中,有一个包含了 **Actor** 类的 **FloatingActor** 的"QuickStart"文件夹。
[![](ClassInContentBrowser.png)](ClassInContentBrowser.png)
1. 我们可以直接把 **FloatingActor** 类拖曳到 **Level Editor关卡编辑器** 窗口来创建世界中 **FloatingActor** 的实例。 我们会在 **Level Editor关卡编辑器** 和 **World Outliner世界大纲视图** 中选择它,它在其中的名称为 "FloatingActor1"。 它的 **Components组件** 和其它属性可以在 **Details详细信息** 面板中看到。
[![](WorldOutliner.png)](WorldOutliner.png)
1. **FloatingActor** 应该在游戏中可见。 在选择了它后,我们可以在 **Details Panel详细信息面板** 中点击 **Add Component添加组件** ,然后选择 **Cone椎体** 从而赋予它简单的可视化表现。
[![](AddStaticMesh.png)](AddStaticMesh.png)
1. 现在自定义的 **Actor** 已经完成了,让我们把它移动到明显的位置。 我们可以用鼠标左键在世界中选择并拖曳内容,或者我们也可以手动来移动它。 如需手动移动,我们可以在 **Level Editor关卡编辑器** 或 **World Outliner世界大纲视图** 中选择它,然后使用 **Details Panel详细信息面板** 来选择"FloatingActor1 (实例)"。 我们现在可以直接编辑FloatingActor1的 **Transform变换** 的 **Location位置** 域了。 让我们把X设置为-200把Z设置为200。这样我们就可以在场景中的桌子上放置"FloatingActor1"了。
[![](SetActorLocation.png)](SetActorLocation.png)
1. 按下 **Play播放** 按钮,然后观看椎体的上下浮动!
[![](MovingCone.png)](MovingCone.png)
----
[OBJECT:Section]
[PARAMLITERAL:id]
代码
[/PARAMLITERAL]
[PARAM:heading]
Finished Code
[/PARAM]
[PARAM:content]
**FloatingActor.h**
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/Actor.h"
#include "FloatingActor.generated.h"
UCLASS()
class QUICKSTART_API AFloatingActor : public AActor
{
GENERATED_BODY()
public:
// 设置此actor属性的默认值
AFloatingActor();
// 当游戏开始或生成时调用
virtual void BeginPlay() override;
// 在每一帧调用
virtual void Tick( float DeltaSeconds ) override;
float RunningTime;
};
**FloatingActor.cpp**
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "QuickStart.h"
#include "FloatingActor.h"
// 设置默认值
AFloatingActor::AFloatingActor()
{
// 将此actor设置为在每一帧都调用Tick()。 如果您不需要这项功能,您可以关闭它以改善性能。
PrimaryActorTick.bCanEverTick = true;
}
// 当游戏开始或生成时调用
void AFloatingActor::BeginPlay()
{
Super::BeginPlay();
}
// 在每一帧调用
void AFloatingActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
FVector NewLocation = GetActorLocation();
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
NewLocation.Z += DeltaHeight * 20.0f; //把高度以20的系数进行缩放
RunningTime += DeltaTime;
SetActorLocation(NewLocation);
}
[/PARAM]
[/OBJECT]
%Steps%