ChatPlexSDK-BS 1.0.1-v6.2.0
C++ ChatPlex BeatSaber SDK
Loading...
Searching...
No Matches
PersistantSingleton.hpp
1#pragma once
2
3#include <UnityEngine/GameObject.hpp>
4
5#define CP_SDK_UNITY_PERSISTANT_SINGLETON_NO_DESTROY_DECL(t_Type) \
6 protected: \
7 static t_Type* m_Instance; \
8 static void WasDestroyed(); \
9 public: \
10 static t_Type* Instance(); \
11 static void TouchInstance();
12
13#define CP_SDK_UNITY_PERSISTANT_SINGLETON_DECL(t_Type) \
14 CP_SDK_UNITY_PERSISTANT_SINGLETON_NO_DESTROY_DECL(t_Type) \
15 public: \
16 static void Destroy();
17
20
21#define CP_SDK_UNITY_PERSISTANT_SINGLETON_NO_DESTROY_IMPL(t_Type) \
22 t_Type* t_Type::m_Instance = nullptr; \
23 void t_Type::WasDestroyed() \
24 { \
25 m_Instance = nullptr; \
26 } \
27 t_Type* t_Type::Instance() \
28 { \
29 if (!CP_SDK::Utils::IsUnityPtrValid(m_Instance)) \
30 { \
31 m_Instance = GameObject::New_ctor()->AddComponent<t_Type*>(); \
32 m_Instance->get_gameObject()->set_name(u"[" #t_Type u"]"); \
33 GameObject::DontDestroyOnLoad(m_Instance->get_gameObject()); \
34 } \
35 \
36 return m_Instance; \
37 } \
38 void t_Type::TouchInstance() \
39 { \
40 Instance(); \
41 }
42
43#define CP_SDK_UNITY_PERSISTANT_SINGLETON_IMPL(t_Type) \
44 CP_SDK_UNITY_PERSISTANT_SINGLETON_NO_DESTROY_IMPL(t_Type) \
45 void t_Type::Destroy() \
46 { \
47 if (!CP_SDK::Utils::IsUnityPtrValid(m_Instance)) \
48 return; \
49 \
50 GameObject::Destroy(m_Instance->get_gameObject()); \
51 m_Instance = nullptr; \
52 }
53