如何使用Steamworks.NET

本文详细介绍如何在Unity项目中整合Steamworks.NET,包括下载、初始化、使用SteamManager及注意事项。涵盖SteamAPI_Init、SteamAPI.RestartAppIfNecessary、steam_appid.txt与SteamAPI_Shutdown的使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

1.下载,初始化。

2.使用SteamManager

3.须知

SteamAPI_Init

SteamAPI.RestartAppIfNecessary()

steam_appid.txt

SteamAPI_Shutdown


1.下载,初始化。

链接(需梯子):SteamWorks.NET 使用说明

按以下步骤操作

步骤原文大意
1Download the .unitypackage from the Releases or clone/download the latest version from Github - (zip download).从 Releases 下载.unitypackage(或Github - (zip download).)
2Import everything into your Assets/ folder. (If you’re using a non release/github/zip version then the Standalone/ folder does not need to be imported.)将所有内容导入到Assets /文件夹中。(如果您使用的是非发行版/ github / zip版本,则无需导入Standalone /文件夹。)
3Launch your Unity project. The included editor scripts will copy steam_appid.txt into the root of your project.运行您的Unity项目。包含的编辑器脚本将把steam_appid.txt复制到项目的根目录中。
4

Open the steam_appid.txt which now resides in the root of your Unity project and replace 480 with your own AppId.

打开现在位于Unity项目根目录中的steam_appid.txt,并将480替换为您自己的AppId

 

Note: If you are using the github version you will want to grab the SteamManager MonoBehaviour. It is included in the unitypackage.

注意:如果您使用的是github版本,则需要获取SteamManager MonoBehaviour。它包含在unitypackage中。

5

Close Unity and relaunch the project so that it loads the freshly updated steam_appid.txt

关闭Unity并重新启动项目,以便它加载新近更新的steam_appid.txt

 

Head over to Getting Started to start using Steamworks.NET!

转至Getting Started 开始使用Steamworks.NET!

 

2.使用SteamManager

  1. 在第一个场景创建一个空物体,挂载SteamManager.cs。
  2. 打开脚本,将SteamAPI.RestartAppIfNecessary()的参数修改为
if (SteamAPI.RestartAppIfNecessary((AppId_t)你的应用ID)) 

现在,运行项目的话Steam客户端会显示游戏“正在运行”。

  • 注意1:通常要避免在其他脚本的Awake()和OnDestory()中,与SteamManager进行交互。因为不能保证执行顺序。
  • 注意2:在调用任何Steamworks函数之前,我们始终通过检查 SteamManager.Initialized 来确保Steam初始化。
  • 遇到问题,请查看“ Frequently Asked Questions ”

 

3.须知

SteamAPI_Init

【重要】在访问任何Steamworks接口之前,必须调用此方法并成功返回它!

原文大意

After you have the Steamworks API set up within your project you can start using it by calling SteamAPI_Init function to initialize the API. 

This will set up the global state and populate the interface pointers which are accessible via the global functions which match the name of the interface. 

在项目中设置Steamworks API后,可以通过调用SteamAPI_Init函数初始化API来开始使用它。

 

这将设置全局状态,并填充可通过与接口名称匹配的全局函数访问的接口指针。

This MUST be called and return successfully prior to accessing any of the Steamworks Interfaces!

【重要】在访问任何Steamworks接口之前,必须调用此方法并成功返回它!

The Steamworks API will not initialize if it does not know the App ID of your game. 

When you launch your app from Steam itself then it will automatically have the App ID available.

 

 While developing you will need to hint this to Steam with a text file. Create the a text file called steam_appid.txt next to your executable containing just the App ID and nothing else.

 

This overrides the value that Steam provides. You should not ship this with your builds.  

如果不知道游戏的应用程序ID,Steamworks API将不会初始化。

从Steam本身启动应用程序时,它将自动具有可用的应用程序ID。

 

在开发过程中,需要使用文本文件来提示它。在可执行文件旁边创建一个名为steam_appid.txt的文本文件,其中仅包含应用程序ID,而没有其他内容。

 

这将覆盖Steam提供的值。发行版本(build)不要提供此文件(手动删除!)。

返回false表示以下情况之一:

  
The Steam client isn't running. A running Steam client is required to provide implementations of the various Steamworks interfaces.

Steam客户端未运行

要提供各种Steamworks接口的实现,需要运行的Steam客户端

The Steam client couldn't determine the App ID of game. If you're running your application from the executable or debugger directly then you must have a steam_appid.txt in your game directory next to the executable, with your app ID in it and nothing else. Steam will look for this file in the current working directory. If you are running your executable from a different directory you may need to relocate the steam_appid.txt file.

Steam客户端无法确定游戏的应用ID。

如果您是直接从可执行文件或调试器运行应用程序,游戏目录中必须在该可执行文件旁有一个steam_appid.txt,其中应有您的应用程序ID,并且没有其他内容。Steam将在当前工作目录中查找此文件。如果您从其他目录运行可执行文件,则可能需要重新定位steam_appid.txt文件。

Your application is not running under the same OS user context as the Steam client, such as a different user or administration access level.

权限

您的应用程序不在与Steam客户端相同的OS用户上下文下运行,例如,不同的用户或管理访问级别。

Ensure that you own a license for the App ID on the currently active Steam account. Your game must show up in your Steam library.

游戏不在库中?

确保您在当前活动的Steam帐户上拥有App ID的许可证。您的游戏必须显示在Steam库中。

Your App ID is not completely set up, i.e. in Release State: Unavailable, or it's missing default packages.

错误设置

您的应用程序ID尚未完全设置,即处于发布状态:不可用,或者缺少默认软件包。

If you're running into initialization issues then see the Steamworks API 调试 documentation to learn about the various methods of debugging the Steamworks API.

如果您遇到初始化问题,请参阅Steamworks API 调试 以了解各种调试Steamworks API的方法。

 

SteamAPI.RestartAppIfNecessary()

简要说明:

原文大意
  If Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the Steam client and also launches this game again if the User owns it.如果Steam没有运行,或是游戏不是通过Steam运行的,SteamAPI_RestartAppIfNecessary会打开Steam客户端重新运行此游戏(如果用户拥有此游戏)
Once you get a Steam AppID assigned by Valve, you need to replace AppId_t.Invalid with it and remove steam_appid.txt from the game depot. eg: "(AppId_t)480" or "new AppId_t(480)".

获得Valve分配的Steam AppID后,您需要用它替换AppId_t.Invalid,并从仓库中删除steam_appid.txt。

例:“(AppId_t)480”或“new AppId_t(480)”。

详细说明:

原文大意

SteamAPI_RestartAppIfNecessary checks if your executable was launched through Steam and relaunches it through Steam if it wasn't.

检查可执行文件是否通过Steam启动,如果不是,将通过Steam重新启动

This is optional but highly recommended as the Steam context associated with your application (including your App ID) will not be set up if the user launches the executable directly.

 If this occurs then SteamAPI_Init will fail and you will be unable to use the Steamworks API.

这是可选的,但强烈建议使用。

因为如果用户直接启动可执行文件,则不会设置与此应用程序关联的Steam上下文(包括您的App ID),SteamAPI_Init将失败,并且无法使用Steamworks API。

If you choose to use this then it should be the first Steamworks function call you make, right before SteamAPI_Init.

如果使用,它应该是第一个Steamworks函数调用,在SteamAPI_Init之前。

If this returns true then it starts the Steam client if required and launches your game again through it, and you should quit your process as soon as possible. 

This effectively runs steam://run/<AppID> so it may not relaunch the exact executable that called this function (for example, if you were running from your debugger). 

It will always relaunch from the version installed in your Steam library folder.

如果返回true,它将在需要时启动Steam客户端并通过它再次启动游戏,因此您应尽快退出进程。

这将有效地运行steam:// run / <AppID>,因此它可能不会重新启动调用此函数的确切可执行文件(例如,如果您是从调试器运行的)。

它将始终从Steam库文件夹中安装的版本重新启动。

Otherwise, if it returns false, then your game was launched by the Steam client and no action needs to be taken. 

One exception is if a steam_appid.txt file is present then this will return false regardless. 

This allows you to develop and test without launching your game through the Steam client.

 Make sure to remove the steam_appid.txt file when uploading the game to your Steam depot!

否则,如果返回false,说明游戏是由Steam客户端启动的,无需采取任何措施。

一个例外是,如果存在steam_appid.txt文件,则无论如何它将返回false。

这使您无需通过Steam客户端启动游戏即可进行开发和测试。

将游戏上传到Steam仓库时,请确保删除steam_appid.txt文件!

NOTE: If you use the Steam DRM wrapper on your primary executable file, this check is unnecessary as the DRM wrapper will perform this internally.

注意:如果在主要可执行文件上使用Steam DRM包装器,则此检查是不必要的,因为DRM包装器将在内部执行此操作。

更多信息:https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown

 

steam_appid.txt

(可以理解为为了在Unity 中方便开发而存在。build时记得删掉。否则,它会屏蔽掉一些功能,比如错误判断游戏是否从steam客户端启动。)

If the steam_appid.txt file is present in the current working directory then SteamAPI_RestartAppIfNecessary() will return false. This allows you to develop without relaunching through Steam every time.

如果当前工作目录中存在steam_appid.txt文件,则SteamAPI_RestartAppIfNecessary()将返回false。这使您无需每次都重新启动Steam就可以进行开发。

 

SteamAPI_Shutdown

When you are done using the Steamworks API you should call SteamAPI_Shutdown to release the resources used by your application internally within Steam. You should call this during process shutdown if possible.

This will not unhook the Steam 界面 from your game as there's no guarantee that your rendering API is done using it.

完成使用Steamworks API的操作后,应调用SteamAPI_Shutdown在内部内部释放应用程序使用的资源。可能的话,应在进程关闭期间调用此函数。
这不能将 Steam 界面从您的游戏中解脱出来,因为不能保证您的渲染API已经使用完毕。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值