Files

86 lines
2.0 KiB
C#

using UnityEngine;
using UnityEngine.UI;
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX
using Steamworks;
#endif
public class steamCheck : MonoBehaviour
{
[Header("UI")]
public Text welcomeText;
private bool steamReady;
void Awake()
{
RefreshSteamState();
}
void OnEnable()
{
RefreshSteamState();
}
void RefreshSteamState()
{
#if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX)
steamReady = false;
SetFailText("Current platform has Steamworks disabled");
return;
#else
if (!SteamManager.SteamVerificationEnabled)
{
steamReady = true;
SetWelcomeText();
return;
}
steamReady = SteamManager.Initialized;
Debug.Log("Steam Init status: " + steamReady);
if (!steamReady)
{
SetFailText("Steam initialization failed");
return;
}
Debug.Log("Steam LoggedOn: " + SteamUser.BLoggedOn());
SetWelcomeText();
#endif
}
void SetWelcomeText()
{
#if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX)
SetFailText("Current platform has Steamworks disabled");
#else
if (!SteamManager.SteamVerificationEnabled)
{
if (welcomeText != null)
welcomeText.text = "Steam verification disabled";
return;
}
if (welcomeText == null)
return;
if (!steamReady)
{
SetFailText("Steam not initialized");
return;
}
string playerName = SteamFriends.GetPersonaName();
CSteamID steamID = SteamUser.GetSteamID();
welcomeText.text = $"{playerName} ({steamID.m_SteamID})";
#endif
}
void SetFailText(string msg)
{
if (welcomeText != null)
welcomeText.text = msg;
}
}