From afaf16b37d6b666984355b8ad8596a2a7d9a8b8f Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 30 May 2019 08:53:02 +0100 Subject: [PATCH] Created Client - Getting Started (markdown) --- Client---Getting-Started.md | 87 +++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Client---Getting-Started.md diff --git a/Client---Getting-Started.md b/Client---Getting-Started.md new file mode 100644 index 0000000..a5ec012 --- /dev/null +++ b/Client---Getting-Started.md @@ -0,0 +1,87 @@ +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 somewhere - and make sure you're building as 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 `Steamworks.SteamClient.Init` 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 ); +} +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. + +```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(); +``` + +A word of 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. + +In Unity I'd recommend sticking it in an `OnDisable`, so that it gets called every time you stop playing. \ No newline at end of file