<file_sep># gamesparks-tbrpg-addons

This is Gamesparks integration for Turnbase RPG template project (https://www.assetstore.unity3d.com/en/#!/content/107578)

Require: https://github.com/insthync/CloudCode-GS-TBRPG
<file_sep>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using GameSparks.Core;

public partial class GSGameService
{
    protected override void DoArenaGetOpponentList(string playerId, string loginToken, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        var request = GetGSEventRequest("GetOpponentList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<Player>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoStartDuel(string playerId, string loginToken, string targetPlayerId, UnityAction<StartDuelResult> onFinish)
    {
        var result = new StartDuelResult();
        var data = new GSRequestData();
        data.AddString("targetPlayerId", targetPlayerId);
        var request = GetGSEventRequest("StartDuel", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var stamina = scriptData.GetGSData("stamina");
                    var session = scriptData.GetString("session");
                    var opponentCharacters = scriptData.GetGSDataList("opponentCharacters");
                    
                    result.stamina = JsonUtility.FromJson<PlayerStamina>(stamina.JSON);
                    result.session = session;
                    foreach (var entry in opponentCharacters)
                    {
                        result.opponentCharacters.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoFinishDuel(string playerId, string loginToken, string session, EBattleResult battleResult, int deadCharacters, UnityAction<FinishDuelResult> onFinish)
    {
        var result = new FinishDuelResult();
        var data = new GSRequestData();
        data.AddString("session", session);
        data.AddNumber("battleResult", (byte)battleResult);
        data.AddNumber("deadCharacters", deadCharacters);
        var request = GetGSEventRequest("FinishDuel", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var rewardItems = scriptData.GetGSDataList("rewardItems");
                    var createItems = scriptData.GetGSDataList("createItems");
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");
                    var rewardSoftCurrency = scriptData.GetInt("rewardSoftCurrency").Value;
                    var rewardHardCurrency = scriptData.GetInt("rewardHardCurrency").Value;
                    var updateScore = scriptData.GetInt("updateScore").Value;
                    var rating = scriptData.GetInt("rating").Value;
                    var player = scriptData.GetGSData("player");

                    foreach (var entry in rewardItems)
                    {
                        result.rewardItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in createItems)
                    {
                        result.createItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                    result.rewardSoftCurrency = rewardSoftCurrency;
                    result.rewardHardCurrency = rewardHardCurrency;
                    result.updateScore = updateScore;
                    result.rating = rating;
                    result.player = JsonUtility.FromJson<Player>(player.JSON);
                }
            }
            onFinish(result);
        });
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using GameSparks.Core;

public partial class GSGameService
{
    protected override void DoStartStage(string playerId, string loginToken, string stageDataId, string helperPlayerId, UnityAction<StartStageResult> onFinish)
    {
        var result = new StartStageResult();
        var data = new GSRequestData();
        data.AddString("stageDataId", stageDataId);
        data.AddString("helperPlayerId", helperPlayerId);
        var request = GetGSEventRequest("StartStage", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var stamina = scriptData.GetGSData("stamina");
                    var session = scriptData.GetString("session");
                    
                    result.stamina = JsonUtility.FromJson<PlayerStamina>(stamina.JSON);
                    result.session = session;
                }
            }
            onFinish(result);
        });
    }

    protected override void DoFinishStage(string playerId, string loginToken, string session, EBattleResult battleResult, int deadCharacters, UnityAction<FinishStageResult> onFinish)
    {
        var result = new FinishStageResult();
        var data = new GSRequestData();
        data.AddString("session", session);
        data.AddNumber("battleResult", (byte)battleResult);
        data.AddNumber("deadCharacters", deadCharacters);
        var request = GetGSEventRequest("FinishStage", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var isFirstClear = scriptData.GetBoolean("isFirstClear").Value;
                    var firstClearRewardPlayerExp = scriptData.GetInt("firstClearRewardPlayerExp").Value;
                    var firstClearRewardSoftCurrency = scriptData.GetInt("firstClearRewardSoftCurrency").Value;
                    var firstClearRewardHardCurrency = scriptData.GetInt("firstClearRewardHardCurrency").Value;
                    var firstClearRewardItems = scriptData.GetGSDataList("firstClearRewardItems");
                    var rewardItems = scriptData.GetGSDataList("rewardItems");
                    var createItems = scriptData.GetGSDataList("createItems");
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");
                    var rewardPlayerExp = scriptData.GetInt("rewardPlayerExp").Value;
                    var rewardCharacterExp = scriptData.GetInt("rewardCharacterExp").Value;
                    var rewardSoftCurrency = scriptData.GetInt("rewardSoftCurrency").Value;
                    var rating = scriptData.GetInt("rating").Value;
                    var clearStage = scriptData.GetGSData("clearStage");
                    var player = scriptData.GetGSData("player");

                    foreach (var entry in firstClearRewardItems)
                    {
                        result.firstClearRewardItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in rewardItems)
                    {
                        result.rewardItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in createItems)
                    {
                        result.createItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                    result.isFirstClear = isFirstClear;
                    result.firstClearRewardPlayerExp = firstClearRewardPlayerExp;
                    result.firstClearRewardSoftCurrency = firstClearRewardSoftCurrency;
                    result.firstClearRewardHardCurrency = firstClearRewardHardCurrency;
                    result.rewardPlayerExp = rewardPlayerExp;
                    result.rewardCharacterExp = rewardCharacterExp;
                    result.rewardSoftCurrency = rewardSoftCurrency;
                    result.rating = rating;
                    result.clearStage = JsonUtility.FromJson<PlayerClearStage>(clearStage.JSON);
                    result.player = JsonUtility.FromJson<Player>(player.JSON);
                }
            }
            onFinish(result);
        });
    }

    protected override void DoReviveCharacters(string playerId, string loginToken, UnityAction<CurrencyResult> onFinish)
    {
        var result = new CurrencyResult();
        var request = GetGSEventRequest("ReviveCharacters");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoSelectFormation(string playerId, string loginToken, string formationName, EFormationType formationType, UnityAction<PlayerResult> onFinish)
    {
        var result = new PlayerResult();
        var data = new GSRequestData();
        data.AddString("formationName", formationName);
        data.AddNumber("formationType", (byte)formationType);
        var request = GetGSEventRequest("SelectFormation", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var player = scriptData.GetGSData("player");
                    result.player = JsonUtility.FromJson<Player>(player.JSON);
                }
            }
            onFinish(result);
        });
    }

    protected override void DoSetFormation(string playerId, string loginToken, string characterId, string formationName, int position, UnityAction<FormationListResult> onFinish)
    {
        var result = new FormationListResult();
        var data = new GSRequestData();
        data.AddString("characterId", characterId);
        data.AddString("formationName", formationName);
        data.AddNumber("position", position);
        var request = GetGSEventRequest("SetFormation", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var list = scriptData.GetGSDataList("list");
                    foreach (var entry in list)
                    {
                        result.list.Add(JsonUtility.FromJson<PlayerFormation>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Events;
using GameSparks.Core;
using GameSparks.Api.Requests;
#if UNITY_EDITOR
using UnityEditor;
#endif


public partial class GSGameService : BaseGameService
{
    private void Awake()
    {
        StartCoroutine(WaitForGS());
    }
    
    IEnumerator WaitForGS()
    {
        while (!GS.Available)
            yield return 0;

        Debug.Log("Gamesparks ready.");
    }

#if UNITY_EDITOR
    [ContextMenu("Export Game Database")]
    public void ExportGameDatabase()
    {
        var gameInstance = FindObjectOfType<GameInstance>();
        if (gameInstance == null)
        {
            Debug.LogError("Cannot export game database, no game instance found");
            return;
        }
        var gameDatabase = gameInstance.gameDatabase;
        if (gameDatabase == null)
        {
            Debug.LogError("Cannot export game database, no game database found");
            return;
        }
        gameDatabase.Setup();
        var achievementsJson = "";
        var itemsJson = "";
        var currenciesJson = "";
        var staminasJson = "";
        var formationsJson = "";
        var stagesJson = "";
        var lootBoxesJson = "";
        var iapPackagesJson = "";
        var inGamePackagesJson = "";
        var startItemsJson = "";
        var startCharactersJson = "";
        var unlockStagesJson = "";
        var arenaRanksJson = "";

        foreach (var achievement in gameDatabase.Achievements)
        {
            if (!string.IsNullOrEmpty(achievementsJson))
                achievementsJson += ",";
            achievementsJson += "\"" + achievement.Key + "\":" + achievement.Value.ToJson();
        }
        achievementsJson = "{" + achievementsJson + "}";

        foreach (var item in gameDatabase.Items)
        {
            if (!string.IsNullOrEmpty(itemsJson))
                itemsJson += ",";
            itemsJson += "\"" + item.Key + "\":" + item.Value.ToJson();
        }
        itemsJson = "{" + itemsJson + "}";

        currenciesJson = "{\"SOFT_CURRENCY\":\"" + gameDatabase.softCurrency.id + "\", \"HARD_CURRENCY\":\"" + gameDatabase.hardCurrency.id + "\"}";
        staminasJson = "{\"STAGE\":" + gameDatabase.stageStamina.ToJson() + ", \"ARENA\":" + gameDatabase.arenaStamina.ToJson() + "}";

        foreach (var entry in gameDatabase.Formations)
        {
            if (!string.IsNullOrEmpty(formationsJson))
                formationsJson += ",";
            formationsJson += "\"" + entry.Key + "\"";
        }
        formationsJson = "[" + formationsJson + "]";

        foreach (var entry in gameDatabase.Stages)
        {
            if (!string.IsNullOrEmpty(stagesJson))
                stagesJson += ",";
            stagesJson += "\"" + entry.Key + "\":" + entry.Value.ToJson();
        }
        stagesJson = "{" + stagesJson + "}";

        foreach (var entry in gameDatabase.LootBoxes)
        {
            if (!string.IsNullOrEmpty(lootBoxesJson))
                lootBoxesJson += ",";
            lootBoxesJson += "\"" + entry.Key + "\":" + entry.Value.ToJson();
        }
        lootBoxesJson = "{" + lootBoxesJson + "}";

        foreach (var entry in gameDatabase.IapPackages)
        {
            if (!string.IsNullOrEmpty(iapPackagesJson))
                iapPackagesJson += ",";
            iapPackagesJson += "\"" + entry.Key + "\":" + entry.Value.ToJson();
        }
        iapPackagesJson = "{" + iapPackagesJson + "}";

        foreach (var entry in gameDatabase.InGamePackages)
        {
            if (!string.IsNullOrEmpty(inGamePackagesJson))
                inGamePackagesJson += ",";
            inGamePackagesJson += "\"" + entry.Key + "\":" + entry.Value.ToJson();
        }
        inGamePackagesJson = "{" + inGamePackagesJson + "}";

        foreach (var entry in gameDatabase.startItems)
        {
            if (entry == null || entry.item == null)
                continue;
            if (!string.IsNullOrEmpty(startItemsJson))
                startItemsJson += ",";
            startItemsJson += entry.ToJson();
        }
        startItemsJson = "[" + startItemsJson + "]";

        foreach (var entry in gameDatabase.startCharacters)
        {
            if (entry == null)
                continue;
            if (!string.IsNullOrEmpty(startCharactersJson))
                startCharactersJson += ",";
            startCharactersJson += "\"" + entry.Id + "\"";
        }
        startCharactersJson = "[" + startCharactersJson + "]";

        foreach (var entry in gameDatabase.unlockStages)
        {
            if (entry == null)
                continue;
            if (!string.IsNullOrEmpty(unlockStagesJson))
                unlockStagesJson += ",";
            unlockStagesJson += "\"" + entry.Id + "\"";
        }
        unlockStagesJson = "[" + unlockStagesJson + "]";

        foreach (var entry in gameDatabase.arenaRanks)
        {
            if (entry == null)
                continue;
            if (!string.IsNullOrEmpty(arenaRanksJson))
                arenaRanksJson += ",";
            arenaRanksJson += entry.ToJson();
        }
        arenaRanksJson = "[" + arenaRanksJson + "]";

        var jsonCombined = "{" +
            "\"achievements\":" + achievementsJson + "," +
            "\"items\":" + itemsJson + "," +
            "\"currencies\":" + currenciesJson + "," +
            "\"staminas\":" + staminasJson + "," +
            "\"formations\":" + formationsJson + "," +
            "\"stages\":" + stagesJson + "," +
            "\"lootBoxes\":" + lootBoxesJson + "," +
            "\"iapPackages\":" + iapPackagesJson + "," +
            "\"inGamePackages\":" + inGamePackagesJson + "," +
            "\"hardToSoftCurrencyConversion\":" + gameDatabase.hardToSoftCurrencyConversion + "," +
            "\"startItems\":" + startItemsJson + "," +
            "\"startCharacters\":" + startCharactersJson + "," +
            "\"unlockStages\":" + unlockStagesJson + "," +
            "\"arenaRanks\":" + arenaRanksJson + "," +
            "\"arenaWinScoreIncrease\":" + gameDatabase.arenaWinScoreIncrease + "," +
            "\"arenaLoseScoreDecrease\":" + gameDatabase.arenaLoseScoreDecrease + "," +
            "\"playerMaxLevel\":" + gameDatabase.playerMaxLevel + "," +
            "\"playerExpTable\":" + gameDatabase.playerExpTable.ToJson() + "," +
            "\"revivePrice\":" + gameDatabase.revivePrice + "," +
            "\"resetItemLevelAfterEvolve\":" + (gameDatabase.resetItemLevelAfterEvolve ? 1 : 0) + "}";

        var cloudCodes = "var gameDatabase = " + jsonCombined + ";";
        var path = EditorUtility.SaveFilePanel("Export Game Database", Application.dataPath, "GAME_DATA", "js");
        if (path.Length > 0)
            File.WriteAllText(path, cloudCodes);
    }
#endif

    protected LogEventRequest GetGSEventRequest(string target, GSRequestData data = null)
    {
        if (data == null)
            data = new GSRequestData();
        var request = new LogEventRequest();
        request.SetEventKey("SERVICE_EVENT");
        request.SetEventAttribute("TARGET", target);
        request.SetEventAttribute("DATA", data);
        return request;
    }

    protected override void DoGetAchievementList(string playerId, string loginToken, UnityAction<AchievementListResult> onFinish)
    {
        var result = new AchievementListResult();
        var request = GetGSEventRequest("GetAchievementList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<PlayerAchievement>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetAuthList(string playerId, string loginToken, UnityAction<AuthListResult> onFinish)
    {
        var result = new AuthListResult();
        onFinish(result);
    }

    protected override void DoGetItemList(string playerId, string loginToken, UnityAction<ItemListResult> onFinish)
    {
        var result = new ItemListResult();
        var request = GetGSEventRequest("GetItemList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetCurrencyList(string playerId, string loginToken, UnityAction<CurrencyListResult> onFinish)
    {
        var result = new CurrencyListResult();
        var request = GetGSEventRequest("GetCurrencyList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetStaminaList(string playerId, string loginToken, UnityAction<StaminaListResult> onFinish)
    {
        var result = new StaminaListResult();
        var request = GetGSEventRequest("GetStaminaList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<PlayerStamina>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetFormationList(string playerId, string loginToken, UnityAction<FormationListResult> onFinish)
    {
        var result = new FormationListResult();
        var request = GetGSEventRequest("GetFormationList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<PlayerFormation>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetUnlockItemList(string playerId, string loginToken, UnityAction<UnlockItemListResult> onFinish)
    {
        var result = new UnlockItemListResult();
        var request = GetGSEventRequest("GetUnlockItemList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<PlayerUnlockItem>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetClearStageList(string playerId, string loginToken, UnityAction<ClearStageListResult> onFinish)
    {
        var result = new ClearStageListResult();
        var request = GetGSEventRequest("GetClearStageList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<PlayerClearStage>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetServiceTime(UnityAction<ServiceTimeResult> onFinish)
    {
        var result = new ServiceTimeResult();
        var request = GetGSEventRequest("ServiceTime");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("serviceTime"))
            {
                result.serviceTime = scriptData.GetLong("serviceTime").Value;
            }
            onFinish(result);
        });
    }
}
<file_sep>﻿using UnityEngine;
using System.Collections;
using UnityEngine.Events;

public partial class GSGameService
{
    protected override void DoCreateClan(string playerId, string loginToken, string clanName, UnityAction<CreateClanResult> onFinish)
    {
        var result = new CreateClanResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoFindClan(string playerId, string loginToken, string clanName, UnityAction<ClanListResult> onFinish)
    {
        var result = new ClanListResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanJoinRequest(string playerId, string loginToken, string clanId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanJoinAccept(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanJoinDecline(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanMemberDelete(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanJoinRequestDelete(string playerId, string loginToken, string clanId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoGetClanMemberList(string playerId, string loginToken, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanOwnerTransfer(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanTerminate(string playerId, string loginToken, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoGetClan(string playerId, string loginToken, UnityAction<ClanResult> onFinish)
    {
        var result = new ClanResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoGetClanJoinRequestList(string playerId, string loginToken, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoGetClanJoinPendingRequestList(string playerId, string loginToken, UnityAction<ClanListResult> onFinish)
    {
        var result = new ClanListResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanExit(string playerId, string loginToken, UnityAction<GameServiceResult> onFinish)
    {
        var result = new ClanResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }

    protected override void DoClanSetRole(string playerId, string loginToken, string targetPlayerId, byte clanRole, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using GameSparks.Core;
using GameSparks.Api.Requests;
using GameSparks.Api.Responses;

public partial class GSGameService
{
    protected override void DoLevelUpItem(string playerId, string loginToken, string itemId, Dictionary<string, int> materials, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        var data = new GSRequestData();
        data.AddString("itemId", itemId);
        var materialsObject = new GSRequestData();
        foreach (var material in materials)
        {
            materialsObject.AddNumber(material.Key, material.Value);
        }
        data.AddObject("materials", materialsObject);
        var request = GetGSEventRequest("LevelUpItem", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");
                    
                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoEvolveItem(string playerId, string loginToken, string itemId, Dictionary<string, int> materials, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        var data = new GSRequestData();
        data.AddString("itemId", itemId);
        var materialsObject = new GSRequestData();
        foreach (var material in materials)
        {
            materialsObject.AddNumber(material.Key, material.Value);
        }
        data.AddObject("materials", materialsObject);
        var request = GetGSEventRequest("EvolveItem", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");

                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoSellItems(string playerId, string loginToken, Dictionary<string, int> items, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        var data = new GSRequestData();
        var itemsObject = new GSRequestData();
        foreach (var item in items)
        {
            itemsObject.AddNumber(item.Key, item.Value);
        }
        data.AddObject("items", itemsObject);
        var request = GetGSEventRequest("SellItems", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");

                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoEquipItem(string playerId, string loginToken, string characterId, string equipmentId, string equipPosition, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        var data = new GSRequestData();
        data.AddString("characterId", characterId);
        data.AddString("equipmentId", equipmentId);
        data.AddString("equipPosition", equipPosition);
        var request = GetGSEventRequest("EquipItem", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var updateItems = scriptData.GetGSDataList("updateItems");

                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoUnEquipItem(string playerId, string loginToken, string equipmentId, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        var data = new GSRequestData();
        data.AddString("equipmentId", equipmentId);
        var request = GetGSEventRequest("UnEquipItem", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var updateItems = scriptData.GetGSDataList("updateItems");

                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetAvailableLootBoxList(UnityAction<AvailableLootBoxListResult> onFinish)
    {
        var result = new AvailableLootBoxListResult();
        var request = GetGSEventRequest("GetAvailableLootBoxList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetStringList("list");
                result.list = list;
            }
            onFinish(result);
        });
    }

    protected override void DoGetAvailableIapPackageList(UnityAction<AvailableIapPackageListResult> onFinish)
    {
        var result = new AvailableIapPackageListResult();
        var request = GetGSEventRequest("GetAvailableIapPackageList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetStringList("list");
                result.list = list;
            }
            onFinish(result);
        });
    }

    protected override void DoGetAvailableInGamePackageList(UnityAction<AvailableInGamePackageListResult> onFinish)
    {
        var result = new AvailableInGamePackageListResult();
        var request = GetGSEventRequest("GetAvailableInGamePackageList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetStringList("list");
                result.list = list;
            }
            onFinish(result);
        });
    }

    protected override void DoOpenLootBox(string playerId, string loginToken, string lootBoxDataId, int packIndex, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        var data = new GSRequestData();
        data.AddString("lootBoxDataId", lootBoxDataId);
        data.AddNumber("packIndex", packIndex);
        var request = GetGSEventRequest("OpenLootBox", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var rewardItems = scriptData.GetGSDataList("rewardItems");
                    var createItems = scriptData.GetGSDataList("createItems");
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");

                    foreach (var entry in rewardItems)
                    {
                        result.rewardItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in createItems)
                    {
                        result.createItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoOpenIapPackage_iOS(string playerId, string loginToken, string iapPackageDataId, string receipt, UnityAction<ItemResult> onFinish)
    {
        var request = new IOSBuyGoodsRequest();
        request.SetReceipt(receipt);
        request.Send((response) =>
        {
            IapResponse(response, onFinish);
        });
    }

    protected override void DoOpenIapPackage_Android(string playerId, string loginToken, string iapPackageDataId, string data, string signature, UnityAction<ItemResult> onFinish)
    {
        var request = new GooglePlayBuyGoodsRequest();
        request.SetSignedData(data);
        request.SetSignature(signature);
        request.Send((response) =>
        {
            IapResponse(response, onFinish);
        });
    }

    private void IapResponse(BuyVirtualGoodResponse response, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();

        if (!response.HasErrors)
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var rewardItems = scriptData.GetGSDataList("rewardItems");
                    var createItems = scriptData.GetGSDataList("createItems");
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");

                    foreach (var entry in rewardItems)
                    {
                        result.rewardItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in createItems)
                    {
                        result.createItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        }
        else
        {
            Debug.LogError("GameSparks error while request accout details: " + response.Errors.JSON);
            result.error = GameServiceErrorCode.UNKNOW;
            onFinish(result);
        }
    }

    protected override void DoEarnAchievementReward(string playerId, string loginToken, string achievementId, UnityAction<EarnAchievementResult> onFinish)
    {
        var result = new EarnAchievementResult();
        var data = new GSRequestData();
        data.AddString("achievementId", achievementId);
        var request = GetGSEventRequest("EarnAchievementReward", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var rewardItems = scriptData.GetGSDataList("rewardItems");
                    var createItems = scriptData.GetGSDataList("createItems");
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");
                    var rewardPlayerExp = scriptData.GetInt("rewardPlayerExp").Value;
                    var rewardSoftCurrency = scriptData.GetInt("rewardSoftCurrency").Value;
                    var rewardHardCurrency = scriptData.GetInt("rewardHardCurrency").Value;
                    var player = scriptData.GetGSData("player");

                    foreach (var entry in rewardItems)
                    {
                        result.rewardItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in createItems)
                    {
                        result.createItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                    result.rewardPlayerExp = rewardPlayerExp;
                    result.rewardSoftCurrency = rewardSoftCurrency;
                    result.rewardHardCurrency = rewardHardCurrency;
                    result.player = JsonUtility.FromJson<Player>(player.JSON);
                }
            }
            onFinish(result);
        });
    }

    protected override void DoConvertHardCurrency(string playerId, string loginToken, int requireHardCurrency, UnityAction<HardCurrencyConversionResult> onFinish)
    {
        var result = new HardCurrencyConversionResult();
        var data = new GSRequestData();
        data.AddNumber("requireHardCurrency", requireHardCurrency);
        var request = GetGSEventRequest("ConvertHardCurrency", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");
                    var receiveSoftCurrency = scriptData.GetInt("receiveSoftCurrency").Value;
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                    result.requireHardCurrency = requireHardCurrency;
                    result.receiveSoftCurrency = receiveSoftCurrency;
                }
            }
            onFinish(result);
        });
    }

    protected override void DoOpenInGamePackage(string playerId, string loginToken, string inGamePackageDataId, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        var data = new GSRequestData();
        data.AddString("inGamePackageDataId", inGamePackageDataId);
        var request = GetGSEventRequest("OpenInGamePackage", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null)
            {
                if (scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                {
                    result.error = scriptData.GetString("error");
                }
                else
                {
                    var rewardItems = scriptData.GetGSDataList("rewardItems");
                    var createItems = scriptData.GetGSDataList("createItems");
                    var updateItems = scriptData.GetGSDataList("updateItems");
                    var deleteItemIds = scriptData.GetStringList("deleteItemIds");
                    var updateCurrencies = scriptData.GetGSDataList("updateCurrencies");

                    foreach (var entry in rewardItems)
                    {
                        result.rewardItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in createItems)
                    {
                        result.createItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    foreach (var entry in updateItems)
                    {
                        result.updateItems.Add(JsonUtility.FromJson<PlayerItem>(entry.JSON));
                    }
                    result.deleteItemIds.AddRange(deleteItemIds);
                    foreach (var entry in updateCurrencies)
                    {
                        result.updateCurrencies.Add(JsonUtility.FromJson<PlayerCurrency>(entry.JSON));
                    }
                }
            }
            onFinish(result);
        });
    }

    protected override void DoCraftItem(string playerId, string loginToken, string itemCraftId, Dictionary<string, int> materials, UnityAction<ItemResult> onFinish)
    {
        var result = new ItemResult();
        result.error = GameServiceErrorCode.NOT_AVAILABLE;
        onFinish(result);
    }
}
<file_sep>﻿using GameSparks.Core;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public partial class GSGameService
{
    protected override void DoGetHelperList(string playerId, string loginToken, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        var request = GetGSEventRequest("GetHelperList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<Player>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetFriendList(string playerId, string loginToken, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        var request = GetGSEventRequest("GetFriendList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<Player>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetFriendRequestList(string playerId, string loginToken, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        var request = GetGSEventRequest("GetFriendRequestList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<Player>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoGetPendingRequestList(string playerId, string loginToken, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        var request = GetGSEventRequest("GetPendingRequestList");
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<Player>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoFindUser(string playerId, string loginToken, string displayName, UnityAction<PlayerListResult> onFinish)
    {
        var result = new PlayerListResult();
        var data = new GSRequestData();
        data.AddString("displayName", displayName);
        var request = GetGSEventRequest("FindUser", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("list"))
            {
                var list = scriptData.GetGSDataList("list");
                foreach (var entry in list)
                {
                    result.list.Add(JsonUtility.FromJson<Player>(entry.JSON));
                }
            }
            onFinish(result);
        });
    }

    protected override void DoFriendRequest(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        var data = new GSRequestData();
        data.AddString("targetPlayerId", targetPlayerId);
        var request = GetGSEventRequest("FriendRequest", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                result.error = scriptData.GetString("error");
            onFinish(result);
        });
    }

    protected override void DoFriendAccept(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        var data = new GSRequestData();
        data.AddString("targetPlayerId", targetPlayerId);
        var request = GetGSEventRequest("FriendAccept", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                result.error = scriptData.GetString("error");
            onFinish(result);
        });
    }

    protected override void DoFriendDecline(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        var data = new GSRequestData();
        data.AddString("targetPlayerId", targetPlayerId);
        var request = GetGSEventRequest("FriendDecline", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                result.error = scriptData.GetString("error");
            onFinish(result);
        });
    }

    protected override void DoFriendDelete(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        var data = new GSRequestData();
        data.AddString("targetPlayerId", targetPlayerId);
        var request = GetGSEventRequest("FriendDelete", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                result.error = scriptData.GetString("error");
            onFinish(result);
        });
    }

    protected override void DoFriendRequestDelete(string playerId, string loginToken, string targetPlayerId, UnityAction<GameServiceResult> onFinish)
    {
        var result = new GameServiceResult();
        var data = new GSRequestData();
        data.AddString("targetPlayerId", targetPlayerId);
        var request = GetGSEventRequest("FriendRequestDelete", data);
        request.Send((response) =>
        {
            GSData scriptData = response.ScriptData;
            if (scriptData != null && scriptData.ContainsKey("error") && !string.IsNullOrEmpty(scriptData.GetString("error")))
                result.error = scriptData.GetString("error");
            onFinish(result);
        });
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public partial class GSGameService
{
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using GameSparks.Core;
using GameSparks.Api.Requests;

public partial class GSGameService
{
    public void RequestAccountDetails(PlayerResult result, UnityAction<PlayerResult> onFinish)
    {
        var player = result.player;
        var request = new AccountDetailsRequest();
        request.Send((accountResponse) =>
        {
            if (!accountResponse.HasErrors)
            {
                player.Id = accountResponse.UserId;
                player.ProfileName = accountResponse.DisplayName;
                if (accountResponse.ScriptData != null)
                {
                    if (accountResponse.ScriptData.ContainsKey("exp"))
                        player.Exp = accountResponse.ScriptData.GetInt("exp").Value;
                    if (accountResponse.ScriptData.ContainsKey("selectedFormation"))
                        player.SelectedFormation = accountResponse.ScriptData.GetString("selectedFormation");
                    if (accountResponse.ScriptData.ContainsKey("selectedArenaFormation"))
                        player.SelectedArenaFormation = accountResponse.ScriptData.GetString("selectedArenaFormation");
                    if (accountResponse.ScriptData.ContainsKey("arenaScore"))
                        player.arenaScore = accountResponse.ScriptData.GetInt("arenaScore").Value;
                    if (accountResponse.ScriptData.ContainsKey("highestArenaRank"))
                        player.highestArenaRank = accountResponse.ScriptData.GetInt("highestArenaRank").Value;
                    if (accountResponse.ScriptData.ContainsKey("highestArenaRankCurrentSeason"))
                        player.highestArenaRankCurrentSeason = accountResponse.ScriptData.GetInt("highestArenaRankCurrentSeason").Value;
                }
                result.player = player;
                onFinish(result);
            }
            else
            {
                Debug.LogError("GameSparks error while request accout details: " + accountResponse.Errors.JSON);
                result.error = GameServiceErrorCode.UNKNOW;
                onFinish(result);
            }
        });
    }

    protected override void DoLogin(string username, string password, UnityAction<PlayerResult> onFinish)
    {
        var result = new PlayerResult();
        result.player = new Player();
        var request = new AuthenticationRequest();
        request.SetUserName(username);
        request.SetPassword(<PASSWORD>);
        request.Send((authResponse) =>
        {
            if (!authResponse.HasErrors)
                RequestAccountDetails(result, onFinish);
            else
            {
                Debug.LogError("GameSparks error while login: " + authResponse.Errors.JSON);
                result.error = GameServiceErrorCode.UNKNOW;
                if (authResponse.Errors.ContainsKey("DETAILS") && authResponse.Errors.GetString("DETAILS").Equals("UNRECOGNISED"))
                    result.error = GameServiceErrorCode.INVALID_USERNAME_OR_PASSWORD;
                onFinish(result);
            }
        });
    }

    protected override void DoRegisterOrLogin(string username, string password, UnityAction<PlayerResult> onFinish)
    {
        DoRegister(username, password, (registerResult) =>
        {
            if (registerResult.Success)
                DoLogin(username, password, onFinish);
            else
                onFinish(registerResult);
        });
    }

    protected override void DoGuestLogin(string deviceId, UnityAction<PlayerResult> onFinish)
    {
        var result = new PlayerResult();
        result.player = new Player();
        var request = new DeviceAuthenticationRequest();
        request.Send((authResponse) =>
        {
            if (!authResponse.HasErrors)
                RequestAccountDetails(result, onFinish);
            else
            {
                Debug.LogError("GameSparks error while guest login: " + authResponse.Errors.JSON);
                result.error = GameServiceErrorCode.UNKNOW;
                onFinish(result);
            }
        });
    }

    protected override void DoValidateLoginToken(string playerId, string loginToken, bool refreshToken, UnityAction<PlayerResult> onFinish)
    {
        var result = new PlayerResult();
        if (GS.Authenticated && !string.IsNullOrEmpty(playerId))
        {
            result.player = new Player();
            RequestAccountDetails(result, onFinish);
            return;
        }
        result.error = GameServiceErrorCode.INVALID_LOGIN_TOKEN;
        onFinish(result);
    }

    protected override void DoSetProfileName(string playerId, string loginToken, string profileName, UnityAction<PlayerResult> onFinish)
    {
        var result = new PlayerResult();
        var player = result.player = Player.CurrentPlayer;
        var request = new ChangeUserDetailsRequest();
        request.SetDisplayName(profileName);
        request.Send((authResponse) =>
        {
            player.ProfileName = profileName;

            if (!authResponse.HasErrors)
                onFinish(result);
            else
            {
                Debug.LogError("GameSparks error while set profile name: " + authResponse.Errors.JSON);
                result.error = GameServiceErrorCode.UNKNOW;
                onFinish(result);
            }
        });
    }

    protected override void DoRegister(string username, string password, UnityAction<PlayerResult> onFinish)
    {
        var result = new PlayerResult();
        var player = result.player = new Player();
        var request = new RegistrationRequest();
        request.SetDisplayName(" ");
        request.SetUserName(username);
        request.SetPassword(<PASSWORD>);
        request.Send((authResponse) =>
        {
            player.Id = authResponse.UserId;

            if (!authResponse.HasErrors)
                onFinish(result);
            else
            {
                Debug.LogError("GameSparks error while register: " + authResponse.Errors.JSON);
                result.error = GameServiceErrorCode.UNKNOW;
                if (authResponse.Errors.ContainsKey("USERNAME") && authResponse.Errors.GetString("USERNAME").Equals("TAKEN"))
                    result.error = GameServiceErrorCode.EXISTED_USERNAME;
                onFinish(result);
            }
        });
    }
}
