Coding Guidelines

Maker sure that InApp purchases Setup Guide is complete.

 

Before using GameCircle API, we need to init SA_AmazonGameCircleManager. We can also subscript for alavalible events before initing.

SA_AmazonGameCircleManager.instance.OnInitializeResult += OnInitializeResult;

SA_AmazonGameCircleManager.instance.OnRequestPlayerDataReceived += OnRequestPlayerDataReceived;

SA_AmazonGameCircleManager.instance.OnRequestAchievementsReceived += OnRequestAchievementsReceived;

SA_AmazonGameCircleManager.instance.OnUpdateAchievementReceived += OnUpdateAchievementReceived;

SA_AmazonGameCircleManager.instance.OnRequestLeaderboardsReceived += OnRequestLeaderboardsReceived;

SA_AmazonGameCircleManager.instance.OnSubmitLeaderboardReceived += OnSubmitLeaderboardReceived;

 

After init call we will get folliwing actions fired:

public Action<AMN_InitializeResult> OnInitializeResult = delegate {};
public Action<AMN_RequestPlayerDataResult> OnRequestPlayerDataReceived = delegate {};
public Action<AMN_RequestAchievementsResult> OnRequestAchievementsReceived = delegate {};
public Action<AMN_UpdateAchievementResult> OnUpdateAchievementReceived = delegate {};
public Action<AMN_RequestLeaderboardsResult> OnRequestLeaderboardsReceived = delegate {};
public Action<AMN_SubmitLeaderboardResult> OnSubmitLeaderboardReceived = delegate {};

 

So it's good practice to subscribe on it before initializing SA_AmazonGameCircleManager, as we already did. Here is parse example of those events.

 

OnInitializeResult action will tell us about initialization info(status):

void OnInitializeResult(AMN_InitializeResult result) {
    if (result.isSuccess) {			
		isInitialized = true;

		playerLabel.text = "Player Connected";
		SA_StatusBar.text = "Amazon connected";
	} else {			
		playerLabel.text = "Player Disconnected";	
		SA_StatusBar.text = "Amazon disconnected with error " + result.Error;
	}
}

 

OnRequestPlayerDataReceived action will tell us about Player info(avatar, id, alias):

void OnRequestPlayerDataReceived(AMN_RequestPlayerDataResult result) {
	if (result.isSuccess) {			
		SA_AmazonGSPlayer player = result.Player;
		playerID.text = "PlayerID: " + " " + player.PlayerId;
		alias.text = "Alias: " + " " + player.Alias;
		LoadAvatar (player.AvatarUrl);
	} else {			
		playerID.text = "PlayerID: none";
		alias.text = "Alias: none";
	}
}

 

OnRequestAchievementsReceived action will tell us about full info of your Achievements:

void OnRequestAchievementsReceived(AMN_RequestAchievementsResult result) {
	if (result.isSuccess) {
		achievements = result.AchievementList;

		Debug.Log("Printing Achievements list, total items: " + achievements.Count);
		foreach(SA_GCAchievement ach in achievements) {
			Debug.Log(ach.Id);
	    	Debug.Log(ach.Description);
			Debug.Log(ach.PointValue);
			Debug.Log(ach.DateUnlocked);

		}


		SA_StatusBar.text = "OnRequest Achievements success!";
	} else {
		SA_StatusBar.text = "OnRequest Achievements Failed with error " + result.Error;
	}
}

 

OnRequestLeaderboardsReceived action will tell us about full info of your Leaderboards:

void OnRequestLeaderboardsReceived(AMN_RequestLeaderboardsResult result) {
    if (result.isSuccess) {
		leaderboards = result.LeaderboardsList;

		Debug.Log("Printing Leaderboards list, total items: " + leaderboards.Count);
		foreach(SA_GCLeaderboard lb in leaderboards) {
			Debug.Log(lb.Id);
			Debug.Log(lb.Name);
			Debug.Log(lb.DisplayText);
			Debug.Log(lb.ImageUrl);
		}

		SA_StatusBar.text = "OnRequest Leaderboards success!";
	} else {
		SA_StatusBar.text = "OnRequest Leaderboards Failed with error " + result.Error;
	}
}

 

To upgrade achievements You need to do:

SA_AmazonGameCircleManager.instance.UpdateAchievementProgress (achieve_id, achieve_progress);

 

After this action come event the result of the upgrade:

void OnUpdateAchievementReceived(AMN_UpdateAchievementResult result) {
	if (result.isSuccess) {
		SA_StatusBar.text = "OnUpdate Achievement Completed for id " + result.AchievementID;
	} else {
		SA_StatusBar.text =  "OnUpdate Achievement Failed for id " + result.AchievementID + result.Error;
	}
}

 

To upgrade leaderboards You need to do:

SA_AmazonGameCircleManager.instance.SubmitLeaderBoardProgress (leaderboard_id, leaderboard_progress);

 

After this action come event the result of the upgrade:

void OnSubmitLeaderboardReceived(AMN_SubmitLeaderboardResult result) {
	if (result.isSuccess) {
		SA_StatusBar.text = "OnSubmit Leaderboard Completed for id " + result.LeaderboardID;
	} else {
		SA_StatusBar.text = "OnSubmit Leaderboard Failed for id " + result.LeaderboardID + result.Error;
	}
}

 

ShowGCOverlay action will show us ShowGCOverlay UI of Game Circle:

SA_AmazonGameCircleManager.instance.ShowGCOverlay ();

 

ShowSignInPage action will show us ShowSignInPage UI of Game Circle:

SA_AmazonGameCircleManager.instance.ShowSignInPage ();

 

ShowAchievementsOverlay action will show us ShowAchievementsOverlay UI of Game Circle:

SA_AmazonGameCircleManager.instance.ShowAchievementsOverlay ();

 

ShowLeaderboardsOverlay action will show us ShowLeaderboardsOverlay UI of Game Circle:

SA_AmazonGameCircleManager.instance.ShowLeaderboardsOverlay ();

 

The full implementation example can be found under SA_AmazonGCExample.cs script.