/// <summary> /// Method that requests packages and promotions from the server. /// This is called automatically by the Spil SDK when the game starts. /// This is not essential so could be removed but might be handy for some developers so we left it in. /// </summary> public override void RequestPackages() { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "requestPackages"; spilEvent.Send(); }
public override void UserPlayAsGuest() { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "userPlayAsGuest"; string newUid = Guid.NewGuid().ToString(); spilEvent.customData.AddField("newUid", newUid); spilEvent.Send(); Spil.SpilUserIdEditor = newUid; unauthorized = false; spilToken = null; JSONObject loginResponse = new JSONObject(); loginResponse.AddField("resetData", true); loginResponse.AddField("socialProvider", (string)null); loginResponse.AddField("socialId", (string)null); loginResponse.AddField("isGuest", true); SpilUnityImplementationBase.fireLoginSuccessful(loginResponse.Print()); }
/// <summary> /// Sends the "requestRewardVideo" event to the native Spil SDK which will send a request to the back-end. /// When a response has been received from the back-end the SDK will fire either an "AdAvailable" or and "AdNotAvailable" /// event to which the developer can subscribe and for instance call PlayVideo(); /// See http://www.spilgames.com/developers/integration/unity/implementing-spil-sdk/spil-sdk-event-tracking/ for more information on events. /// </summary> public override void RequestRewardVideo(string location = null, string rewardType = null) { int priv = Spil.Instance.GetPrivValue(); if (priv < 2 && priv > -1 && Spil.UseUnityPrefab) { fireAdAvailableEvent("rewardVideo"); return; } SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "requestRewardVideo"; if (location != null) { spilEvent.customData.AddField("location", location); } if (rewardType != null) { spilEvent.customData.AddField("rewardType", rewardType); } spilEvent.Send(); }
public static void SetPrivateGameState(String gameState) { UserDataManager.UpdateUserDataVersions(); UserDataManager.UpdateUserDataMeta(); SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "updateGameState"; if (gameState.Contains("\"")) { gameState = gameState.Replace("\"", "\\\"").Replace("\\\\", "\\"); } PrivateGameStateData = gameState; JSONObject gameStateJSONArray = new JSONObject(JSONObject.Type.ARRAY); JSONObject gameStateJSON = new JSONObject(); gameStateJSON.AddField("data", gameState); gameStateJSON.AddField("access", "private"); gameStateJSONArray.Add(gameStateJSON); spilEvent.customData.AddField("gameStates", gameStateJSONArray); spilEvent.customData.AddField("deviceVersions", UserDataManager.GenerateUserDataVersionsJSON(UserDataManager.userDataVersions)); spilEvent.Send(); }
public void ApplyItems(JSONObject items) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "liveEventApplyItems"; spilEvent.customData.AddField("liveEventId", liveEventOverview.liveEventId); if (items != null) { spilEvent.customData.AddField("items", items); for (int i = 0; i < items.Count; i++) { int id = (int)items.list[i].GetField("id").n; int amount = (int)items.list[i].GetField("amount").n; Spil.Instance.SubtractItemFromInventory(id, amount, PlayerDataUpdateReasons.LiveEvent, null); } } else { spilEvent.customData.AddField("items", ""); } spilEvent.Send(); }
internal void AdvertisementInit() { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "advertisementInit"; spilEvent.Send(); }
internal void RequestConfig() { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "requestConfig"; spilEvent.Send(); }
public static void ShowPromotionScreen(int promotionId) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "showPromotionScreen"; spilEvent.customData.AddField("id", promotionId); spilEvent.Send(); }
internal void RequestGameData() { gData = gData.InitialiseGameObjects(); Spil.GameData = new SpilGameDataHelper(this); SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "requestGameData"; spilEvent.Send(); }
public override void UserLogin(string socialId, string socialProvider, string socialToken) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "userLogin"; spilEvent.customData.AddField("socialId", socialId); spilEvent.customData.AddField("socialProvider", socialProvider); spilEvent.customData.AddField("socialToken", socialToken); spilEvent.Send(); }
public override void RequestSplashScreen(string type = null) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "requestSplashscreen"; if (type != null) { spilEvent.customData.AddField("type", type); } spilEvent.Send(); }
public void AdvanceToNextStage() { if (liveEventOverview.currentStage != null && liveEventOverview.alwaysShowStartStage) { OpenStageView(StageType.PROGRESS, liveEventOverview.currentStage); } else { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "liveEventNextStage"; spilEvent.customData.AddField("liveEventId", liveEventOverview.liveEventId); spilEvent.Send(); } }
public override void ClaimToken(string token, string rewardType) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "claimToken"; spilEvent.customData.AddField("token", Spil.RewardToken); Spil.RewardFeatureTypeEnum tokenType = Spil.MonoInstance.RewardFeatureType; if (tokenType.Equals(Spil.RewardFeatureTypeEnum.DEEPLINK)) { spilEvent.customData.AddField("rewardType", "deepLink"); } spilEvent.Send(); }
public override void RequestUserData() { pData.Wallet = pData.InitWallet(); pData.Inventory = pData.InitInventory(); Spil.PlayerData = new PlayerDataHelper(this); pData.SetInitalWalletValues(); pData.SetInitalInventoryValues(); SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "requestUserData"; JSONObject playerDataJSON = new JSONObject(); JSONObject walletJSON = new JSONObject(); walletJSON.AddField("offset", pData.Wallet.offset); playerDataJSON.AddField("wallet", walletJSON); JSONObject inventoryJSON = new JSONObject(); inventoryJSON.AddField("offset", pData.Inventory.offset); playerDataJSON.AddField("inventory", inventoryJSON); spilEvent.customData.AddField("playerData", playerDataJSON); JSONObject gameStateJSON = new JSONObject(); JSONObject gameStateArray = new JSONObject(JSONObject.Type.ARRAY); gameStateArray.Add("private"); if (Response.provider != null & Response.externalId != null) { gameStateArray.Add("public"); } gameStateJSON.AddField("access", gameStateArray); spilEvent.customData.AddField("gameState", gameStateJSON); spilEvent.customData.AddField("deviceVersions", UserDataManager.GenerateUserDataVersionsJSON(UserDataManager.userDataVersions)); spilEvent.Send(); }
public override void UserLogout(bool global) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "userLogout"; spilEvent.customData.AddField("newUid", Spil.SpilUserIdEditor); spilEvent.customData.AddField("global", global); spilEvent.Send(); if (!global) { SetUserId(null, null); Spil.SpilUserIdEditor = Guid.NewGuid().ToString(); spilToken = null; SpilUnityImplementationBase.fireLogoutSuccessful(); } }
/// <summary> /// Gets the public game state of other users. /// </summary> /// <param name="provider">Provider.</param> /// <param name="userIdsJsonArray">User identifiers json array.</param> public override void GetOtherUsersGameState(string provider, string userIdsJsonArray) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "requestOtherUsersGameState"; JSONObject users = new JSONObject(JSONObject.Type.ARRAY); List <String> userList = JsonHelper.getObjectFromJson <List <String> >(userIdsJsonArray); for (int i = 0; i < userList.Count; i++) { users.Add(userList[i]); } spilEvent.customData.AddField("provider", provider); spilEvent.customData.AddField("users", users); spilEvent.Send(); }
/// <summary> /// Sends an event to the native Spil SDK which will send a request to the back-end. /// Custom events may be tracked as follows: /// To track an simple custom event, simply call Spil.Instance.SendCustomEvent(String eventName); from anywhere in your code. /// To pass more information with the event create a <String, String> Dictionary and pass that as the second parameter like so: /// Dictionary<String, String> eventParams = new Dictionary<String,String>(); /// eventParams.Add(“level”,levelName); /// Spil.Instance.SendCustomEvent(“PlayerDeath”, eventParams); /// See https://github.com/spilgames/spil_event_unity_plugin for more information on events. /// This method was previously called "TrackEvent". /// </summary> /// <param name="eventName"></param> /// <param name="dict"></param> public override void SendCustomEvent(string eventName, Dictionary <string, object> dict) { SpilLogging.Log("SpilSDK-Unity SendCustomEvent " + eventName); SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = eventName; if (dict != null) { spilEvent.customData = JsonHelper.DictToJSONObject(dict); if (dict.ContainsKey("trackingOnly")) { spilEvent.customData.RemoveField("trackingOnly"); spilEvent.customData.AddField("trackingOnly", true); dict.Remove("trackingOnly"); } } spilEvent.Send(); }
public static void SendBoughtPromotion(int promotionId) { string promotionName = ""; foreach (SpilPromotionData promotionData in PromotionData) { if (promotionData.id == promotionId) { promotionName = promotionData.name; break; } } SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "boughtPromotion"; spilEvent.customData.AddField("id", promotionId); spilEvent.customData.AddField("name", promotionName); spilEvent.Send(); }
public static void SetPublicGameState(String gameState) { if (Response.externalId != null && Response.provider != null) { UserDataManager.UpdateUserDataVersions(); UserDataManager.UpdateUserDataMeta(); SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "updateGameState"; if (gameState.Contains("\"")) { gameState = gameState.Replace("\"", "\\\"").Replace("\\\\", "\\"); } PublicGameStateData = gameState; JSONObject gameStateJSONArray = new JSONObject(JSONObject.Type.ARRAY); JSONObject gameStateJSON = new JSONObject(); gameStateJSON.AddField("data", gameState); gameStateJSON.AddField("access", "public"); gameStateJSONArray.Add(gameStateJSON); spilEvent.customData.AddField("gameStates", gameStateJSONArray); spilEvent.customData.AddField("deviceVersions", UserDataManager.GenerateUserDataVersionsJSON(UserDataManager.userDataVersions)); spilEvent.Send(); } else { SpilErrorMessage error = new SpilErrorMessage(); error.id = 12; error.name = "UserIdMissing"; error.message = "Error adding public game state data! A custom user id must be set in order to save public game state data"; SpilUnityImplementationBase.fireUserDataError(JsonUtility.ToJson(error)); } }
public void SendUpdatePlayerDataEvent() { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "updatePlayerData"; JSONObject walletObject = new JSONObject(); walletObject.AddField("offset", Wallet.offset); spilEvent.customData.AddField("wallet", walletObject); JSONObject inventoryObject = new JSONObject(); inventoryObject.AddField("offset", Inventory.offset); spilEvent.customData.AddField("inventory", inventoryObject); spilEvent.customData.AddField("deviceVersions", UserDataManager.GenerateUserDataVersionsJSON(UserDataManager.userDataVersions)); spilEvent.Send(); }
public static void MergeUserData(string mergeData, string mergeType) { JSONObject mergeDataJSON = new JSONObject(mergeData); JSONObject mergePlayerData = mergeDataJSON.GetField("playerData"); JSONObject mergeGameStateJSON = mergeDataJSON.GetField("gameState"); JSONObject mergeWallet = mergePlayerData.GetField("wallet"); JSONObject mergeCurrencies = new JSONObject(JSONObject.Type.ARRAY); for (int i = 0; i < mergeWallet.GetField("currencies").Count; i++) { JSONObject currency = new JSONObject(); currency.AddField("id", mergeWallet.GetField("currencies")[i].GetField("id")); currency.AddField("name", mergeWallet.GetField("currencies")[i].GetField("name")); currency.AddField("type", mergeWallet.GetField("currencies")[i].GetField("type")); currency.AddField("currentBalance", mergeWallet.GetField("currencies")[i].GetField("currentBalance")); currency.AddField("delta", mergeWallet.GetField("currencies")[i].GetField("delta")); mergeCurrencies.Add(currency); } mergePlayerData.RemoveField("currencies"); mergePlayerData.AddField("currencies", mergeCurrencies); JSONObject mergeInventory = mergePlayerData.GetField("inventory"); JSONObject mergeItems = new JSONObject(JSONObject.Type.ARRAY); for (int i = 0; i < mergeInventory.GetField("items").Count; i++) { JSONObject item = new JSONObject(); item.AddField("id", mergeInventory.GetField("items")[i].GetField("id")); item.AddField("name", mergeInventory.GetField("items")[i].GetField("name")); item.AddField("type", mergeInventory.GetField("items")[i].GetField("type")); item.AddField("amount", mergeInventory.GetField("items")[i].GetField("amount")); item.AddField("delta", mergeInventory.GetField("items")[i].GetField("delta")); item.AddField("value", mergeInventory.GetField("items")[i].GetField("value")); mergeItems.Add(item); } mergePlayerData.RemoveField("items"); mergePlayerData.AddField("items", mergeItems); if (!mergeType.Equals("local")) { WalletData wallet = JsonHelper.getObjectFromJson <WalletData>(mergeDataJSON.GetField("playerData").GetField("wallet").Print()); InventoryData inventory = JsonHelper.getObjectFromJson <InventoryData>(mergeDataJSON.GetField("playerData").GetField("inventory").Print()); SpilUnityEditorImplementation.pData.Wallet = wallet; SpilUnityEditorImplementation.pData.Inventory = inventory; JSONObject gameStateData = mergeGameStateJSON.GetField("gameStates"); foreach (JSONObject gameState in gameStateData.list) { string access = null; if (gameState.HasField("access")) { access = gameState.GetField("access").str; } string data = null; if (gameState.HasField("data")) { data = gameState.GetField("data").str; } if (access == null || data == null) { continue; } if (access.Equals("private")) { GameStateManager.PrivateGameStateData = data; } else if (access.Equals("public")) { GameStateManager.PublicGameStateData = data; } } UpdateUserDataMeta(); } SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "mergeUserData"; spilEvent.customData.AddField("playerData", mergeDataJSON.GetField("playerData")); spilEvent.customData.AddField("gameState", mergeDataJSON.GetField("gameState")); JSONObject deviceVersionsJSON = new JSONObject(); deviceVersionsJSON.AddField("local", GenerateUserDataVersionsJSON(userDataVersions)); if (remoteUserDataVersions != null) { deviceVersionsJSON.AddField("remote", GenerateUserDataVersionsJSON(remoteUserDataVersions)); } else { deviceVersionsJSON.AddField("remote", GenerateUserDataVersionsJSON(new List <UserDataVersion>())); } spilEvent.customData.AddField("deviceVersions", deviceVersionsJSON); spilEvent.customData.AddField("mergeType", mergeType); spilEvent.Send(); }
public void SendUpdatePlayerDataEvent(bool resetWallet, bool resetInventory, string reason) { if (resetWallet) { foreach (PlayerCurrencyData currency in Wallet.currencies) { int newDelta = currency.initialValue - currency.currentBalance; currency.currentBalance = currency.initialValue; currency.delta = newDelta + currency.delta; UpdateCurrency(currency); } } if (resetInventory) { foreach (PlayerItemData item in Inventory.items) { int newDelta = item.initialValue - item.amount; item.amount = item.initialValue; item.delta = newDelta + item.delta; UpdateItem(item); } } SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "updatePlayerData"; JSONObject walletObject = new JSONObject(); JSONObject currenciesJSON = new JSONObject(JSONObject.Type.ARRAY); foreach (PlayerCurrencyData currencyData in Wallet.currencies) { JSONObject obj = new JSONObject(); obj.AddField("id", currencyData.id); obj.AddField("currentBalance", currencyData.currentBalance); obj.AddField("delta", currencyData.delta); currenciesJSON.Add(obj); } walletObject.AddField("currencies", currenciesJSON); walletObject.AddField("offset", Wallet.offset); spilEvent.customData.AddField("wallet", walletObject); JSONObject inventoryObject = new JSONObject(); JSONObject itemsJSON = new JSONObject(JSONObject.Type.ARRAY); foreach (PlayerItemData playerItemData in Inventory.items) { JSONObject obj = new JSONObject(); obj.AddField("id", playerItemData.id); obj.AddField("amount", playerItemData.amount); obj.AddField("delta", playerItemData.delta); itemsJSON.Add(obj); } inventoryObject.AddField("items", itemsJSON); inventoryObject.AddField("offset", Inventory.offset); spilEvent.customData.AddField("inventory", inventoryObject); spilEvent.customData.AddField("reason", reason); spilEvent.customData.AddField("deviceVersions", UserDataManager.GenerateUserDataVersionsJSON(UserDataManager.userDataVersions)); spilEvent.Send(); }
public void SendUpdatePlayerDataEvent(SpilBundleData bundle, string reason, string reasonDetails, string location, string transactionId) { SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>(); spilEvent.eventName = "updatePlayerData"; JSONObject walletObject = new JSONObject(); List <PlayerCurrencyData> currencyList = new List <PlayerCurrencyData>(); foreach (PlayerCurrencyData currencyData in Wallet.currencies) { if (currencyData.delta != 0) { currencyList.Add(currencyData); } } if (currencyList.Count > 0) { JSONObject currenciesJSON = new JSONObject(); foreach (PlayerCurrencyData currencyData in currencyList) { JSONObject obj = new JSONObject(); obj.AddField("id", currencyData.id); obj.AddField("currentBalance", currencyData.currentBalance); obj.AddField("delta", currencyData.delta); currenciesJSON.Add(obj); } walletObject.AddField("currencies", currenciesJSON); walletObject.AddField("offset", Wallet.offset); spilEvent.customData.AddField("wallet", walletObject); foreach (PlayerCurrencyData currencyData in Wallet.currencies) { currencyData.delta = 0; UpdateCurrency(currencyData); } } JSONObject inventoryObject = new JSONObject(); List <PlayerItemData> itemsList = new List <PlayerItemData>(); foreach (PlayerItemData playerItemData in Inventory.items) { if (playerItemData.delta != 0) { itemsList.Add(playerItemData); } } if (itemsList.Count > 0) { JSONObject itemsJSON = new JSONObject(JSONObject.Type.ARRAY); foreach (PlayerItemData playerItemData in itemsList) { JSONObject obj = new JSONObject(); obj.AddField("id", playerItemData.id); obj.AddField("amount", playerItemData.amount); obj.AddField("delta", playerItemData.delta); itemsJSON.Add(obj); } inventoryObject.AddField("items", itemsJSON); inventoryObject.AddField("offset", Inventory.offset); spilEvent.customData.AddField("inventory", inventoryObject); foreach (PlayerItemData playerItemData in Inventory.items) { playerItemData.delta = 0; UpdateItem(playerItemData); } } if (bundle != null) { spilEvent.customData.AddField("bundle", new JSONObject(JsonHelper.getJSONFromObject(bundle))); } spilEvent.customData.AddField("reason", reason); if (reasonDetails != null) { spilEvent.customData.AddField("reasonDetails", reasonDetails); } if (location != null) { spilEvent.customData.AddField("location", location); } if (transactionId != null) { spilEvent.customData.AddField("transactionId", transactionId); } spilEvent.customData.AddField("deviceVersions", UserDataManager.GenerateUserDataVersionsJSON(UserDataManager.userDataVersions)); spilEvent.Send(); }