-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSteamManager.cs
107 lines (96 loc) · 2.44 KB
/
SteamManager.cs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Steamworks;
using System;
using System.Text;
using UnityEngine;
[DisallowMultipleComponent]
internal class SteamManager : MonoBehaviour
{
private static SteamManager s_instance;
private static bool s_EverInialized;
private bool m_bInitialized;
private SteamAPIWarningMessageHook_t m_SteamAPIWarningMessageHook;
private static SteamManager Instance => s_instance ?? new GameObject("SteamManager").AddComponent<SteamManager>();
public static bool Initialized => Instance.m_bInitialized;
private static void SteamAPIDebugTextHook(int nSeverity, StringBuilder pchDebugText)
{
Debug.LogWarning(pchDebugText);
}
private void Awake()
{
if (s_instance != null)
{
UnityEngine.Object.Destroy(base.gameObject);
}
else
{
s_instance = this;
if (s_EverInialized)
{
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);
}
try
{
if (SteamAPI.RestartAppIfNecessary(AppId_t.Invalid))
{
Application.Quit();
return;
}
}
catch (DllNotFoundException arg)
{
Debug.LogError("[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n" + arg, this);
Application.Quit();
return;
IL_00a6:;
}
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_EverInialized = true;
}
}
}
private void OnEnable()
{
if (s_instance == null)
{
s_instance = this;
}
if (m_bInitialized && m_SteamAPIWarningMessageHook == null)
{
m_SteamAPIWarningMessageHook = SteamAPIDebugTextHook;
SteamClient.SetWarningMessageHook(m_SteamAPIWarningMessageHook);
}
}
private void OnDestroy()
{
if (!(s_instance != this))
{
s_instance = null;
if (m_bInitialized)
{
SteamAPI.Shutdown();
}
}
}
private void Update()
{
if (m_bInitialized)
{
SteamAPI.RunCallbacks();
}
}
}