# 伪单例
在UE4中GameInstance实现伪单例,用来控制总体的东西
//===================头文件======================
class DINGMU_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
virtual void Init();
public:
static UMyGameInstance* GameInstanceReference;
};
//===================源文件======================
UMyGameInstance* UMyGameInstance::GameInstanceReference=NULL;
void UMyGameInstance::Init()
{
GameInstanceReference = Cast<UMyGameInstance>(GetWorld()->GetGameInstance());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15