请选择 进入手机版 | 继续访问电脑版

01BIM社区

 找回密码
 立即注册

扫一扫,访问微社区

查看: 5828|回复: 0

官方案例程序:Game-Controlled Cameras

[复制链接]

155

主题

643

帖子

2531

积分

金牌会员

Rank: 6Rank: 6

积分
2531
发表于 2018-3-26 12:02:48 | 显示全部楼层 |阅读模式
本帖最后由 tzbm123456 于 2018-3-26 12:04 编辑

一、CameraDirector.h
// Fill out your copyright notice in the Description page of Project Settings.


#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CameraDirector.generated.h"
UCLASS()
class HOWTO_AUTOCAMERA_API ACameraDirector : public AActor
{
        GENERATED_BODY()        
public:        
        // Sets default values for this actor's properties
        ACameraDirector();
protected:
        // Called when the game starts or when spawned
        virtual void BeginPlay() override;
public:        
        // Called every frame
        virtual void Tick(float DeltaTime) override;
        UPROPERTY(EditAnywhere)
                AActor* CameraOne;
        UPROPERTY(EditAnywhere, Category = "Parameter")
                AActor* CameraTwo;
        UPROPERTY(EditAnywhere,Category = "Parameter")
                float TimeBetweenCameraChanges;
        UPROPERTY(EditAnywhere)
                float SmoothBlendTime;
        float TimeToNextCameraChange;        
};

二、CameraDirector.cpp
// Fill out your copyright notice in the Description page of Project Settings.


#include "CameraDirector.h"
#include "HowTo_AutoCamera.h"
#include "Kismet/GameplayStatics.h"
// Sets default values
ACameraDirector::ACameraDirector()
{
         // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
        PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ACameraDirector::BeginPlay()
{
        Super::BeginPlay();
        
}
// Called every frame
void ACameraDirector::Tick(float DeltaTime)
{
        Super::Tick(DeltaTime);
        //const float TimeBetweenCameraChanges = 3.0f;
        //const float SmoothBlendTime = 1.5f;
        TimeToNextCameraChange -= DeltaTime;
        if (TimeToNextCameraChange <= 0.0f)
        {
                TimeToNextCameraChange += TimeBetweenCameraChanges;
                // Find the actor that handles control for the local player.
                APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0);
                if (OurPlayerController)
                {
                        if ((OurPlayerController->GetViewTarget() != CameraOne) && (CameraOne != nullptr))
                        {
                                // Cut instantly to camera one.
                                OurPlayerController->SetViewTarget(CameraOne);
                        }
                        else if ((OurPlayerController->GetViewTarget() != CameraTwo) && (CameraTwo != nullptr))
                        {
                                // Blend smoothly to camera two.
                                OurPlayerController->SetViewTargetWithBlend(CameraTwo, SmoothBlendTime);
                        }
                }
        }
}



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|01BIM社区 - 最专业的BIM技术交流平台 ( 渝ICP备15000873号 )

GMT+8, 2024-3-29 21:53 , Processed in 0.057925 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表