我想通过 Steamworks.net 对 Unity 游戏客户端进行身份验证,以使用 SteamUser.GetAuthTicketForWebApi 将帐户连接到我的 Node.js 服务器。但是我无法从该函数获得回调。在我的代码示例中 Debug.Log("callback") 永远不会出现。 SteamUser.GetSteamID() 或 SteamFriends.GetPersonaName() 等命令运行正常。但不是 SteamUser.GetAuthTicketForWebApi。
我尝试在新创建的项目上执行此操作。我已完成所有步骤,我应该做其他事情吗?:
using Steamworks;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Services.Authentication;
using Unity.Services.Core;
using UnityEngine;
public class SteamUtility : MonoBehaviour
{
Callback<GetTicketForWebApiResponse_t> m_AuthTicketForWebApiResponseCallback;
string m_SessionTicket;
string identity = "unityauthenticationservice";
private void Start()
{
SignInWithSteam();
}
void SignInWithSteam()
{
// It's not necessary to add event handlers if they are
// already hooked up.
// Callback.Create return value must be assigned to a
// member variable to prevent the GC from cleaning it up.
// Create the callback to receive events when the session ticket
// is ready to use in the web API.
// See GetAuthSessionTicket document for details.
m_AuthTicketForWebApiResponseCallback = Callback<GetTicketForWebApiResponse_t>.Create(OnAuthCallback);
SteamUser.GetAuthTicketForWebApi(identity);
Debug.Log("login");
}
void OnAuthCallback(GetTicketForWebApiResponse_t callback)
{
Debug.Log("callback");
m_SessionTicket = BitConverter.ToString(callback.m_rgubTicket).Replace("-", string.Empty);
m_AuthTicketForWebApiResponseCallback.Dispose();
m_AuthTicketForWebApiResponseCallback = null;
Debug.Log("Steam Login success. Session Ticket: " + m_SessionTicket);
// Call Unity Authentication SDK to sign in or link with Steam, displayed in the following examples, using the same identity string and the m_SessionTicket.
}
}
您需要定期给
SteamAPI.RunCallbacks();
打电话。尝试将其放入更新统一消息中,然后重试。