开始在 Steamworks.net (Unity) 中使用 GetAuthTicketForWebApi

问题描述 投票:0回答:1

我想通过 Steamworks.net 对 Unity 游戏客户端进行身份验证,以使用 SteamUser.GetAuthTicketForWebApi 将帐户连接到我的 Node.js 服务器。但是我无法从该函数获得回调。在我的代码示例中 Debug.Log("callback") 永远不会出现。 SteamUser.GetSteamID() 或 SteamFriends.GetPersonaName() 等命令运行正常。但不是 SteamUser.GetAuthTicketForWebApi。

我尝试在新创建的项目上执行此操作。我已完成所有步骤,我应该做其他事情吗?:

  1. 新项目
  2. 在包管理器中添加身份验证
  3. 在 Authentication 项目设置中设置 App Id 和 Key
  4. 在包管理器中添加 steamworks.net
  5. 在 steam_appid.txt 中设置我的应用程序 ID
  6. 在场景中使用SteamManager.cs添加游戏对象
  7. 使用该代码添加游戏对象:
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.
    }

}
c# unity-game-engine steam steam-web-api steamworks-api
1个回答
0
投票

您需要定期给

SteamAPI.RunCallbacks();
打电话。尝试将其放入更新统一消息中,然后重试。

© www.soinside.com 2019 - 2024. All rights reserved.