76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
#endif
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.Utility
|
|
{
|
|
/// <summary>
|
|
/// 打开游戏的 Steam 商店页面。
|
|
/// </summary>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Windows 下优先使用 Steam 客户端;Steam 协议不可用时回退到网页商店。
|
|
/// </summary>
|
|
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
|
|
}
|
|
}
|