summaryrefslogtreecommitdiff
path: root/GameCode/SteamManager.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/SteamManager.cs
+ init
Diffstat (limited to 'GameCode/SteamManager.cs')
-rw-r--r--GameCode/SteamManager.cs99
1 files changed, 99 insertions, 0 deletions
diff --git a/GameCode/SteamManager.cs b/GameCode/SteamManager.cs
new file mode 100644
index 0000000..9f30390
--- /dev/null
+++ b/GameCode/SteamManager.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Text;
+using Steamworks;
+using UnityEngine;
+
+[DisallowMultipleComponent]
+public class SteamManager : MonoBehaviour
+{
+ protected static bool s_EverInitialized;
+
+ protected static SteamManager s_instance;
+
+ protected bool m_bInitialized;
+
+ protected SteamAPIWarningMessageHook_t m_SteamAPIWarningMessageHook;
+
+ protected static SteamManager Instance
+ {
+ get
+ {
+ if (s_instance == null)
+ {
+ return new GameObject("SteamManager").AddComponent<SteamManager>();
+ }
+ return s_instance;
+ }
+ }
+
+ public static bool Initialized => Instance.m_bInitialized;
+
+ protected static void SteamAPIDebugTextHook(int nSeverity, StringBuilder pchDebugText)
+ {
+ }
+
+ protected virtual void Awake()
+ {
+ if (s_instance != null)
+ {
+ UnityEngine.Object.Destroy(base.gameObject);
+ return;
+ }
+ s_instance = this;
+ if (s_EverInitialized)
+ {
+ throw new Exception("Tried to Initialize the SteamAPI twice in one session!");
+ }
+ UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
+ if (!Packsize.Test())
+ {
+ Debug.LogError("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.", this);
+ }
+ if (!DllCheck.Test())
+ {
+ Debug.LogError("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.", this);
+ }
+ m_bInitialized = SteamAPI.Init();
+ if (!m_bInitialized)
+ {
+ Debug.LogError("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.", this);
+ }
+ else
+ {
+ s_EverInitialized = true;
+ }
+ }
+
+ protected virtual void OnEnable()
+ {
+ if (s_instance == null)
+ {
+ s_instance = this;
+ }
+ if (m_bInitialized && m_SteamAPIWarningMessageHook == null)
+ {
+ m_SteamAPIWarningMessageHook = SteamAPIDebugTextHook;
+ SteamClient.SetWarningMessageHook(m_SteamAPIWarningMessageHook);
+ }
+ }
+
+ protected virtual void OnDestroy()
+ {
+ if (!(s_instance != this))
+ {
+ s_instance = null;
+ if (m_bInitialized)
+ {
+ SteamAPI.Shutdown();
+ }
+ }
+ }
+
+ protected virtual void Update()
+ {
+ if (m_bInitialized)
+ {
+ SteamAPI.RunCallbacks();
+ }
+ }
+}