From bd39c27c1d53b12ba056d7d4531307e19a75934d Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Fri, 31 Jul 2026 18:22:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=89=93=E5=BC=80Ste?= =?UTF-8?q?am=E5=95=86=E5=BA=97=E9=A1=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/AssetRefs/ConstRef.cs | 1 + Assets/Scripts/Utility/SteamStoreUtility.cs | 75 +++++++++++++++++++ .../Scripts/Utility/SteamStoreUtility.cs.meta | 11 +++ 3 files changed, 87 insertions(+) create mode 100644 Assets/Scripts/Utility/SteamStoreUtility.cs create mode 100644 Assets/Scripts/Utility/SteamStoreUtility.cs.meta diff --git a/Assets/Scripts/AssetRefs/ConstRef.cs b/Assets/Scripts/AssetRefs/ConstRef.cs index 1031b6bd9..3ce27da86 100644 --- a/Assets/Scripts/AssetRefs/ConstRef.cs +++ b/Assets/Scripts/AssetRefs/ConstRef.cs @@ -18,6 +18,7 @@ namespace AibisDream.Utility public const string SurveyURL_JP = "https://jsj.top/f/icnVug"; public const string WishlistURL = "https://store.steampowered.com/app/3473430/_All_Our_Broken_Parts?utm_source=playtest"; + public const string SteamWishlistURL = "steam://store/3473430"; public static readonly string SaveFilePath = Path.Combine(Application.persistentDataPath, "demo_saves"); #if UNITY_EDITOR || DEVELOPMENT_BUILD diff --git a/Assets/Scripts/Utility/SteamStoreUtility.cs b/Assets/Scripts/Utility/SteamStoreUtility.cs new file mode 100644 index 000000000..25265b3af --- /dev/null +++ b/Assets/Scripts/Utility/SteamStoreUtility.cs @@ -0,0 +1,75 @@ +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN +using System.Runtime.InteropServices; +using System.Text; +#endif +using UnityEngine; + +namespace AibisDream.Utility +{ + /// + /// 打开游戏的 Steam 商店页面。 + /// + public static class SteamStoreUtility + { +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + private const uint AssocStrCommand = 1; + private const int S_OK = 0; + + [DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)] + private static extern int AssocQueryString( + uint flags, + uint str, + string association, + string extra, + StringBuilder output, + ref uint outputLength); +#endif + + /// + /// Windows 下优先使用 Steam 客户端;Steam 协议不可用时回退到网页商店。 + /// + public static void OpenWishlistPage() + { +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + if (IsSteamProtocolRegistered()) + { + Application.OpenURL(ConstRef.SteamWishlistURL); + return; + } +#endif + + Application.OpenURL(ConstRef.WishlistURL); + } + +#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + private static bool IsSteamProtocolRegistered() + { + try + { + uint commandLength = 0; + AssocQueryString(0, AssocStrCommand, "steam", null, null, ref commandLength); + if (commandLength == 0) + { + return false; + } + + var command = new StringBuilder((int)commandLength); + var result = AssocQueryString( + 0, + AssocStrCommand, + "steam", + null, + command, + ref commandLength); + return result == S_OK && command.Length > 0; + } + catch (System.Exception exception) + { + Debug.LogWarning( + $"[SteamStoreUtility] 无法检测 Steam URL Protocol,将回退到网页商店:{exception.Message}"); + return false; + } + } +#endif + } +} diff --git a/Assets/Scripts/Utility/SteamStoreUtility.cs.meta b/Assets/Scripts/Utility/SteamStoreUtility.cs.meta new file mode 100644 index 000000000..7dd0186e5 --- /dev/null +++ b/Assets/Scripts/Utility/SteamStoreUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5d54f85d89d04849a54cde529cb66d55 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: