C# custom engine integration for PC: get started
Use this topic if you are preparing your game for publishing to the Microsoft Store on PC, and your game uses a C# based engine that does not have built in support for the GDK.
- Creating a product in Partner Center
- Integrating the GDK into C# games
- Testing Xbox Services in your game
Creating a product in Partner Center
Before you can publish a game to the Microsoft Store, you need to create your Xbox Live-enabled product in Partner Center. For more information about Partner Center, see Setting up an app or game in Partner Center, for Managed Partners.
Integrating the GDK into C# games
To integrate the GDK into C# game, the game needs 3 things:
- An "API layer" that provides C# friendly functions for the native implementation.
- An "Interop layer" that handles the interop between the managed layer (C# engine such as Unity) and the unmanaged layer (GRTS/XSAPI runtime dll).
- The dynamic-link library that actually contains the runtime implementation of the functions.
Adding requirements for Gaming Runtime Services and Xbox Services API to your project
The following steps outline the changes you need to make to your project to ensure it has all of the requirements for using the Gaming Runtime Services and Xbox Services API.
Clone or download a .zip of the Unity GDK plugin git repo from https://github.com/microsoft/gdk-unity-package.
Open the XGamingRuntimeSDK.sln which is found in gdk-unity-package/Tools/XGamingRuntimeSDK/.
Note that the solution file is for Visual Studio 2017 and the required C# version is 6 or later.
In the XGamingRuntime project open XBL\Social\XblSocialRelationshipFilter.cs and comment out the
using UnityEngine;line at the top of the file and save.
Build the XGamingRuntimeThunks project and the XGamingRuntime project.
Open your C# game project.
Set your project to target x64.
Add a reference to the XGamingRuntime.dll that you built with the XGamingRuntime project.
You can find the DLL under gdk-unity-package-main\Tools\XGamingRuntimeSDK\Gaming.Desktop.x64\Debug|Release.
Make sure XGamingRuntime.dll, XGamingRuntimeThunks.dll, and XCurl.dll are copied to the same directy your .exe is built in.
You can find the DLLs under gdk-unity-package-main\Tools\XGamingRuntimeSDK\Gaming.Desktop.x64\Debug|Release.
Make sure Microsoft_Xbox_Services_141_GDK_C_Thunks.dll is copied to the same directory your .exe is built in.
You can find the DLL in the GDK install path under C:\Program Files (x86)\Microsoft GDK\220300\GRDK\ExtensionLibraries\Xbox.Services.API.C\DesignTime\CommonConfiguration\Neutral\Lib\Debug|Release.
Note that the DLL name uses periods instead of underscores in the GDK and must be renamed to use underscores instead of periods.
Create a MicrosoftGame.config file and make sure it is copied to the same destination as the .exe during builds.
For starting development you can use a config with default values like the following example. Values for Identity->Name, Executable->Name, and Executable->Alias would all be replaced with the name of your executable.
<?xml version="1.0" encoding="utf-8"?> <Game configVersion="1"> <Identity Name="Direct3DGame1_test" Publisher="CN=Publisher" Version="22.214.171.124"/> <ExecutableList> <Executable Name="Direct3DGame1_test.exe" Id="Game" Alias="Direct3DGame1_test.exe"/> </ExecutableList> <ShellVisuals DefaultDisplayName="Direct3DGame1_test" PublisherDisplayName="PublisherName" Square480x480Logo="LargeLogo.png" Square150x150Logo="GraphicsLogo.png" Square44x44Logo="SmallLogo.png" Description="Direct3DGame1_test" ForegroundText="light" BackgroundColor="#000040" SplashScreenImage="SplashScreen.png" StoreLogo="StoreLogo.png"/> </Game>
The MicrosoftGame.config file created in the previous step has default values that allow early development on PC and Xbox without the need for further configuration until you start to use features in the Gaming Runtime, Microsoft Store, and title identity. In order to use Xbox services functionality you need to update your project's MicrosoftGame.config with your Partner Center project identity details.
You'll also need to list VC14 as a known dependency which is required by Microsoft_Xbox_Services_141_GDK_C_Thunks.dll.
- Go to the Partner Center dashboard.
- Select your game from the list of products.
- Select the Game setup tab, and then select Identity details.
- Select Show Details to expand the Identity details section.
- Use the following values from the table in the Identity details section, and then copy those values from Partner Center into the corresponding element and field in MicrosoftGame.config.
- Add a KnownDependency element for VC14 in DesktopRegistrarion->DependencyList.
|Name in Partner Center||MicrosoftGame.config|
|Xbox Title ID||TitleId|
|Xbox services -> Xbox Settings -> MSAAppId||MSAAppId|
For example, the following identity details in Partner Center would result in your MicrosoftGame.config looking like the sample bellow:
|Name in Partner Center||Example value|
|Xbox Title ID||64353034|
|Xbox services -> Xbox Settings -> MSAAppId||0000000000000000|
<?xml version="1.0" encoding="utf-8"?> <Game configVersion="1"> <Identity Name='41336MicrosoftATG.Achievements2017Redux' Version="126.96.36.199" Publisher='CN=A4954634-DF4B-47C7-AB70-D3215D246AF1' /> <TitleId>64353034</TitleId> <MSAAppId>0000000000000000</MSAAppId> <ExecutableList> <Executable Name="Achievements2017_desktop.exe" TargetDeviceFamily="PC" Id="Game"/> </ExecutableList> <ShellVisuals DefaultDisplayName="Achievements2017 Desktop Sample" PublisherDisplayName="Xbox Advanced Technology Group" StoreLogo="Assets\StoreLogo.png" Square150x150Logo="Assets\Logo.png" Square44x44Logo="Assets\SmallLogo.png" Square480x480Logo="Assets\LargeLogo.png" Description="Achievements2017" ForegroundText="dark" BackgroundColor="#000000" SplashScreenImage="Assets\SplashScreen.png"/> <DesktopRegistration> <DependencyList> <KnownDependency Name="VC14"/> </DependencyList> </DesktopRegistration> </Game>
See MicrosoftGame.config overview for additional information on the values in MicrosoftGame.config.
Initialize the game runtime and XSAPI
The following steps show how to initialize Gaming Runtime Services and XSAPI in your game.
using XGamingRuntime;to your project's .cs file.
using XGamingRuntime.Interop;to your project's .cs file.
- Add a call to initialize the Gaming Runtime:
Int32 hr = SDK.XGameRuntimeInitialize();
- Add a call to initialize Xbox services:
Replace SCID with a string containing your Partner Center project's SCID.
Int32 hresult = SDK.XBL.XblInitialize(SCID);
Testing Xbox services in your game
In order to test Xbox services functionality in your game such as achievements, you need to use a sandbox and test accounts with access to that sandbox.
Creating a test account
To test any Xbox services features in your game you'll need to create test accounts that have access to your development sandbox. For information about creating test accounts, see Creating test accounts.
Switching your sandbox
After you've created a test account, use the account to access your sandbox by using the following steps.
- To find your sandbox ID, go to Partner Center.
- Select Xbox Live, and then select Gameplay Settings.
Your sandbox ID is on the first tab, and it's named like "ABCDEF.0".
- Open the Start menu.
- Enter Microsoft GDK Command Prompts, and then select Enter on your keyboard.
- Open the first command prompt.
- In the command prompt, enter XblPCSandbox.exe [your sandbox ID].
- After the command prompt launches several apps, sign in with your test account to the Xbox App.
If you're able to sign in successfully, you've created a test account and changed to your sandbox to begin testing.
For more information on sandboxes see Xbox Live Sandboxes overview.
In order to be ready to publish your game, you need to:
- Have finished integrating your game with the GDK
- Created a game package by following the steps in Getting started with packaging titles for a PC by using the MSIXVC packaging tools
After you've completed those two requirements, you're ready to publish. To submit your game, go to Partner Center and follow the instructions in the UI.