C++ Programming Tutorials_3翻譯



所在原文目錄結構位置:

C++ Programming Guide

 |_____Programming Quick Start Guide

 |_____Introduction to C++ Programming in UE4

 |_____C++ Programming Tutorials

 |_____Managing Game Code

 |_____Development Setup

 |_____Gameplay Programming

 |_____Engine Architecture

 |_____Console Manager: Console Variables in C++

 |_____Command-Line Arguments

 |_____Assertions

 |_____Blueprint Function Libraries

 |_____Unreal Build System

 |_____Plugins

 |_____Coding Standard

 |_____Symbol Debugger


原文地址:Variables,Times,and Events


-------------------------------------------------------------------------------------------------------------------------------------------------------


C++ Programming Tutorials

C++編程教程

1.Player Input and Pawns 玩家輸入和Pawn(個人感覺Pawn是副角色,配角) 

 見譯文:  C++ Programming Tutorials_1 


2.Game-Controlled Cameras 遊戲控制攝像機

見譯文:C++ Programming Tutorials 2


3.Variables, Timers, and Events 變量,定時器和事件

This tutorial will show you how to expose variables and functions to the editor, use timers to delay or repeat code execution, and use events to communicate between Actors.

本教程要講怎樣將(C++中)變量,函數暴露給UE編輯器,使用計時器來延遲或重複代碼的執行,和用事件來使Actorr交互.

Steps 步驟:

   1.Creating an Actor that uses a timer  創建一個ACtor,使用一個計數器

         !!!If you are new to Unreal Engine 4, you might want to read ourProgramming Quick Start tutorial first. For this tutorial, we will assume you are familiar with creating a project and adding C++ code to it.

         !!!如果你是新手,請先閱讀前面的譯文.

         ① We will begin by creating a new, Basic Code project, with starter content, named "HowTo_VTE", and then adding an Actor class to it. We'll name it "Countdown" in this tutorial.     

          我們從創建一個新的,C++,基礎代碼開始,使用初學者內容,項目命名爲"HowTo_VTE", ,然後本教程爲項目增加一個Actor類,名爲該類爲"Countdown"



         ② We'll start by creating a simple countdown timer that we can see in-game. InCountdown.h, add the following lines to the end of our class definition:

          我們創建一個簡單的countdown計時器,能在遊戲中被看見.在Countdown.h頭文件中,在該類定義的尾部增加如下代碼:`

int32 CountdownTime;

UTextRenderComponent* CountdownText;

void UpdateTimerDisplay();

         ③ InCountdown.cpp, we can create our renderable text Component and initialize our countdown time to 3 seconds. We can also turn Ticking off for this type of Actor, since we will not need it. ACountdown::ACountdown should look like this:

         在Countdown.cpp文件中,我們創建我們的可渲染的文本組件,初始化我們的countdown計時器爲3秒.在我們不再需要的時候我們也可以關閉Actor這種類型的Ticking. ACountdown::ACountdown應該是這樣的:


PrimaryActorTick.bCanEverTick = false;

CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("CountdownNumber"));
CountdownText->SetHorizontalAlignment(EHTA_Center);
CountdownText->SetWorldSize(150.0f);
RootComponent = CountdownText;

CountdownTime = 3;

         ④ ACountdown::UpdateTimerDisplay should update our text display to show the time remaining, or zero if the time is up. This code should run when we first spawn our ACountdown into the game, and once per second until our CountdownTime variable hits zero.

         ACountdown::UpdateTimerDisplay 更新我們的文本顯示,顯示剩餘時間,時間到了爲0,這段代碼應當在遊戲中我們一運行我們的ACountdown 就要被觸發,每秒一次,直到時間爲0爲止.

void ACountdown::UpdateTimerDisplay()
{
    CountdownText->SetText(FString::FromInt(FMath::Max(CountdownTime, 0)));
}

  無論何時我們指定一個計時器去控制一個函數的運行,我們有一個計時器的句柄.我們需要抓住這個句柄以便我們可以在計時結束時關閉計時器,我們新增加一個函數來表示時間到了,計時器句柄將要控制它,在Countdown.h類定義的末尾,當時間計時結束時做一些指定的事.</span></span>

    

void AdvanceTimer();

void CountdownHasFinished();

FTimerHandle CountdownTimerHandle;
</pre></h3><h3 align="left"><span style="color:#3333ff;background-color: rgb(255, 255, 255);"><span style="color:#000000;">       We can also write the body of ACountdown::AdvanceTimer and ACountdown::CountdownHasFinished in<code>Countdown.cpp</code> now:</span></span></h3><h3 align="left"><span style="color:#3333ff;background-color: rgb(255, 255, 255);"><span style="color:#000000;">我們在<span style="font-family:Courier New;">Countdown.cpp</span> 的ACountdown::AdvanceTimer 和ACountdown::CountdownHasFinished中寫:</span></span></h3><h3 align="left"><span style="color:#3333ff;background-color: rgb(255, 255, 255);"><span style="color:#000000;"></span></span><pre class="cpp" name="code">void ACountdown::AdvanceTimer()
{
    --CountdownTime;
    UpdateTimerDisplay();
    if (CountdownTime < 1)
    {
        //We're done counting down, so stop running the timer.
        GetWorldTimerManager().ClearTimer(CountdownTimerHandle);
        CountdownHasFinished();
    }
}

void ACountdown::CountdownHasFinished()
{
    //Change to a special readout
    CountdownText->SetText(TEXT("GO!"));
}

         ⑥Let's initialize the text display in ACountdown::BeginPlay by adding a call to our new update function, and setting a timer to advance and update the countdown once per second:

          讓我們在ACountdown::BeginPlay 中初始化文本顯示,爲我們新的更新函數增加一個回調,每秒一次更新我們的計時器

UpdateTimerDisplay();
GetWorldTimerManager().SetTimer(CountdownTimerHandle, this, &ACountdown::AdvanceTimer, 1.0f, true);


         !!!We are updating the display in ACountdown::BeginPlay rather than ACountdown::ACountdown because values set to variables in the Unreal Editor will be assigned after the constructor, but before BeginPlay. We will want to respect those values later, when we expose CountdownTime to the editor.

         !!!我們在ACountdown::BeginPlay 中更新展示而不是在ACountdown::ACountdown 構造函數中,因爲設置的變量在虛幻編輯器中將在構造函數之後被分配,但是在BeginPlay之前.當我們要暴露CountdownTime到編輯器的時候,以後我們要注重這些值.

         ⑦Let's check our progress so far by going to the Unreal Editor and pressing Compile

          回到UE編輯器中按下Play來檢查到目前爲止我們的進程.

          We can then drop our updated ACountdown class from the Content Browser into the Level Editor.

           我們可以在Level Editor(關卡編輯器)的Content Browser (內容瀏覽器)減少ACountdown的更新.

          !!!Because we set our countdown text during ACountdown::BeginPlay and not ACountdown::ACountdown, the default "Text" is shown in the Level Editor.

          !!!由於我們在ACountdown::BeginPlay中設置我們的countdown 文本而不是在ACountdown::ACountdown ,在關卡編輯器中顯示默認的默認的"Text"

    When we press Play, the countdown will progress as expected, saying "3", "2", "1", and finally "GO!"

    當我們按下Play按鈕,計時器將如期運行,"3", "2", "1",最後:"GO!".

At this point, we've already created a simple class that uses a timer. Non-programming users would get much more out of it if they could set the countdown time, or change the behavior when the countdown finishes. Next, we'll expose these features to the editor.

這兒,我們已經創建好了一個簡單的類,使用了計時器.非編程的用戶如果他們能設置倒計時,或者倒計時結束時改變他們的行爲的話他們將獲得更多,下面,我們要暴露屬性給編輯器.



完成代碼:

Countdown.h


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "GameFramework/Actor.h"
#include "Countdown.generated.h"

UCLASS()
class HOWTO_VTE_API ACountdown : public AActor
{
    GENERATED_BODY()

public: 
    // 構造函數
    ACountdown();

    // 遊戲開始時調用
    virtual void BeginPlay() override;

    // 每幀調用(本項目屏蔽了該函數,改成每秒更新)
    virtual void Tick( float DeltaSeconds ) override;

    //倒計時(這裏默認爲3秒)
    int32 CountdownTime;
    UTextRenderComponent* CountdownText;//文本

    void UpdateTimerDisplay();//更新時間和文本的顯示

    void AdvanceTimer();//計時器的委託函數

    void CountdownHasFinished();//計時器時間到後的行爲

    FTimerHandle CountdownTimerHandle;//計時器句柄
};


Countdown.cpp

<strong>// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#include "HowTo_VTE.h"
#include "Countdown.h"

// Sets default values
ACountdown::ACountdown()
{
    // 本項目不需要Tick這個函數,屏蔽之
    PrimaryActorTick.bCanEverTick = false;

    CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("CountdownNumber"));
    CountdownText->SetHorizontalAlignment(EHTA_Center);
    CountdownText->SetWorldSize(150.0f);
    RootComponent = CountdownText;

    CountdownTime = 3;
}

// 遊戲開始時調用一次
void ACountdown::BeginPlay()
{
    Super::BeginPlay();

    UpdateTimerDisplay();
    GetWorldTimerManager().SetTimer(CountdownTimerHandle, this, &ACountdown::AdvanceTimer, 1.0f, true);
}

// 每幀調用(此項目屏蔽)
void ACountdown::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );

}

void ACountdown::UpdateTimerDisplay()
{
    CountdownText->SetText(FString::FromInt(FMath::Max(CountdownTime, 0)));
}

void ACountdown::AdvanceTimer()
{
    --CountdownTime;
    UpdateTimerDisplay();
    if (CountdownTime < 1)
    {
        // We're done counting down, so stop running the timer.
        GetWorldTimerManager().ClearTimer(CountdownTimerHandle);
        //Perform any special actions we want to do when the timer ends.
        CountdownHasFinished();
    }
}

void ACountdown::CountdownHasFinished()
{
    //Change to a special readout
    CountdownText->SetText(TEXT("GO!"));
}</strong>

總結:心中一直縈繞着這麼一個問題,例子中,把Tick這個每幀更新這個函數給屏蔽掉了,爲啥還能3,2,1,地跑呢?

而且BeginPlay也就調用了一次.

解:它是通過委託來調用的,GetWorldTimerManager().SetTimer(CountdownTimerHandle,this,&ACountdown::AdvanceTimer,1.0f,true);它把AdvanceTimer這個委託函數地址保存下來,後面的參數1.0表示調用頻率,這裏爲1.0秒調用一次AdvanceTimer.(一孔之見,我改成0.5,結論跟我想的絲毫不差)

(注意:改0.5要注意數據類型,int32改成 float,FromInt變成SanitizeFloat),UE4基本類型轉換參考這兒:UE4基礎數據類型轉換

    2.Expose variables and functions to the editor 暴露變量,函數給編輯器

           ①Our countdown timer is currently hard-coded to use a value of 3 seconds. It would be more useful if we could set the countdown time to any value we want in the editor, and this is easy to do. In Visual Studio, we can openCountdown.h and find the line that says:

           我們的countdown 計時器目前使用硬編碼的值3秒,如果我們把它設置爲編輯器中可編輯的任意值豈不是更好嗎?修改還更簡單了.在VS中,我們打開Countdown.h,找到這個成員變量:

int32 CountdownTime;

     In order to expose this variable to Unreal Engine, we need to make it a UPROPERTY. This enables the engine to preserve the value of the variable when launching the game or loading a saved level. The UPROPERTY tag, with empty parentheses, is added right above the variable it affects:

     爲了暴露這個變量到虛幻引擎,我們需要使之成爲一個UPROPERTY宏,當引擎啓動或者加載一個關卡的時候,允許引擎能維護變量的值,

UPROPERTY標記,用一對圓括號括起來,放在變量的正上方,如下:

UPROPERTY()
int32 CountdownTime;

    UPROPERTY supports arguments that change how Unreal Engine will use the variable. Since we want our variable to be editable, we can add the EditAnywhere argument

    UPROPERTY 支持一些參數,這取決於引擎要怎樣使用這些變量,這裏,我們希望引擎能修改變量的值,所以,我們修改參數爲EditAnywhere(哪裏都可以修改) ,這樣引擎就可以修改這個變量的值了.

UPROPERTY(EditAnywhere)
int32 CountdownTime;

重新編譯,可以看到如下:

 

We can also add a comment to our variable in C++, and our comment will become the description of the variable in the Unreal Editor, like this:

爲我們的變量添加註釋,這樣,在虛幻編輯器中可以看到這個變量的作用了,如下:

     !!!There is a lot more we can do with UPROPERTY, and looking into other arguments such as BlueprintReadWrite and Category might be good next steps, but we have all that we need at the moment.

     !!!我們可以用UPROPERTY宏做更多的事情,和調查其他參數,比如BlueprintReadWrite(藍圖讀寫)和Category 可能是很好的下一步,但是待會兒我們都需要。


When we return to the Unreal Editor and press Compile, our variable will appear in the Details Panel for the ACountdown we placed earlier, and we can test out different timer values by changing this number and pressing Play.

當我們返回編輯器編譯,我們的變量就顯示在Details面板上,修改不同的時間,按Play運行測試下效果吧


           ②In addition to changing the value of the timer, let's also enable non-programming developers to change what happens when the timer is up. In Visual Studio, we'll open Countdown.h and find the following line:

           除了改變timer的值,讓我們也使非編程開發人員改變定時器的時候會發生什麼情況.在VS中,打開Countdown.h找到以下行:

void CountdownHasFinished();

We can expose this function to the Unreal Engine by making it a UFUNCTION, like this:

我們能通過UFUNCTION宏來暴露這個函數給虛幻引擎,像這樣:

UFUNCTION()
void CountdownHasFinished();


          

Just like the UPROPERTY macro, we need to provide information about what can be done with it in order to enable more features and access for non-programming developers. There are three options to consider:

就像UPROPERTY宏一樣,我們需要提能做什麼的信息以便更多未來的需求和給非編程開發人員使用,有三個選項需要考慮:

           (①)BlueprintCallable functions are written in C++ and can be called from the Blueprint Graph, but cannot be changed or overridden without editing C++ code. Functions marked this way are usually features that have been programmed for non-programmer use, but that are not supposed to be changed or wouldn't make sense to change. An easy example of this would be any kind of math function.

           BlueprintCallable 函數使用C++寫的,能從Blueprint Graph被調用,但是不能被修改或者覆蓋,除非修改C++代碼.函數用這種方法標記,通常表明設定給非編程人員使用.但它不允許修改,或者沒有改變的意義.一個簡單的例子就是一些數學函數.

           (②)BlueprintImplementableEvent functions are set up in a C++ header (.h) file, but the body of the function is written entirely in the Blueprint Graph, not in C++. These are usually created to give a non-programmer the ability to create custom reactions to special situations that have no expected default action or standard behavior. An example of this might be an event that happens when a powerup touches the player's ship in a spaceship game.

            BlueprintImplementableEvent 函數是設置在C++的頭文件(.h)中,但是函數的實現部分是寫在Blueprint Graph,bushi zai C++.這些函數通常被建用來給非編程人員建立自定義指定行爲,因爲那些行爲是無法預料的,或者不是規範的.一個例子就是在太空船遊戲中,一個通電玩家飛船將會發生什麼事件.

           (③)BlueprintNativeEvent functions are like a combination of BlueprintCallable and BlueprintImplementableEvent functions. They have default behaviors programmed in C++, but these can be supplemented or replaced by overriding in the Blueprint Graph. When programming these, the C++ code always goes in a virtual function with "_Implementation" added to the end of the name, as shown below. This is the most flexible option, so we will use it for this tutorial.

            BlueprintNativeEvent 函數就像是BlueprintCallable 和 BlueprintImplementableEvent 的組合.他們在C++裏有默認的行爲,但是這些能在Blueprint Graph被擴充或者通過覆蓋替換掉,當編程時,C++代碼經常在虛函數名最後加上"_Implementation",如下所示.這是最靈活的選擇,因此,本教程我們使用它.(這就是我以前看到函數名不一樣時候的疑惑)

To grant non-programmers the ability to call our C++ function and to override it with Blueprints, we need to make the following changes toCountdown.h:

授予非程序員調用我們的c++函數的能力和用Blueprints覆蓋函數的能力,我們要對Countdown.h作如下改變:

UFUNCTION(BlueprintNativeEvent)
void CountdownHasFinished();
virtual void CountdownHasFinished_Implementation();

Then, in Countdown.cpp, we will need to change the line that says:

然後,在Countdown.cpp文件中,我們需要作如下改變:

void ACountdown::CountdownHasFinished()
!!!

To:轉變爲:

void ACountdown::CountdownHasFinished_Implementation()

We have now made a variable and a function accessible to, and alterable by, non-programmers, while providing our own default value and functionality in C++. To see how a non-programmer might use this, we'll make a Blueprint extension of our ACountdown class and modify it ourselves.

我們已經做了一個變量和一個函數,可訪問,可修改,非程序化,同時在C++中提供默認的值.非程序員可以使用這個,我們將爲我們的ACountdown 類做一個可擴展可修改的Blueprint.

完成代碼:

Countdown.h

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "GameFramework/Actor.h"
#include "Countdown.generated.h"

UCLASS()
class HOWTO_VTE_API ACountdown : public AActor
{
    GENERATED_BODY()

public: 
    // Sets default values for this actor's properties
    ACountdown();

    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

    // Called every frame
    virtual void Tick( float DeltaSeconds ) override;

    //How long, in seconds, the countdown will run
    UPROPERTY(EditAnywhere)
    int32 CountdownTime;

    UTextRenderComponent* CountdownText;

    void UpdateTimerDisplay();

    void AdvanceTimer();

    UFUNCTION(BlueprintNativeEvent)
    void CountdownHasFinished();
    virtual void CountdownHasFinished_Implementation();

    FTimerHandle CountdownTimerHandle;
};

Countdown.cpp

<strong>// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#include "HowTo_VTE.h"
#include "Countdown.h"

// Sets default values
ACountdown::ACountdown()
{
    // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = false;

    CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("CountdownNumber"));
    CountdownText->SetHorizontalAlignment(EHTA_Center);
    CountdownText->SetWorldSize(150.0f);
    RootComponent = CountdownText;

    CountdownTime = 3;
}

// Called when the game starts or when spawned
void ACountdown::BeginPlay()
{
    Super::BeginPlay();

    UpdateTimerDisplay();
    GetWorldTimerManager().SetTimer(CountdownTimerHandle, this, &ACountdown::AdvanceTimer, 1.0f, true);
}

// Called every frame
void ACountdown::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );

}

void ACountdown::UpdateTimerDisplay()
{
    CountdownText->SetText(FString::FromInt(FMath::Max(CountdownTime, 0)));
}

void ACountdown::AdvanceTimer()
{
    --CountdownTime;
    UpdateTimerDisplay();
    if (CountdownTime < 1)
    {
        // We're done counting down, so stop running the timer.
        GetWorldTimerManager().ClearTimer(CountdownTimerHandle);
        //Perform any special actions we want to do when the timer ends.
        CountdownHasFinished();
    }
}

void ACountdown::CountdownHasFinished_Implementation()
{
    //Change to a special readout
    CountdownText->SetText(TEXT("GO!"));
}</strong>

   3.  Extend and override C++ withBlueprints   藍圖擴展和覆蓋c++

           !!!This section of the tutorial involves using Blueprints to extend the functionality of C++ classes. However, it is only intended as a test that our C++ code was written correctly, not as a Blueprint tutorial. For a proper introduction to Blueprints, we recommend theBlueprints Quick Start Guide

           !!!這段教程涉及到使用藍圖來擴展C++類的函數功能,然而,它只是作爲C++代碼寫的正確的一個測試,這不是藍圖教程,適當介紹藍圖,見藍圖教程.

            ①To change the behavior of our ACountdown instance, called "Countdown1", in the editor, we must first make an editable Blueprint version of it. To do this, we can select it from the World Outliner and click the Blueprint/Add Script button in the Details Panel.

             要改變我們的ACountdown實例的行爲,叫做"Countdown1",在編輯器,我們必須先做一個可編輯版本的藍圖,爲此,我們可以選World Outliner 中的Countdown1,然後 點擊Details面板中Blueprint/Add Script 按鈕.

From there, we can provide a path and name for the Blueprint asset that will contain our modified ACountdown class.

從這兒,我們爲能Blueprint 提供一個路徑和名字,包含我們修改的ACountdown類.

This will create a new asset that represents a Blueprint version of "Countdown1". It will also replace "Countdown1" with an instance of this new Blueprint, so that changes we make to the Blueprint will affect "Countdown1" in the game.

這將創建一個代表"Countdown1"版本的Blueprint 的新的資源.它還將取代“Countdown1”這個新藍圖的一個實例,改變我們的藍圖將會影響“Countdown1”遊戲


            ②The Unreal Editor will automatically take us to our new asset in the Content Browser, and we can right-click it and choose "Edit..." to modify its Blueprint Graph, Component hierararchy, and Default Values.

            虛幻編輯器自動的帶我們到Content Browser新資源.右擊->編輯 來修改它的Blueprint Graph(),Component 層級和Default Values.


            ③Functions and events can be found in the Event Graph tab, so we'll select that first.

            函數和事件可以在Event Graph(事件圖表)中被找到,所以我們選擇這個標籤.

Then, by righting-click anywhere in the Event Graph window, we can add our CountdownHasFinished function as an event node to define its behavior.

然後,在Event Graph窗口中右擊,我們能把CountdownHasFinished 這個函數作爲定義它它行爲事件的節點.

            ④We can now add any additional functionality we would like by left-clicking and dragging off of the white ("execution") pin on the right side of our new node.

            我們現在能增加額外的功能,左擊然後拖出一條白色的線.

When we release the left mouse button, we will be asked what function or event we would like to execute. For this tutorial, let's spawn aParticle System when the countdown finishes. We'll want a Spawn Emitter At Location node, so select that from the list. It can save time to type a partial phrase, like "spawn loc", into the search field. We can then left-click and drag the yellow "Location" pin and attach it to aGet Actor Location function.

當我們鬆開左鍵,我們將被問想要執行什麼功能或事件,在本教程中,當倒計時結束我們將產生一個粒子系統.我們需要一個Spawn Emitter At Location 節點(注意:不是Spawn Effect at Location,寡人深受其害,半天沒找到粒子),所以,從列表中選擇,在搜索地方輸入一部分短語,像"spawn loc",拖拽黃色的 "Location"附加到Get Actor Location 函數



            Now we just need to select what effect we'd like to see. By clicking "Select Asset" under "Emitter Template", we can get a list of appropriate effect assets. "P_Explosion" is a good one, so we'll pick that.

             選一個粒子效果,爆炸挺不錯的.點擊"Select Asset",模版裏選"P_Explosion"

           ⑤If we press Play now, we'll see our countdown take place, and our explosion will happen when our countdown number hits zero.

               點擊Play,到0的時候,爆炸.

However, we programmed our countdown to say "GO!" at the end, not "0". This is no longer happening because we have completely replaced our C++ functionality with our Blueprint visual scripting. This is not what we intended to do in this case, so we need to add a call to the C++ version of this function, which can be done by right-clicking the Countdown Has Finished node and selecting "Add call to parent function" from the context menu.

但是,我們規劃了說GO之後爆炸,而不是0,GO永遠不會發生了,因爲我們藍圖已經完全取代了C++函數功能,這不是我們想要的,所以,我們需要添加一個C++版本的功能函數,

右擊Countdown Has Finished 節點,點擊 "Add call to parent function".


When this is done, a node labeledParent: Countdown Has Finished will be placed in theEvent Graph. The typical place to connect a "parent" node is directly to the event node, which is what we will do here. This is not required, though, as the parent-call node is like any other and can be called anywhere we like, even multiple times.

做完這些,一個節點的標籤Parent: Countdown Has Finished 將出現在圖表窗口中,像這樣:

Now when we run our game, we should see both the word "GO!" (from our C++ code) and an explosion (from our Blueprint Graph) after the countdown finishes!

現在啓動我們的遊戲,我們在計時器爲0的時候就能看到"GO"(C++代碼)和爆炸的粒子效果(藍圖事件)了.

代碼和上面的一樣:略.

   4.On Your Own! 自己做!

Next Step

Using what you have learned, try to do the following:

學以致用:

  • Create an Actor that moves or rotates to a target transform when anEvent is run. This could be used as a moving platform or door in a game. Make theEvent start aTimer that will trigger a second Event which moves theActor back to its original location. Use exposed variables (viaUPROPERTY) instead of hard-coded values wherever appropriate.

  • 創建一個Actor,當事件促發時,移動或者旋轉到目標值.這能被用來做遊戲裏的一個移動平臺或者門.用事件啓動一個計時器,使得計時器觸發第二個事件(讓Actor回到原來最初的位置),無論在哪裏都用暴露變量(用UPROPERTY)的方式,而不是硬編碼方式.

  • Make a lit torch that burns out (perhaps by deactivating a fiery Particle System Component) by using aTimer handle and a few customEvents. For example, anAddFuel Event could extend the burning time of the torch. ADouseWithWaterEvent could shut it off immediately and preventAddFuel from working in the future. Both of these features can be written without using aTick, simply by modifying a runningTimer through its handle.

  • 通過使用一個定時器和一些自定義的事件讓火炬點燃燃燒(也許通過關閉的粒子系統的組件),舉個例子,AddFuel事件可以延長燃燒的火炬,DouseWithWater事件會立即把它關掉,和在未來,防止AddFuel工作.這兩種功能可以都不使用Tick,只要簡單的修改一個運行的計時器句柄即可.

As for the specifics covered in this tutorial:

  • For more information about Timers, try the Gameplay Timers page.

  • For a complete reference using the UPROPERTY tag with variables in your classes or structs, look at theProperties page.

  • To learn more about UFUNCTIONS and Event creation, check theFunctions page.

  • For further tutorials, see the C++ Programming Tutorials page.


 ------------------------------------------------題目容我好好研究---------------------------------------------------------



4.Player-Controlled Cameras 玩家控制攝像機

5.Components And Collision 組件和碰撞


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章