目录
外部与一个子系统的通信必须通过一个统一的外观对象进行,为子系统中的一组结构提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
外观模式又称门面模式,它是一种对象结构型模式。
其实UE4有很多外观模式的影子,例如UKismet库,很多都是继承封装好的,用户可以轻易调用
实现一个剧情过程的案例雏形
- UCLASS() // 镜头序列轨道管理系统
- class DESIGNPATTERNS_API UCameraSubSystem : public UObject
- {
- GENERATED_BODY()
- public:
- void Play() {
- UE_LOG(LogTemp, Warning, TEXT(__FUNCTION__" Camera start moving."));
- }
-
- void Stop() {
- UE_LOG(LogTemp, Warning, TEXT(__FUNCTION__" Camera stop moving."));
- }
- };
- UCLASS() // 特效管理系统
- class DESIGNPATTERNS_API UVFXSubsystem : public UObject
- {
- GENERATED_BODY()
- public:
- void Play() {
- UE_LOG(LogTemp, Warning, TEXT(__FUNCTION__" VFX start playing."));
- }
-
- void Stop() {
- UE_LOG(LogTemp, Warning, TEXT(__FUNCTION__" VFX stop playing."));
- }
- };
- UCLASS() // 音频管理系统
- class DESIGNPATTERNS_API USFXSubsystem : public UObject
- {
- GENERATED_BODY()
- public:
- void Play() {
- UE_LOG(LogTemp, Warning, TEXT(__FUNCTION__" SFX start playing."));
- }
-
- void Stop() {
- UE_LOG(LogTemp, Warning, TEXT(__FUNCTION__" SFX stop playing."));
- }
- };
- UCLASS()
- class DESIGNPATTERNS_API UFacadeObject : public UObject
- {
- GENERATED_BODY()
- public:
- UFacadeObject(){
- CameraSubSystem = NewObject
(); - VFXSubsystem = NewObject
(); - SFXSubsystem = NewObject
(); - }
- ~UFacadeObject(){}
-
- // 开始过场剧场
- void PlayCutscene() {
- CameraSubSystem->Play();
- VFXSubsystem->Play();
- SFXSubsystem->Play();
- }
-
- // 结束过场剧场
- void StopCutscene() {
- CameraSubSystem->Stop();
- VFXSubsystem->Stop();
- SFXSubsystem->Stop();
- }
-
- private:
- UPROPERTY()
- UCameraSubSystem* CameraSubSystem;
-
- UPROPERTY()
- UVFXSubsystem* VFXSubsystem;
-
- UPROPERTY()
- USFXSubsystem* SFXSubsystem;
- };
测试
- UCLASS()
- class DESIGNPATTERNS_API AFacadeTestActor : public AActor
- {
- GENERATED_BODY()
-
- public:
- AFacadeTestActor();
- virtual void Tick(float DeltaTime) override;
-
- UPROPERTY()
- UFacadeObject* FacadeObject;
-
- protected:
- // Called when the game starts or when spawned
- virtual void BeginPlay() override {
- FacadeObject = NewObject
(); -
- // 播放过场剧情
- FacadeObject->PlayCutscene();
-
- UE_LOG(LogTemp, Warning, TEXT(" ---------------------------------------------- "));
-
- // 结束或跳过过场剧情
- FacadeObject->StopCutscene();
- }
- };
- LogTemp: Warning: UCameraSubSystem::Play Camera start moving.
- LogTemp: Warning: UVFXSubsystem::Play VFX start playing.
- LogTemp: Warning: USFXSubsystem::Play SFX start playing.
- LogTemp: Warning: ----------------------------------------------
- LogTemp: Warning: UCameraSubSystem::Stop Camera stop moving.
- LogTemp: Warning: UVFXSubsystem::Stop VFX stop playing.
- LogTemp: Warning: USFXSubsystem::Stop SFX stop playing.