Revision Difference
Setting_Up#524489
<cat>gettingstarted</cat>⤶
<title>Setting Up</title>⤶
⤶
If you're making a game you probably want the SteamClient. ⤶
⤶
This gives access to things like friends, achievements, stats, server lists etc.⤶
⤶
# Dlls⤶
⤶
You need to copy us to your project to be able to use Steamworks.⤶
⤶
## Regular .net app⤶
⤶
You'll need to put steam_api64.dll/steam_api.dll somewhere (depending on whether you're building 32bit/64bit)⤶
⤶
## Unity⤶
⤶
If you're using Unity, open the release zip file and copy the Unity file into your project, anywhere in `Assets` (we usually put it in `Assets/Plugins/Facepunch.Steamworks/`.⤶
⤶
The zip file already includes `.meta` files so that files the dlls are set up properly. The `.meta` files for the native dlls are set up in a way that mean that they're used on the right platforms and will get copied properly on build. You don't need to do anything special.⤶
⤶
# Initializing⤶
⤶
To start up you just call <page>SteamClient.Init</page> with your appid. ⤶
⤶
If it can't initialize it'll throw an exception - so make sure you catch that and deal with it.⤶
⤶
```csharp⤶
try⤶
{⤶
Steamworks.SteamClient.Init( 252490, true );⤶
}⤶
catch ( System.Exception e )⤶
{⤶
// Something went wrong! Steam is closed?⤶
}⤶
```⤶
⤶
Common reasons for exceptions are:⤶
⤶
* Steam is closed⤶
* Can't find steam_api dlls⤶
* Don't have permission to open appid ⤶
⤶
In Unity I'd recommend calling this in an Awake on an object with [DontDestroyOnLoad](https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html) called on it.⤶
⤶
# Running⤶
⤶
Every frame or so you should call RunCallbacks. ⤶
⤶
This isn't needed if you left asyncCallbacks as true in Client.Init because it'll be called every frame anyway (in the background).⤶
⤶
```csharp⤶
Steamworks.SteamClient.RunCallbacks();⤶
```⤶
⤶
In Unity I'd recommend sticking it in an `Update`.⤶
⤶
# Using⤶
⤶
You can make sure Steam is loaded and accessible using `SteamClient.IsValid`.⤶
⤶
Here's some examples of other interfaces and functions to give you an idea of how to use/find stuff.⤶
⤶
```csharp⤶
var playername = SteamClient.Name;⤶
var playersteamid = SteamClient.SteamId;⤶
⤶
SteamScreenshots.TriggerScreenshot();⤶
⤶
Steamworks.SteamUserStats.SetStat( "deaths", value );⤶
⤶
foreach ( var item in Steamworks.SteamInventory.Items )⤶
{⤶
Debug.Log( $"{item.Def.Name} x {item.Quantity}" );⤶
}⤶
⤶
foreach ( var player in SteamFriends.GetFriends() )⤶
{⤶
Debug.Log( $"{player.Name}" );⤶
}⤶
```⤶
⤶
# Shutting Down⤶
⤶
When you're done call `SteamClient.Shutdown`.⤶
⤶
```csharp⤶
Steamworks.SteamClient.Shutdown();⤶
```⤶
⤶
<warning>Steam won't actually show that you've stopped playing the game at this point. It doesn't do that until the exe and any child processes are closed. It sucks, but that's the way it is.⤶
⤶
This also means that in the Unity Editor it'll show as in game until you close the editor, but subsequent `SteamClient.Init` calls are needed and will work.⤶
</warning>⤶
⤶
⤶
In Unity I'd recommend sticking it in an `OnDisable`, so that it gets called every time you stop playing.