void UploadCallback(WorkshopItemUpdateEventArgs args, WorkshopItemUpdate uploadItem) { uploading = false; currentUploadItem = null; saveUI.feedbackTextSecondary.gameObject.SetActive(true); saveUI.feedbackTextPrimary.gameObject.SetActive(false); if (args.IsError) { if (args.ErrorMessage == "File was not found!") { saveUI.feedbackTextSecondary.SetText($"No workshop file found - attempting new upload..."); saveUI.feedbackTextSecondaryButton.onClick.RemoveAllListeners(); UploadActiveSaveToWorkshop(true /* forcing new upload */); } } else { string url = $"https://steamcommunity.com/sharedfiles/filedetails/?id={uploadItem.SteamNative.m_nPublishedFileId.ToString()}"; saveUI.feedbackTextSecondary.SetText($"Workshop URL (must be logged in):\n{url}"); saveUI.feedbackTextSecondaryButton.onClick.AddListener(() => Application.OpenURL(url)); fileOnSteamWorkshop = true; PerformWorkshopVisibilityCheck(uploadItem.SteamNative.m_nPublishedFileId.m_PublishedFileId); } }
private void OnOwnedItemSelectedForUpdate(WorkshopItem p_item) { uMyGUI_PopupManager.Instance.HidePopup(uMyGUI_PopupManager.POPUP_DROPDOWN); // only installed items can be updated if (!p_item.IsInstalled) { ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Not Installed", "This item is not installed. Please subscribe this item first!") .ShowButton(uMyGUI_PopupManager.BTN_OK, Start); // retry on OK button return; } // generate a WorkshopItemUpdate instance WorkshopItemUpdate updateExistingItem = new WorkshopItemUpdate(p_item); string itemContentFile = Path.Combine(updateExistingItem.ContentPath, "ItemData.txt"); if (File.Exists(itemContentFile)) { // update the content of your item File.AppendAllText(itemContentFile, "\nUpdate - " + System.DateTime.Now); // show the Steam Workshop item upload popup ((SteamWorkshopPopupUpload)uMyGUI_PopupManager.Instance.ShowPopup("steam_ugc_upload")).UploadUI.SetItemData(updateExistingItem); } else { ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Not Installed", "This item is subscribed, but not installed. Please sync local files in Steam!") .ShowButton(uMyGUI_PopupManager.BTN_OK, Start); // retry on OK button } }
void UploadActiveSaveToWorkshop(bool newUpload = false) { var bundleId = GetActiveBundleId(); Debug.Assert(bundleId != null); uploaddesired = false; uploading = true; string contentPath = gameBundleLibrary.GetBundleDirectory(bundleId); WorkshopItemUpdate uploadItem = null; if (File.Exists(Path.Combine(contentPath, SteamUtil.WorkshopItemInfoFileName))) { uploadItem = SteamWorkshopMain.Instance.GetItemUpdateFromFolder(contentPath); } if (uploadItem == null || newUpload) { uploadItem = new WorkshopItemUpdate(); } GameBundle.Metadata metadata = GetMetadataFromUI(); uploadItem.Name = metadata.name; uploadItem.Description = metadata.description; uploadItem.ContentPath = contentPath; if (gameBundleLibrary.GetBundle(bundleId).GetThumbnail() != null) { uploadItem.IconPath = gameBundleLibrary.GetBundle(bundleId).GetThumbnailPath(); } uploadItem.Tags.Add(SteamUtil.GameBuilderTags.Project.ToString()); SteamWorkshopMain.Instance.Upload(uploadItem, (args) => UploadCallback(args, uploadItem)); currentUploadItem = uploadItem; }
private void Start() { // enable debug log SteamWorkshopMain.Instance.IsDebugLogEnabled = true; // everything inside this folder will be uploaded with your item string dummyItemContentFolder = Path.Combine(Application.persistentDataPath, "DummyItemContentFolder" + System.DateTime.Now.Ticks); // use DateTime.Now.Ticks to create a unique folder for each upload if (!Directory.Exists(dummyItemContentFolder)) { Directory.CreateDirectory(dummyItemContentFolder); } // create dummy content to upload string dummyItemContentStr = "Save your item/level/mod data here.\n" + "It does not need to be a text file. Any file type is supported (binary, images, etc...).\n" + "You can save multiple files, Steam items are folders (not single files).\n"; File.WriteAllText(Path.Combine(dummyItemContentFolder, "ItemData.txt"), dummyItemContentStr); // tell which folder you want to upload WorkshopItemUpdate createNewItemUsingGivenFolder = new WorkshopItemUpdate(); createNewItemUsingGivenFolder.ContentPath = dummyItemContentFolder; // show the Steam Workshop item upload popup ((SteamWorkshopPopupUpload)uMyGUI_PopupManager.Instance.ShowPopup("steam_ugc_upload")).UploadUI.SetItemData(createNewItemUsingGivenFolder); }
/// <summary> /// Call SetItemData to refresh the item UI. /// </summary> /// <param name="p_itemData">item update data to be visualized.</param> public virtual void SetItemData(WorkshopItemUpdate p_itemData) { // make sure that m_itemData is not null (if p_itemData is null, then create an empty data object) m_itemData = p_itemData != null ? p_itemData : new WorkshopItemUpdate(); // make sure that name and description are not null if (m_itemData.Name == null) { m_itemData.Name = ""; } if (m_itemData.Description == null) { m_itemData.Description = ""; } // update name and description in UI if (NAME_INPUT != null) { NAME_INPUT.text = m_itemData.Name; } else { Debug.LogError("SteamWorkshopUIUpload: SetItemData: NAME_INPUT is not set in inspector!"); } if (DESCRIPTION_INPUT != null) { if (!string.IsNullOrEmpty(m_itemData.Description)) { // A Unity bug going through various Unity versions does not allow to set the text of a multiline InputField directly after creation -> Coroutine StartCoroutine(SetDescriptionSafe(m_itemData.Description)); } else { DESCRIPTION_INPUT.text = ""; } } else { Debug.LogError("SteamWorkshopUIUpload: SetItemData: DESCRIPTION_INPUT is not set in inspector!"); } if (ICON != null) { if (!string.IsNullOrEmpty(m_itemData.IconPath)) { StartCoroutine(LoadIcon(m_itemData.IconPath)); } else { ICON.texture = null; } } else { Debug.LogError("SteamWorkshopUIUpload: SetItemData: ICON is not set in inspector!"); } }
private void Start() { // enable debug log SteamWorkshopMain.Instance.IsDebugLogEnabled = true; // check if this scene contains a SteamWorkshopUIUpload instance if (SteamWorkshopUIUpload.Instance == null) { string errorMessage = "SteamWorkshopUpdateItemFromFolderExampleStatic: you have no SteamWorkshopUIUpload in this scene! Please drag an drop the 'SteamWorkshopItemUpload' prefab from 'LapinerTools/Steam/Workshop' into your Canvas object!"; Debug.LogError(errorMessage); ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Error", errorMessage); return; } // get items which were uploaded before from disk, this will allow us to select an item for the update List <WorkshopItemUpdate> itemsAvailableForUpdate = new List <WorkshopItemUpdate>(); string uploadRootFolderPath = Application.persistentDataPath; foreach (string itemFolderPath in System.IO.Directory.GetDirectories(uploadRootFolderPath)) { WorkshopItemUpdate itemUpdate = SteamWorkshopMain.Instance.GetItemUpdateFromFolder(itemFolderPath); if (itemUpdate != null) { itemsAvailableForUpdate.Add(itemUpdate); } } if (itemsAvailableForUpdate.Count > 0) { // generate a list of item names string[] dropdownEntries = new string[itemsAvailableForUpdate.Count]; for (int i = 0; i < dropdownEntries.Length; i++) { dropdownEntries[i] = itemsAvailableForUpdate[i].Name; } // select the item, which you want to update ((uMyGUI_PopupDropdown)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_DROPDOWN)) .SetEntries(dropdownEntries) .SetOnSelected((int p_selectedIndex) => OnExistingItemSelectedForUpdate(itemsAvailableForUpdate[p_selectedIndex])) .SetText("Select Item", "Select the item, which you want to update"); } else { ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("No Items Found", "Cannot find any items to update, it seems that you haven't uploaded any items yet.") .ShowButton(uMyGUI_PopupManager.BTN_OK); } }
IEnumerator PutRoutine( string contentPath, string name, string description, SteamUtil.GameBuilderTags typeTag, string thumbnailPath, PublishedFileId_t?fileIdToUpdate, System.Action <Util.Maybe <ulong> > onComplete, System.Action <GetUploadProgress> onStatus = null) { yield return(null); if (!SteamManager.Initialized) { onComplete(Util.Maybe <ulong> .CreateError("Steam Workshop not available. Are you logged in? Maybe it's down?")); yield break; } WorkshopItemUpdate updateInfo = null; // NOTE: If we want to update the item, we can just remember the old file ID. Not sure how best to do this...we'd have to remember who the item belongs to..? // if (File.Exists(Path.Combine(contentPath, SteamUtil.WorkshopItemInfoFileName))) // { // uploadItem = SteamWorkshopMain.Instance.GetItemUpdateFromFolder(contentPath); // } updateInfo = new WorkshopItemUpdate(); updateInfo.Name = name; updateInfo.Description = description; updateInfo.ContentPath = contentPath; updateInfo.IconPath = thumbnailPath; updateInfo.Tags.Add(SteamUtil.GameBuilderTags.Asset.ToString()); updateInfo.Tags.Add(typeTag.ToString()); if (fileIdToUpdate != null) { updateInfo.SteamNative.m_nPublishedFileId = fileIdToUpdate.Value; } if (updateInfo.IconPath == null && typeTag == SteamUtil.GameBuilderTags.CardPack) { updateInfo.IconPath = Path.Combine( Util.GetConcretePath(Util.AbstractLocation.StreamingAssets), CARD_PACK_ICON_PATH); } // uploadItem.IconPath // TODO SteamWorkshopMain.Instance.Upload(updateInfo, (args) => UploadCallback(args, onComplete)); onStatus?.Invoke(() => { return(SteamWorkshopMain.Instance.GetUploadProgress(updateInfo)); }); }
private void OnExistingItemSelectedForUpdate(WorkshopItemUpdate p_updateExistingItem) { uMyGUI_PopupManager.Instance.HidePopup(uMyGUI_PopupManager.POPUP_DROPDOWN); string itemContentFile = Path.Combine(p_updateExistingItem.ContentPath, "ItemData.txt"); if (File.Exists(itemContentFile)) { // update the content of your item File.AppendAllText(itemContentFile, "\nUpdate - " + System.DateTime.Now); // show the Steam Workshop item upload popup ((SteamWorkshopPopupUpload)uMyGUI_PopupManager.Instance.ShowPopup("steam_ugc_upload")).UploadUI.SetItemData(p_updateExistingItem); } else { ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Content File Is Missing", "Have you changed this item's data?!") .ShowButton(uMyGUI_PopupManager.BTN_OK); } }
private void Start() { // enable debug log SteamWorkshopMain.Instance.IsDebugLogEnabled = true; // get items which were uploaded before from disk, this will allow us to select an item for the update List <WorkshopItemUpdate> itemsAvailableForUpdate = new List <WorkshopItemUpdate>(); string uploadRootFolderPath = Application.persistentDataPath; foreach (string itemFolderPath in System.IO.Directory.GetDirectories(uploadRootFolderPath)) { WorkshopItemUpdate itemUpdate = SteamWorkshopMain.Instance.GetItemUpdateFromFolder(itemFolderPath); if (itemUpdate != null) { itemsAvailableForUpdate.Add(itemUpdate); } } if (itemsAvailableForUpdate.Count > 0) { // generate a list of item names string[] dropdownEntries = new string[itemsAvailableForUpdate.Count]; for (int i = 0; i < dropdownEntries.Length; i++) { dropdownEntries[i] = itemsAvailableForUpdate[i].Name; } // select the item, which you want to update ((uMyGUI_PopupDropdown)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_DROPDOWN)) .SetEntries(dropdownEntries) .SetOnSelected((int p_selectedIndex) => OnExistingItemSelectedForUpdate(itemsAvailableForUpdate[p_selectedIndex])) .SetText("Select Item", "Select the item, which you want to update"); } else { ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("No Items Found", "Cannot find any items to update, it seems that you haven't uploaded any items yet.") .ShowButton(uMyGUI_PopupManager.BTN_OK); } }
private void Start() { // enable debug log SteamWorkshopMain.Instance.IsDebugLogEnabled = true; // check if this scene contains a SteamWorkshopUIUpload instance if (SteamWorkshopUIUpload.Instance == null) { string errorMessage = "SteamWorkshopUploadNewItemExampleStatic: you have no SteamWorkshopUIUpload in this scene! Please drag an drop the 'SteamWorkshopItemUpload' prefab from 'LapinerTools/Steam/Workshop' into your Canvas object!"; Debug.LogError(errorMessage); ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Error", errorMessage); return; } // everything inside this folder will be uploaded with your item string dummyItemContentFolder = Path.Combine(Application.persistentDataPath, "DummyItemContentFolder" + System.DateTime.Now.Ticks); // use DateTime.Now.Ticks to create a unique folder for each upload if (!Directory.Exists(dummyItemContentFolder)) { Directory.CreateDirectory(dummyItemContentFolder); } // create dummy content to upload string dummyItemContentStr = "Save your item/level/mod data here.\n" + "It does not need to be a text file. Any file type is supported (binary, images, etc...).\n" + "You can save multiple files, Steam items are folders (not single files).\n"; File.WriteAllText(Path.Combine(dummyItemContentFolder, "ItemData.txt"), dummyItemContentStr); // tell which folder you want to upload WorkshopItemUpdate createNewItemUsingGivenFolder = new WorkshopItemUpdate(); createNewItemUsingGivenFolder.ContentPath = dummyItemContentFolder; // set upload data in Steam Workshop item upload UI SteamWorkshopUIUpload.Instance.SetItemData(createNewItemUsingGivenFolder); }
public void Open() { if (IsOpen()) { return; } UpdateSaveButtonTextAndVisibility(); saveUI.feedbackTextPrimary.gameObject.SetActive(false); saveUI.feedbackTextSecondary.gameObject.SetActive(false); gameObject.SetActive(true); Update(); string existingBundleId = GetActiveBundleId(); if (existingBundleId != null) { GameBundle bundle = gameBundleLibrary.GetBundle(existingBundleId); saveUI.nameInput.text = bundle.GetMetadata().name; saveUI.descriptionInput.text = bundle.GetMetadata().description; currentSaveImage = bundle.GetThumbnail(); #if USE_STEAMWORKS WorkshopItemUpdate uploadItem = null; //see if the xml file is there if (File.Exists(Path.Combine(gameBundleLibrary.GetBundleDirectory(existingBundleId), SteamUtil.WorkshopItemInfoFileName))) { uploadItem = SteamWorkshopMain.Instance.GetItemUpdateFromFolder(gameBundleLibrary.GetBundleDirectory(existingBundleId)); } if (uploadItem != null) { string url = $"https://steamcommunity.com/sharedfiles/filedetails/?id={uploadItem.SteamNative.m_nPublishedFileId.ToString()}"; saveUI.feedbackTextSecondary.SetText($"Workshop URL (must be logged in):\n{url}"); saveUI.feedbackTextSecondaryButton.onClick.AddListener(() => Application.OpenURL(url)); saveUI.feedbackTextSecondary.gameObject.SetActive(true); fileOnSteamWorkshop = true; } else #endif { saveUI.feedbackTextSecondary.gameObject.SetActive(false); fileOnSteamWorkshop = false; } } else if (GameBuilderApplication.IsRecoveryMode) { saveUI.feedbackTextPrimary.gameObject.SetActive(true); saveUI.feedbackTextPrimary.text = "Recovering will create a new save, and you can continue building normally from it. Your old project will still exist in your game library in case you need to go back to it."; saveUI.feedbackTextPrimaryButton.onClick.RemoveAllListeners(); // Fill in these fields for convenience string autosaveBundleId = GameBuilderApplication.CurrentGameOptions.bundleIdToLoad; GameBundle bundle = gameBundleLibrary.GetBundle(autosaveBundleId); saveUI.nameInput.text = bundle.GetMetadata().name; saveUI.descriptionInput.text = bundle.GetMetadata().description; currentSaveImage = bundle.GetThumbnail(); } if (currentSaveImage != null) { saveUI.screenshotImage.gameObject.SetActive(true); saveUI.screenshotImage.sprite = Sprite.Create(currentSaveImage, new Rect(0, 0, currentSaveImage.width, currentSaveImage.height), new Vector2(.5f, .5f), 100); } }
public void SaveLevelToFile() { if (!SteamWorkshopUIUpload.Instance.IsAllInfoFilled()) { return; } string path = Path.Combine(saveLocation, levelId.ToString()); if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path); for (int i = 0; i < files.Length; ++i) { string copyTo = Path.Combine(Directory.GetParent(path).FullName, "thumbnail.jpeg"); if (File.Exists(copyTo)) { File.Delete(copyTo); } if (files[i].EndsWith("thumbnail.jpeg")) { File.Copy(files[i], copyTo); } File.Delete(files[i]); } Directory.Delete(path); } Directory.CreateDirectory(path); File.WriteAllText(Path.Combine(path, "ItemData.json"), completeJSON); WorkshopItemUpdate createNewItemUsingGivenFolder = new WorkshopItemUpdate(); createNewItemUsingGivenFolder.ContentPath = path; createNewItemUsingGivenFolder.IconPath = path + "\\thumbnail.jpeg"; SteamWorkshopUIUpload.Instance.SetItemData(createNewItemUsingGivenFolder); FileInfo[] filesInParent = Directory.GetParent(path).GetFiles(); for (int i = 0; i < filesInParent.Length; ++i) { if (filesInParent[i].FullName.EndsWith("thumbnail.jpeg") || filesInParent[i].FullName.EndsWith("thumbnail")) { string copyTo = string.Empty; if (filesInParent[i].FullName.EndsWith("thumbnail.jpeg")) { copyTo = filesInParent[i].Name; } else { copyTo = filesInParent[i].Name + ".jpeg"; } filesInParent[i].CopyTo(Path.Combine(path, copyTo)); File.Delete(filesInParent[i].FullName); break; } } string infoJson = SteamWorkshopUIUpload.Instance.TransferInfoToJson(path); File.WriteAllText(Path.Combine(path, "LevelInfo.json"), infoJson); File.WriteAllText(Path.Combine(path, "LevelTheme.txt"), SceneManager.GetActiveScene().name); OpenCloseSaveOptions(false); ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Item Saved", "Item '" + SteamWorkshopUIUpload.Instance.NAME_INPUT.text + "' was successfully saved!") .ShowButton(uMyGUI_PopupManager.BTN_OK); }
private void OnGUI() { GUILayout.BeginArea(new Rect(0, Screen.height - 28, Screen.width, 28)); GUILayout.BeginHorizontal(); // BUTTONS if (GUILayout.Button("Browse With Tags", GUILayout.Height(28))) { // show the Steam Workshop browse popup if (SteamWorkshopUIBrowse.Instance != null) { // popup is shown already => let it reload SteamWorkshopUIBrowse.Instance.LoadItems(1); } else { // popup is not shown => bring it to the front (it will automatically load the first page) ((SteamWorkshopPopupBrowse)uMyGUI_PopupManager.Instance.ShowPopup("steam_ugc_browse")).BrowseUI // implement your item/level loading here .OnPlayButtonClick += (WorkshopItemEventArgs p_itemArgs) => { ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Item Played", "Item Name: " + p_itemArgs.Item.Name + "\nFor further item details check SteamWorkshopBrowseExamplePopup or SteamWorkshopBrowseExampleStatic classes.") .ShowButton(uMyGUI_PopupManager.BTN_OK); }; } } if (GUILayout.Button("Upload With Tags", GUILayout.Height(40))) { // everything inside this folder will be uploaded with your item string dummyItemContentFolder = Path.Combine(Application.persistentDataPath, "DummyItemContentFolder" + System.DateTime.Now.Ticks); // use DateTime.Now.Ticks to create a unique folder for each upload if (!Directory.Exists(dummyItemContentFolder)) { Directory.CreateDirectory(dummyItemContentFolder); } // create dummy content to upload string dummyItemContentStr = "Save your item/level/mod data here.\n" + "It does not need to be a text file. Any file type is supported (binary, images, etc...).\n" + "You can save multiple files, Steam items are folders (not single files).\n"; File.WriteAllText(Path.Combine(dummyItemContentFolder, "ItemData.txt"), dummyItemContentStr); // tell which folder you want to upload WorkshopItemUpdate createNewItemUsingGivenFolder = new WorkshopItemUpdate(); createNewItemUsingGivenFolder.ContentPath = dummyItemContentFolder; createNewItemUsingGivenFolder.Tags = m_tagsToUse; // apply tags to the item // show the Steam Workshop item upload popup with a custom popup after successful upload SteamWorkshopPopupUpload uploadPopup = (SteamWorkshopPopupUpload)uMyGUI_PopupManager.Instance.ShowPopup("steam_ugc_upload"); uploadPopup.UploadUI.SetItemData(createNewItemUsingGivenFolder); uploadPopup.UploadUI.OnFinishedUpload += ((WorkshopItemUpdateEventArgs p_args) => { if (!p_args.IsError && p_args.Item != null) { ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)) .SetText("Item Uploaded", "Item '" + p_args.Item.Name + "' was successfully uploaded!\nTags: " + p_args.Item.Tags.Aggregate((tag1, tag2) => tag1 + ", " + tag2) + "\nIt can take a long time for this new level to arrive in the Steam Workshop listing, sometimes longer than an hour! Be patient...") .ShowButton(uMyGUI_PopupManager.BTN_OK); } }); } // TAG SELECTION for (int i = 0; i < TAGS.Length; i++) { bool isTagSetInScript = m_tagsToUse.Contains(TAGS[i]); bool isTagSetInToggle = GUILayout.Toggle(isTagSetInScript, TAGS[i]); // add tag if (isTagSetInToggle && !isTagSetInScript) { m_tagsToUse.Add(TAGS[i]); } // remove tag if (!isTagSetInToggle && isTagSetInScript) { m_tagsToUse.Remove(TAGS[i]); } // apply tags for the item browser search SteamWorkshopMain.Instance.SearchTags = m_tagsToUse; } GUILayout.EndHorizontal(); GUILayout.EndArea(); }