using UnityEngine; using UnityEngine.UI; #if !DISABLESTEAMWORKS using Steamworks; #endif public class steamCheck : MonoBehaviour { [Header("UI")] public Text welcomeText; private bool steamReady; void Awake() { RefreshSteamState(); } void OnEnable() { RefreshSteamState(); } void RefreshSteamState() { #if DISABLESTEAMWORKS steamReady = false; SetFailText("当前平台未启用 Steamworks"); return; #else steamReady = SteamManager.Initialized; Debug.Log("Steam Init 状态: " + steamReady); if (!steamReady) { SetFailText("Steam 初始化失败"); return; } Debug.Log("Steam LoggedOn: " + SteamUser.BLoggedOn()); SetWelcomeText(); #endif } void SetWelcomeText() { #if DISABLESTEAMWORKS SetFailText("当前平台未启用 Steamworks"); #else if (welcomeText == null) return; if (!steamReady) { SetFailText("Steam 未初始化"); 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; } }