public void UpdateScreen(LootLockerSessionResponse sessionResponse) { if (sessionResponse == null) { return; } username.text = LootLockerConfig.current.playerName; playerId.text = sessionResponse.player_id.ToString(); className.text = LootLockerConfig.current.playerClass; credits.text = sessionResponse.account_balance.ToString(); level.text = sessionResponse.level.ToString(); if (message != null) { message.text = ""; } LootLockerSDKManager.GetMessages((response) => { LoadingManager.HideLoadingScreen(); if (response.success) { if (message != null) { message.text = response.messages.Length > 0 ? response.messages.First().title : ""; } } else { Debug.LogError("failed to get all messages: " + response.Error); } }); }
public void Save() { if (string.IsNullOrEmpty(key.text) || string.IsNullOrEmpty(key.text)) { PopupSystem.ShowPopup("Please enter valid text for key and value", null, "Close", () => { }, url: keySucces, isError: true); return; } LoadingManager.ShowLoadingScreen(); LootLockerSDKManager.UpdateOrCreateKeyValue(key.text, value.text, (response) => { LoadingManager.HideLoadingScreen(); if (response.success) { Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("Key", key.text); data.Add("Value", value.text); DemoAppGetPersistentStoragResponse mainResponse = JsonConvert.DeserializeObject <DemoAppGetPersistentStoragResponse>(response.text); PopupSystem.ShowPopup("Save Successful", data, "Close", () => { StagesManager.instance.GoToStage(StagesManager.StageID.Storage, mainResponse); GetComponent <ScreenCloser>()?.Close(); PopupSystem.CloseNow(); }, url: keySucces); } }); }
public void ViewCollectables() { objects.Clear(); LootLockerSDKManager.GettingCollectables((response) => { LoadingManager.HideLoadingScreen(); AppDemoLootLockerRequests.GettingCollectablesResponse mainResponse = JsonConvert.DeserializeObject <AppDemoLootLockerRequests.GettingCollectablesResponse>(response.text); if (mainResponse.success) { Debug.Log("Successfuly got collectables: " + mainResponse.text); for (int i = scrollViewContent.childCount - 1; i >= 0; i--) { Destroy(scrollViewContent.GetChild(i).gameObject); } LootLockerCollectable[] collectables = response.collectables; for (int i = 0; i < collectables.Length; i++) { GameObject newCollectableObject = Instantiate(collectableRecordPrefab); objects.Add(newCollectableObject); newCollectableObject.GetComponent <ContextControllerCollectables>()?.Init(mainResponse.collectables[i].groups, mainResponse.collectables[i].name, imagesForCollectables); } StartCoroutine(DelayShowing()); } else { Debug.Log(response.Error); } }); }
public void StartSession() { Guid guid = Guid.NewGuid(); LoadingManager.ShowLoadingScreen(); //Starting a new session using the new id that has been created LootLockerSDKManager.StartSession(guid.ToString(), (response) => { if (response.success) { Debug.Log("Created Session for new player with id: " + guid.ToString()); LocalPlayer localPlayer = new LocalPlayer { playerName = newPlayerName.text, uniqueID = guid.ToString(), characterClass = null }; List <LocalPlayer> localPlayers = JsonConvert.DeserializeObject <List <LocalPlayer> >(PlayerPrefs.GetString(playerStorageKeyNameToUse)); localPlayers.Add(localPlayer); PlayerPrefs.SetString(playerStorageKeyNameToUse, JsonConvert.SerializeObject(localPlayers)); ListPlayers(); LoadingManager.HideLoadingScreen(); } else { Debug.LogError("Session failure: " + response.text); } }); }
public void SelectPlayer(LocalPlayer selectedPlayer) { if (isEasyPrefab) { Debug.LogError("You clicked on player " + selectedPlayer.playerName + " thats all we know :) "); return; } playersScreen.SetActive(false); createPlayerScreen.SetActive(false); LoadingManager.ShowLoadingScreen(); LootLockerConfig.current.deviceID = selectedPlayer.uniqueID; LootLockerSDKManager.StartSession(selectedPlayer.uniqueID, (response) => { if (response.success) { playersScreen.SetActive(true); Debug.Log("Logged in successfully."); LoadingManager.HideLoadingScreen(); LootLockerConfig.current.playerName = selectedPlayer.playerName; LootLockerConfig.current.playerClass = selectedPlayer.characterClass.type.ToString(); StagesManager.instance.GoToStage(StagesManager.StageID.Home, response); } else { playersScreen.SetActive(true); Debug.LogError("Log in failure."); LoadingManager.HideLoadingScreen(); } }); }
public void Delete() { if (string.IsNullOrEmpty(key.text) || string.IsNullOrEmpty(key.text)) { PopupSystem.ShowPopup("Please enter valid text for key and value", null, "Close", () => { }, url: keySucces, isError: true); return; } LoadingManager.ShowLoadingScreen(); LootLockerSDKManager.DeleteKeyValue(key.text, (response) => { LoadingManager.HideLoadingScreen(); if (response.success) { Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("Key", key.text); PopupSystem.ShowPopup("Deletion Successful", data, "Close", () => { StagesManager.instance.GoToStage(StagesManager.StageID.Storage, null); GetComponent <ScreenCloser>()?.Close(); PopupSystem.CloseNow(); }, url: keySucces); } }); }
void ListMessages() { LoadingManager.ShowLoadingScreen(); LootLockerSDKManager.GetMessages((response) => { LoadingManager.HideLoadingScreen(); if (response.success) { Debug.Log("Successful got all messages: " + response.text); for (int i = 0; i < messagesParent.childCount; i++) { Destroy(messagesParent.GetChild(i).gameObject); } foreach (LootLockerGMMessage message in response.messages) { GameObject messageObject = Instantiate(messagePrefab, messagesParent); messageObject.GetComponent <MessageElement>().InitMessage(message); messageObject.GetComponent <Button>().onClick.AddListener(() => SelectMessage(message)); } } else { Debug.LogError("failed to get all messages: " + response.Error); } }); }
public void ViewStore() { for (int i = 0; i < parent.childCount; i++) { Destroy(parent.GetChild(i).gameObject); } this.normalText.text = ""; this.normalText.text += "Price" + " : " + "" + "\n"; this.normalText.text += "Asset Name" + " : " + "" + "\n"; this.normalText.text += "Asset Context" + " : " + "" + "\n"; LootLockerSDKManager.GetEquipableContextToDefaultCharacter((contextResponse) => { LoadingManager.HideLoadingScreen(); if (contextResponse.success) { Debug.Log("Successful got context: " + contextResponse.text); UpdateBalanceDisplay(); LootLockerSDKManager.GetAssetListWithCount(50, (response) => { Debug.Log("Successful got Assets: " + response.text); LoadingManager.HideLoadingScreen(); InventoryAssetResponse.AssetResponse mainResponse = JsonConvert.DeserializeObject <InventoryAssetResponse.AssetResponse>(response.text); if (mainResponse.success) { string[] contexts = contextResponse.contexts.Select(x => x.name).ToArray(); InventoryAssetResponse.DemoAppAsset[] assets = mainResponse.assets?.Where(x => x.purchasable && x.price > 0)?.ToArray(); for (int i = 0; i < contexts.Length; i++) { GameObject contextObject = Instantiate(contextPrefab, parent); ContextController contextController = contextObject.GetComponent <ContextController>(); contextController.Init(contexts[i], assets.FirstOrDefault(x => x.context == contexts[i])?.id.ToString()); InventoryAssetResponse.DemoAppAsset[] assetsForContextController = assets.Where(x => x.context == contextController.context)?.ToArray(); contextController.Populate(assetsForContextController); } this.headerText.text = "Store"; selectText.text = "Buy"; this.normalText.text = ""; this.normalText.text += "Price" + " : " + "" + "\n"; this.normalText.text += "Asset Name" + " : " + "" + "\n"; this.normalText.text += "Asset Context" + " : " + "" + "\n"; } else { Debug.LogError("failed to get all inventory items: " + response.Error); } }); } else { Debug.LogError("Failed to get context: " + contextResponse.Error); } }); }
public void OnElementClicked() { string[] names = itemToCollect.Split('.'); Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("Collectable", names[0]); data.Add("Group Name", names[1]); data.Add("Item Name", names[2]); string header = ""; item.url = groupName + "_Active"; PopupSystem.ShowPopup("Collectable", data, "Collect", () => { LoadingManager.ShowLoadingScreen(); LootLockerSDKManager.CollectingAnItem(itemToCollect, (response) => { LoadingManager.HideLoadingScreen(); if (response.success) { Debug.Log("Success\n" + response.text); header = "Success"; data.Clear(); AppDemoLootLockerRequests.CollectingAnItemResponse mainResponse = JsonConvert.DeserializeObject <AppDemoLootLockerRequests.CollectingAnItemResponse>(response.text); string[] collectableStrings = itemToCollect.Split('.'); string collectable = collectableStrings[0]; string group = collectableStrings[1]; string tempItem = collectableStrings[2]; mainResponse.mainCollectable = mainResponse.collectables?.FirstOrDefault(x => x.name == collectable); mainResponse.mainGroup = mainResponse.mainCollectable?.groups?.FirstOrDefault(x => x.name == group); mainResponse.mainItem = mainResponse.mainGroup?.items?.FirstOrDefault(x => x.name == tempItem); //Preparing data to display or error messages we have data.Add("1", "You successfully collected: " + itemToCollect); PopupSystem.ShowApprovalFailPopUp(header, data, item.url, false, onComplete: () => { ShowRewards(mainResponse.mainItem, mainResponse.mainGroup, mainResponse.mainCollectable); }); UpdateButtonAppearance(mainResponse.mainItem); } else { header = "Collection Failed"; data.Clear(); //Preparing data to display or error messages we have data.Add("1", "Collection of item failed"); PopupSystem.ShowApprovalFailPopUp(header, data, item.url, true); Debug.Log("Failed\n" + response.text); } }); }, groupName + "_Active"); }
IEnumerator DelayShowing() { LoadingManager.ShowLoadingScreen(); yield return(new WaitForSeconds(1f)); for (int i = 0; i < objects.Count; i++) { objects[i].transform.SetParent(scrollViewContent); objects[i].transform.localScale = new Vector3(1, 1, 1); } LoadingManager.HideLoadingScreen(); }
public void DownloadFile(TypeOfFile typeOfFile) { switch (typeOfFile) { case TypeOfFile.Image: TempImageClass tempImageClass = new TempImageClass(); tempImageClass.url = url; tempImageClass.preview = image; tempImageClass.OnDownloadCompleted = () => { LoadingManager.HideLoadingScreen(); }; TexturesSaver.QueueForDownload(tempImageClass); break; } }
public void Refresh() { LoadingManager.ShowLoadingScreen(); foreach (Transform tr in content.transform) { Destroy(tr.gameObject); } LootLockerSDKManager.GetEntirePersistentStorage((response) => { LoadingManager.HideLoadingScreen(); UpdateScreen(response.payload); }); }
public void ButtonClicked() { if (currentAsset.asset != null) { if (currentAsset.asset.files != null && currentAsset.asset.files.Length > 0) { StagesManager.instance.GoToStage(StagesManager.StageID.Files, currentAsset.asset); return; } } string header = "Equip"; string btnText = "Equip"; Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("Asset Name", currentAsset.asset.name); data.Add("Asset Context", currentAsset.asset.context); PopupSystem.ShowPopup(header, data, btnText, () => { LoadingManager.ShowLoadingScreen(); LootLockerSDKManager.EquipIdAssetToDefaultCharacter(currentAsset.inventory.instance_id.ToString(), (response) => { LoadingManager.HideLoadingScreen(); if (response.success) { header = "Success"; data.Clear(); //Preparing data to display or error messages we have data.Add("1", "You successfully equipped: " + currentAsset.inventory.asset.name); LoadingManager.ShowLoadingScreen(); StagesManager.instance.GoToStage(StagesManager.StageID.Inventory, null); PopupSystem.ShowApprovalFailPopUp(header, data, currentAsset.asset.url, false); } else { Debug.LogError(response.Error); header = "Failed"; data.Clear(); //Preparing data to display or error messages we have string correctedResponse = response.Error.First() == '{' ? response.Error : response.Error.Substring(response.Error.IndexOf('{')); ResponseError equipErrorResponse = new ResponseError(); equipErrorResponse = JsonConvert.DeserializeObject <ResponseError>(correctedResponse); data.Add("1", equipErrorResponse.messages[0]); PopupSystem.ShowApprovalFailPopUp(header, data, currentAsset.asset.url, true); } }); }, currentAsset.asset.url); }
public void UpdateScreenData(ILootLockerStageData stageData) { LootLockerGetPersistentStoragResponse response = stageData as LootLockerGetPersistentStoragResponse; if (response != null) { UpdateScreen(response.payload); LoadingManager.HideLoadingScreen(); } else { Refresh(); } }
public void ButtonClicked() { string header = "Buy Item"; string btnText = "Buy"; Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("Asset Name", currentAsset.name); data.Add("Asset Context", currentAsset.context); data.Add("Cost", currentAsset.price.ToString()); PopupSystem.ShowPopup(header, data, btnText, () => { LoadingManager.ShowLoadingScreen(); LootLockerSDKManager.NormalPurchaseCall(currentAsset.id, currentAsset.variations.First().id, (response) => { LoadingManager.HideLoadingScreen(); if (response.success) { Debug.Log(response.text); UpdateBalanceDisplay(); header = "Success"; data.Clear(); //Preparing data to display or error messages we have data.Add("1", "You successfully bought: " + currentAsset.name); PopupSystem.ShowApprovalFailPopUp(header, data, currentAsset.url, false); } else { Debug.Log(response.Error); //making object from error json string correctedResponse = response.Error.First() == '{' ? response.Error : response.Error.Substring(response.Error.IndexOf('{')); ResponseError purchaseErrorResponse = new ResponseError(); purchaseErrorResponse = JsonConvert.DeserializeObject <ResponseError>(correctedResponse); header = "Purchase Failed"; data.Clear(); //Preparing data to display or error messages we have data.Add("1", purchaseErrorResponse.messages[0]); PopupSystem.ShowApprovalFailPopUp(header, data, currentAsset.url, true); } }); }, currentAsset.url); }
public async Task <bool> DownloadImage(string MediaUrl, Image targetImage) { targetImage.sprite = null; try { Texture2D downloadedTexture = await GetRemoteTexture(MediaUrl, targetImage); targetImage.sprite = Sprite.Create(downloadedTexture, new Rect(0, 0, downloadedTexture.width, downloadedTexture.height), Vector2.zero); LoadingManager.HideLoadingScreen(); return(true); } catch (Exception ex) { Debug.LogError("Couldn't download image. " + ex); LoadingManager.HideLoadingScreen(); return(false); } }
public void UpdateScreenData(ILootLockerStageData stageData) { LoadingManager.ShowLoadingScreen(); LootLockerGMMessage selectedMessage = stageData as LootLockerGMMessage; if (!string.IsNullOrEmpty(selectedMessage.image)) { messageImage.gameObject.SetActive(true); _ = DownloadImage(selectedMessage.image, messageImage); } else { messageImage.gameObject.SetActive(false); LoadingManager.HideLoadingScreen(); } messageSummary.text = selectedMessage.summary ?? ""; messageBody.text = selectedMessage.body ?? ""; messageTitle.text = selectedMessage.title ?? ""; }
public void ListAllCharacterClasses() { //Loadouts are the default items that are associated with each character class. This is why we can use this to list all character classes and then display to user LootLockerSDKManager.GetCharacterLoadout((response) => { if (response.success) { foreach (LootLockerLootLockerLoadout loadout in response.loadouts) { GameObject selectionButton = Instantiate(characterClassPrefab, parent); selectionButton.GetComponent <ClassSelectionButton>()?.Init(loadout); } } else { } LoadingManager.HideLoadingScreen(); }); }
public void UpdateDefaultCharacterClass(Action onCompletedUpdate) { ////now that we have a new player created, we need to set the default character of this player to the one that was selected LootLockerSDKManager.UpdateCharacter(loadout.character.id.ToString(), LootLockerConfig.current.playerName, true, (updateResponse) => { if (updateResponse.success) { LootLockerConfig.current.playerClass = loadout.character.type; Debug.Log("Updated character info successfully: " + updateResponse.text); onCompletedUpdate?.Invoke(); LoadingManager.HideLoadingScreen(); } else { failResponse?.Invoke(); Debug.LogError("Failed to update character info: " + updateResponse.text); LoadingManager.HideLoadingScreen(); } }); }
public void StartSession(Action OnCompletedSessionStart) { guid = Guid.NewGuid(); LoadingManager.ShowLoadingScreen(); //Starting a new session using the new id that has been created LootLockerSDKManager.StartSession(guid.ToString(), (response) => { if (response.success) { sessionResponse = response; Debug.Log("Session success: " + response.text); OnCompletedSessionStart?.Invoke(); } else { failResponse?.Invoke(); Debug.LogError("Session failure: " + response.text); LoadingManager.HideLoadingScreen(); } }); }
public void Close() { LoadingManager.HideLoadingScreen(); PopupSystem.CloseNow(); }
private void SelectPlayer(Grant grant, List <LootLockerRewardObject> rewardObjects = null) { string header = ""; string normalTextMessage = ""; Dictionary <string, string> data = new Dictionary <string, string>(); string icon = grant == Grant.Credits ? creditsSprite : xpSprite; LootLockerSDKManager.StartSession(LootLockerConfig.current.deviceID, (response) => { LoadingManager.HideLoadingScreen(); if (response.success) { header = "Success"; if (grant == Grant.Credits) { normalTextMessage = "Successfully granted Credits."; } if (grant == Grant.XP) { normalTextMessage = "Successfully granted XP."; } data.Clear(); //Preparing data to display or error messages we have data.Add("1", normalTextMessage); StagesManager.instance.GoToStage(StagesManager.StageID.Home, response); if (rewardObjects != null && rewardObjects.Count > 0) { for (int i = 0; i < rewardObjects.Count; i++) { PopupData PopupData = new PopupData(); PopupData.buttonText = "Ok"; PopupData.url = rewardObjects[i].asset.links.thumbnail; PopupData.withKey = true; PopupData.normalText = new Dictionary <string, string>() { { "Reward", rewardObjects[i].asset.name } }; PopupData.header = "You got a reward"; PopupSystem.ShowScheduledPopup(PopupData); } } } else { header = "Failed"; string correctedResponse = response.Error.First() == '{' ? response.Error : response.Error.Substring(response.Error.IndexOf('{')); ResponseError errorMessage = new ResponseError(); errorMessage = JsonConvert.DeserializeObject <ResponseError>(correctedResponse); normalTextMessage = errorMessage.messages[0]; data.Clear(); //Preparing data to display or error messages we have data.Add("1", normalTextMessage); } PopupSystem.ShowApprovalFailPopUp(header, data, icon); }); }
public void UpdateScreenData(ILootLockerStageData stageData) { if (stageData != null) { createPlayerRequest = stageData as CreatePlayerRequest; LootLockerConfig.current.playerName = createPlayerRequest.playerName; LoadingManager.ShowLoadingScreen(); failResponse = () => { StagesManager.instance.GoToStage(StagesManager.StageID.Player, null); }; //Starting session first before character is chosen StartSession(() => { foreach (Transform tr in parent) { Destroy(tr.gameObject); } LootLockerSDKManager.GetCharacterLoadout((response) => { if (response.success) { foreach (LootLockerLootLockerLoadout loadout in response.loadouts) { GameObject selectionButton = Instantiate(characterClassPrefab, parent); selectionButton.GetComponent <ClassSelectionButton>()?.Init(loadout); } } else { StagesManager.instance.GoToStage(StagesManager.StageID.CreatePlayer, null); } LoadingManager.HideLoadingScreen(); }); }); //if we are creating a new character then we want to set character details once it is created button.onClick.RemoveAllListeners(); button.onClick.AddListener(() => { UpdateDefaultCharacterClass(() => { if (!isEasyPrefab) { LocalPlayer localPlayer = new LocalPlayer { playerName = createPlayerRequest.playerName, uniqueID = guid.ToString(), characterClass = loadout?.character }; List <LocalPlayer> localPlayers = JsonConvert.DeserializeObject <List <LocalPlayer> >(PlayerPrefs.GetString("localplayers")); localPlayers.Add(localPlayer); PlayerPrefs.SetString("localplayers", JsonConvert.SerializeObject(localPlayers)); LootLockerConfig.current.deviceID = localPlayer.uniqueID; LootLockerConfig.current.playerClass = loadout.character.type.ToString(); //Character has been set, we can now load the home page StagesManager.instance.GoToStage(StagesManager.StageID.Home, sessionResponse); } else { Debug.Log("Updated the default class for the current player"); } }); }); } else { failResponse = () => { StagesManager.instance.GoToStage(StagesManager.StageID.Settings, null); }; foreach (Transform tr in parent) { Destroy(tr.gameObject); } LootLockerSDKManager.GetCharacterLoadout((response) => { if (response.success) { foreach (LootLockerLootLockerLoadout loadout in response.loadouts) { GameObject selectionButton = Instantiate(characterClassPrefab, parent); selectionButton.GetComponent <ClassSelectionButton>()?.Init(loadout); } } else { StagesManager.instance.GoToStage(StagesManager.StageID.Settings, null); } LoadingManager.HideLoadingScreen(); }); //if we are just updating the character class for player, then after it is completed. We want to return to the inventory screen button.onClick.RemoveAllListeners(); button.onClick.AddListener(() => { UpdateDefaultCharacterClass(() => { //Character has been set, we can now load inventory StagesManager.instance.GoToStage(StagesManager.StageID.Settings, null); }); }); } }
public void ViewInventory() { this.normalText.text = ""; this.normalText.text += "Asset Name" + " : " + "" + "\n"; this.normalText.text += "Asset Context" + " : " + "" + "\n"; LootLockerSDKManager.GetCurrentLoadOutToDefaultCharacter((response) => { if (response.success) { foreach (Transform tr in inventoryParent) { Destroy(tr.gameObject); } contextControllers.Clear(); LootLockerSDKManager.GetEquipableContextToDefaultCharacter((contextResponse) => { if (contextResponse.success) { string[] contexts = contextResponse.contexts.Select(x => x.name).ToArray(); LootLockerCommonAsset[] assets = response.GetAssets(); for (int i = 0; i < contexts.Length; i++) { GameObject contextObject = Instantiate(contextsPrefab, inventoryParent); ContextController contextController = contextObject.GetComponent <ContextController>(); contextController.Init(contexts[i], assets.FirstOrDefault(x => x.context == contexts[i])?.id.ToString()); contextControllers.Add(contextController); } this.headerText.text = "Inventory"; selectText.text = "Equip"; this.normalText.text = ""; this.normalText.text += "Asset Name" + " : " + "" + "\n"; this.normalText.text += "Asset Context" + " : " + "" + "\n"; LootLockerSDKManager.GetInventory((res) => { LoadingManager.HideLoadingScreen(); if (res.success) { InventoryAssetResponse.InventoryResponse mainResponse = JsonConvert.DeserializeObject <InventoryAssetResponse.InventoryResponse>(res.text); Debug.Log("Successful got inventory: " + res.text); for (int j = 0; j < contextControllers.Count; j++) { InventoryAssetResponse.Inventory[] inventories = mainResponse.inventory.Where(x => x.asset?.context == contextControllers[j].context)?.ToArray(); Dictionary <int, int> numberOfInventories = new Dictionary <int, int>();//It will contain amount of each inventory we have for (int i = 0; i < inventories.Length; i++) { if (numberOfInventories.ContainsKey(inventories[i].asset.id))//Increase amount of inventory if we already have it in our dictionary { numberOfInventories[inventories[i].asset.id]++; } else { numberOfInventories.Add(inventories[i].asset.id, 1); } } inventories = inventories.GroupBy(x => x.asset.id).Select(x => x.First()).ToArray();//Grouping inventories, so we won't have duplicates contextControllers[j].Populate(inventories, numberOfInventories); } } else { Debug.LogError("failed to get all inventory items: " + res.Error); } }); } else { Debug.LogError("failed to get all inventory items: " + contextResponse.Error); } }); } }); }