Singleton accessors for Client/Server

This commit is contained in:
Garry Newman 2017-06-09 10:18:39 +01:00
parent d417f22336
commit 67fd7fe00a
2 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,11 @@ namespace Facepunch.Steamworks
{
public partial class Client : BaseSteamworks
{
/// <summary>
/// A singleton accessor to get the current client instance.
/// </summary>
public static Client Instance { get; private set; }
/// <summary>
/// Current user's Username
/// </summary>
@ -56,6 +61,7 @@ public partial class Client : BaseSteamworks
public Client( uint appId )
{
Instance = this;
native = new Interop.NativeInterface();
//
@ -162,6 +168,11 @@ public override void Dispose()
Achievements = null;
}
if ( Instance == this )
{
Instance = null;
}
base.Dispose();
}

View File

@ -13,6 +13,11 @@ namespace Facepunch.Steamworks
/// </summary>
public partial class Server : BaseSteamworks
{
/// <summary>
/// A singleton accessor to get the current client instance.
/// </summary>
public static Server Instance { get; private set; }
internal override bool IsGameServer { get { return true; } }
public ServerQuery Query { get; internal set; }
@ -31,6 +36,7 @@ public partial class Server : BaseSteamworks
/// <param name="VersionString">A string defining version, ie "1001"</param>
public Server( uint appId, uint IpAddress, ushort SteamPort, ushort GamePort, ushort QueryPort, bool Secure, string VersionString )
{
Instance = this;
native = new Interop.NativeInterface();
//
@ -284,6 +290,11 @@ public override void Dispose()
Auth = null;
}
if ( Instance == this )
{
Instance = null;
}
base.Dispose();
}