public void UploadFile() { string path = EditorUtility.OpenFolderPanel("Select folder to upload", "", ""); string[] files = Directory.GetFiles(path); if (files != null && files.Length > 0) { foreach (string file in files) { Debug.Log(GetIdFromFile(file)); if (!file.EndsWith(".meta")) { LootLockerSDKAdminManager.UploadAFile(file, sendAssetID, LootLockerAdminConfig.current.gameID, (response) => { if (response.success) { Debug.LogError("Successful created event: " + response.text); } else { Debug.LogError("failed to create event: " + response.Error); } }); } } } // EditorUtility.DisplayDialog("Select Texture", "You must select a texture first!", "OK"); }
void DrawCreateFileView() { GUILayout.BeginArea(ContentSection); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Asset name: "); assetName = EditorGUILayout.TextField(assetName); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Asset Context ID: "); activeAsset = assetsResponse.assets[0]; AssetContextIndex = EditorGUILayout.Popup(AssetContextIndex, ContextNames); activeAsset.context = Contexts[AssetContextIndex].name; EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Tags"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("saperated by comma", new GUIStyle(GUI.skin.label) { fontSize = 10 }); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); FileTags = EditorGUILayout.TextField(FileTags); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(string.IsNullOrEmpty(filePath) ? "Attach File" : "Choose a different file", GUILayout.Height(30), GUILayout.MaxWidth(200))) { filePath = EditorUtility.OpenFilePanel("Choose a file", "", ""); } if (string.IsNullOrEmpty(filePath)) { EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("You must attach a file to be able to upload", new GUIStyle(GUI.skin.label) { fontSize = 12, fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleLeft }, GUILayout.MaxWidth(1000), GUILayout.Height(25)); } else { EditorGUILayout.LabelField("File name: " + Path.GetFileName(filePath), new GUIStyle(GUI.skin.label) { fontSize = 12, fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleLeft }, GUILayout.MaxWidth(1000), GUILayout.Height(25)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Upload", GUILayout.Height(30))) { currentView = LootLockerView.Loading; var request = new LootLockerCreateAssetRequest() { name = assetName, context_id = Contexts[Array.IndexOf(ContextNames, activeAsset.context)].id }; LootLockerSDKAdminManager.CreateAsset(request, (response) => { if (response.success) { Debug.LogError("Asset created successfully. Uploading file.."); LootLockerSDKAdminManager.GetAssets((getAssetsResponse) => { if (getAssetsResponse.success) { Debug.Log("Successfully got uploaded asset: " + getAssetsResponse.text); LootLockerCommonAsset uploadedAsset = getAssetsResponse.assets[0]; LootLockerSDKAdminManager.UploadAFile(filePath, uploadedAsset.id.ToString(), LootLockerAdminConfig.current.gameID, (uploadResponse) => { if (uploadResponse.success) { Debug.Log("Successfully uploaded file: " + uploadResponse.text); PopulateFiles(); } else { Debug.LogError("Failed to upload file: " + uploadResponse.Error); currentView = LootLockerView.CreateFile; } }, tags: FileTags.Split(',')); } else { Debug.LogError("Failed to get assets: " + getAssetsResponse.Error); currentView = LootLockerView.CreateFile; } }); } else { Debug.LogError("failed to get create/update asset: " + response.Error); currentView = LootLockerView.CreateFile; } }); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (GUILayout.Button("Back", GUILayout.Height(20))) { PopulateFiles(); } GUILayout.EndArea(); }
void DrawAssetView(bool create) { style = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter }; // assetsSection.x = 0; // assetsSection.y = 60; // assetsSection.width = Screen.width; // assetsSection.height = Screen.width - 100; // GUI.DrawTexture(assetsSection, defaultSectionTexture); GUILayout.BeginArea(ContentSection); if (activeAsset != null) { assetsViewScrollPos = EditorGUILayout.BeginScrollView(assetsViewScrollPos, GUILayout.ExpandHeight(true)); #region BackButton and upload EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Back", GUILayout.Height(20))) { PopulateAssets(); } EditorGUILayout.EndHorizontal(); if (UploadingToSelectedAsset) { GUI.backgroundColor = Color.blue; } else if (UploadSucceedForSelectAsset) { GUI.backgroundColor = Color.green; } else if (UploadFailedForSelectAsset) { GUI.backgroundColor = Color.red; } if (!create) { if (GUILayout.Button("Upload", GUILayout.Height(40))) { var filePath = EditorUtility.OpenFilePanel("choose a file", "", ""); UploadingToSelectedAsset = true;//you can do this after call because the response can be in the same frame! if (string.IsNullOrEmpty(filePath)) { Debug.LogWarning("please select a valid file"); UploadingToSelectedAsset = false; } LootLockerSDKAdminManager.UploadAFile(filePath, activeAsset.id.ToString(), LootLockerAdminConfig.current.gameID, (response) => { UploadingToSelectedAsset = false; if (response.success) { UploadSucceedForSelectAsset = true; Task.Delay(2000).ContinueWith(t => UploadSucceedForSelectAsset = false); Debug.Log("Successful uploade file: " + response.text); } else { UploadFailedForSelectAsset = true; Task.Delay(2000).ContinueWith(t => UploadFailedForSelectAsset = false); Debug.LogError("failed to uploade file: " + response.Error); } }); } } GUI.backgroundColor = Color.white; #endregion #region Name EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Name: "); // EditorGUILayout.LabelField(activeAsset.name.ToString()); activeAsset.name = EditorGUILayout.TextField(activeAsset.name); EditorGUILayout.EndHorizontal(); #endregion #region context EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("context: "); // EditorGUILayout.LabelField(activeAsset.context.ToString()); AssetContextIndex = EditorGUILayout.Popup(AssetContextIndex, ContextNames); activeAsset.context = Contexts[AssetContextIndex].name; EditorGUILayout.EndHorizontal(); #endregion #region ID EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("ID: "); EditorGUILayout.LabelField(activeAsset.id.ToString()); EditorGUILayout.EndHorizontal(); #endregion #region Is Active EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Is Active: "); EditorGUILayout.LabelField(activeAsset.active.ToString()); EditorGUILayout.EndHorizontal(); #endregion #region purchasable EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("purchasable: "); EditorGUILayout.LabelField(activeAsset.purchasable.ToString()); EditorGUILayout.EndHorizontal(); #endregion #region price EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("price: "); EditorGUILayout.LabelField(activeAsset.price.ToString()); EditorGUILayout.EndHorizontal(); #endregion // #region display_price // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("display_price: "); // EditorGUILayout.LabelField(activeAsset.display_price.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region unlocks_context // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("unlocks_context: "); // EditorGUILayout.LabelField(activeAsset.unlocks_context.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion #region detachable EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("detachable: "); EditorGUILayout.LabelField(activeAsset.detachable.ToString()); EditorGUILayout.EndHorizontal(); #endregion // #region updated // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("updated: "); // EditorGUILayout.LabelField(activeAsset.updated.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region marked_new // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("marked_new: "); // EditorGUILayout.LabelField(activeAsset.marked_new.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion #region default_variation_id EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("default_variation_id: "); EditorGUILayout.LabelField(activeAsset.default_variation_id.ToString()); EditorGUILayout.EndHorizontal(); #endregion // #region default_loadouts // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("default_loadouts: "); // EditorGUILayout.LabelField(activeAsset.default_loadouts.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region description // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("description: "); // EditorGUILayout.LabelField(activeAsset.description.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region links // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("links: "); // EditorGUILayout.LabelField(activeAsset.links.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region storage // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("storage: "); // EditorGUILayout.LabelField(activeAsset.storage.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region rarity // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("rarity: "); // EditorGUILayout.LabelField(activeAsset.rarity.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion #region popular EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("popular: "); EditorGUILayout.LabelField(activeAsset.popular.ToString()); EditorGUILayout.EndHorizontal(); #endregion #region popularity_score EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("popularity_score: "); EditorGUILayout.LabelField(activeAsset.popularity_score.ToString()); EditorGUILayout.EndHorizontal(); #endregion // #region package_contents // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("package_contents: "); // EditorGUILayout.LabelField(activeAsset.package_contents.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion #region unique_instance EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("unique_instance: "); EditorGUILayout.LabelField(activeAsset.unique_instance.ToString()); EditorGUILayout.EndHorizontal(); #endregion // #region external_identifiers // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("external_identifiers: "); // EditorGUILayout.LabelField(activeAsset.external_identifiers.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region rental_options // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("rental_options: "); // EditorGUILayout.LabelField(activeAsset.rental_options.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region filters // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("filters: "); // EditorGUILayout.LabelField(activeAsset.filters.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion // #region variations // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("variations: "); // EditorGUILayout.LabelField(activeAsset.variations.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion #region featured EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("featured: "); EditorGUILayout.LabelField(activeAsset.featured.ToString()); EditorGUILayout.EndHorizontal(); #endregion // #region success // EditorGUILayout.BeginHorizontal(); // EditorGUILayout.LabelField("success: "); // EditorGUILayout.LabelField(activeAsset.s.ToString()); // EditorGUILayout.EndHorizontal(); // #endregion var msg = String.Empty; if (GUILayout.Button(create ? "Create" : "Update", GUILayout.Height(50))) { var request = new LootLockerCreateAssetRequest() { name = activeAsset.name, context_id = Contexts[Array.IndexOf(ContextNames, activeAsset.context)].id }; LootLockerSDKAdminManager.CreateAsset(request, (response) => { if (response.success) { msg = "asset created/updated successfully"; if (create) { DrawAssetView(create: false); } } else { Debug.LogError("failed to get create/update asset: " + response.Error); } }); } EditorGUILayout.LabelField(msg); EditorGUILayout.EndScrollView(); } GUILayout.EndArea(); }