Last active
December 11, 2018 08:50
-
-
Save codehoose/1d0de5fdc159c59b30d870b01f9da926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CloudFactory | |
{ | |
public static ICloudService Create() | |
{ | |
if (Application.platform == RuntimePlatform.WindowsPlayer) | |
return new SteamCloudService(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GameSystems : MonoBehaviour | |
{ | |
private static GameSystems _instance; | |
public static GameSystems Instance | |
{ | |
get | |
{ | |
if (_instance == null) | |
{ | |
_instance = GameObject.FindObjectOfType<GameSystems>(); | |
if (_instance == null) | |
{ | |
var go = new GameObject("__GAMESYSTEMS__"); | |
_instance = go.AddComponent<GameSystems>(); | |
_instance.Cloud = CloudFactory.Create(); | |
_instance.FileIO = FileSystemFactory.Create(); | |
} | |
} | |
} | |
} | |
public ICloudService Cloud { get; private set; } | |
public IFileSystem FileIO { get; private set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ICloudService | |
{ | |
void RequestLeaderboard(int userId, Action<ILeaderboardData> callback); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SteamCloudService : ICloudService | |
{ | |
public void RequestLeaderboard(int userId, Action<ILeaderboardData> callback) | |
{ | |
// Example code, not complete | |
SteamInterface.Leaderboards.Fetch(OUR_LEADERBOARD, (boardData) => { | |
var converted = ToGameFormat(boardData); | |
callback(converted); | |
}); | |
} | |
private ILeaderboardData ToGameFormat(ISteamLeaderboard leaderboard) | |
{ | |
// TODO: Convert from Steam format to in-game format | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GameSystems
is the singleton for the game that gives the rest of the classes access to the game's systems. In this example, I have a singleton that has two systems; a cloud service and a file service. I implemented basic versions of the cloud service to illustrate the point, file system would be similar.An example call to get the leaderboard data and populate the UI might look like this: