我是靠谱客的博主 火星上小甜瓜,这篇文章主要介绍UE4_子系统(SubSystem)应用案例,现在分享给大家,希望可以做个参考。

参考来源见《InsideUE4》GamePlay架构(十一)Subsystems
案例来源油管官方视频

为什么要用子系统这个模块,往往在开发中我们要维护某一个类型(类别)的集群的一个生成,添加,业务处理,销毁等逻辑,一般情况下会写一个Manager的东西。 官方推出这个子系统这个概念,个人理解是方便开发者去更好地、方便地实现上述陈述的东西。

在开发中经常使用的官方插件VaRest(用来处理http)就是把它设计成了一个子系统的样子。

以下代码摘自油管的官方视频,记录下来,以便日后学习使用。

.h

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Subsystems/GameInstanceSubsystem.h" #include "ScoreSubsystem.generated.h" /** * */ UCLASS() class MULTITASKTEST_API UScoreSubsystem : public UGameInstanceSubsystem { GENERATED_BODY() public: // begin USubsystem void Initialize(FSubsystemCollectionBase& Collection) override; // end USubsystem void Deinitialize() override; UFUNCTION(BlueprintCallable, Category="ScoreSystem") void IncrementMultiplier(int32 Amout=1); UFUNCTION(BlueprintCallable,Category="ScoreSystem") int32 GetMultiplier(); UFUNCTION(BlueprintCallable,Category="ScoreSystem") void AddScore(int32 BaseScore); UFUNCTION(BlueprintCallable, Category = "ScoreSystem") int32 GetTotalScore(int32 BaseScore); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FScoreAdded, int32, UnmultipleAddScore); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FScoreChanged, int32, TotalNewScore); UPROPERTY(BlueprintAssignable,Category="ScoreSubsystem") FScoreAdded OnScoreAdd; UPROPERTY(BlueprintAssignable,Category="ScoreSubsystem") FScoreChanged OnScoreChanged; private: int32 CurrentMultiplier; int32 CurentScore; };

.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Fill out your copyright notice in the Description page of Project Settings. #include "Core/ScoreSubsystem.h" void UScoreSubsystem::Initialize(FSubsystemCollectionBase& Collection) { CurrentMultiplier = 1; CurentScore = 0; } void UScoreSubsystem::Deinitialize() { OnScoreAdd.Clear(); OnScoreChanged.Clear(); } void UScoreSubsystem::IncrementMultiplier(int32 Amout/*=1*/) { CurrentMultiplier = FMath::Max(CurrentMultiplier + Amout, 1); } int32 UScoreSubsystem::GetMultiplier() { return CurrentMultiplier; } void UScoreSubsystem::AddScore(int32 BaseScore) { CurentScore = FMath::Max(CurentScore + (CurrentMultiplier * BaseScore), 0); OnScoreAdd.Broadcast(BaseScore); OnScoreChanged.Broadcast(CurentScore); } int32 UScoreSubsystem::GetTotalScore(int32 BaseScore) { return CurentScore; }

最后

以上就是火星上小甜瓜最近收集整理的关于UE4_子系统(SubSystem)应用案例的全部内容,更多相关UE4_子系统(SubSystem)应用案例内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部