81 lines
1.6 KiB
C#
81 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Steamworks;
|
|
|
|
public class steamCheck : MonoBehaviour
|
|
{
|
|
[Header("UI")]
|
|
public Text welcomeText;
|
|
|
|
private const uint APP_ID = 2191270;
|
|
|
|
private bool steamInitialized = false;
|
|
|
|
void Awake()
|
|
{
|
|
#if !UNITY_EDITOR
|
|
if (SteamAPI.RestartAppIfNecessary(new AppId_t(APP_ID)))
|
|
{
|
|
Application.Quit();
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
try
|
|
{
|
|
steamInitialized = SteamAPI.Init();
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError("Steam 初始化异常: " + e);
|
|
steamInitialized = false;
|
|
}
|
|
|
|
Debug.Log("Steam Init 状态: " + steamInitialized);
|
|
|
|
if (!steamInitialized)
|
|
{
|
|
SetFailText("Steam 初始化失败");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("Steam LoggedOn: " + SteamUser.BLoggedOn());
|
|
|
|
SetWelcomeText();
|
|
}
|
|
|
|
void SetWelcomeText()
|
|
{
|
|
if (welcomeText == null)
|
|
return;
|
|
|
|
if (!steamInitialized)
|
|
{
|
|
SetFailText("Steam 未初始化");
|
|
return;
|
|
}
|
|
|
|
string playerName = SteamFriends.GetPersonaName();
|
|
CSteamID steamID = SteamUser.GetSteamID();
|
|
|
|
welcomeText.text = $"欢迎特别测试专员 {playerName} ({steamID.m_SteamID})";
|
|
}
|
|
|
|
void SetFailText(string msg)
|
|
{
|
|
if (welcomeText != null)
|
|
welcomeText.text = msg;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (steamInitialized)
|
|
SteamAPI.RunCallbacks();
|
|
}
|
|
|
|
void OnApplicationQuit()
|
|
{
|
|
if (steamInitialized)
|
|
SteamAPI.Shutdown();
|
|
}
|
|
} |