static void SendManifest(string json, int versionNumber, System.Action callback) { var settings = CognitiveVR_Preferences.FindCurrentScene(); if (settings == null) { Debug.LogWarning("Send Manifest settings are null " + UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().path); string s = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; if (string.IsNullOrEmpty(s)) { s = "Unknown Scene"; } EditorUtility.DisplayDialog("Dynamic Object Manifest Upload Failed", "Could not find the Scene Settings for \"" + s + "\". Are you sure you've saved, exported and uploaded this scene to SceneExplorer?", "Ok"); return; } string url = Constants.POSTDYNAMICMANIFEST(settings.SceneId, versionNumber); Util.logDebug("Send Manifest Contents: " + json); //upload manifest Dictionary <string, string> headers = new Dictionary <string, string>(); if (EditorCore.IsDeveloperKeyValid) { headers.Add("Authorization", "APIKEY:DEVELOPER " + EditorCore.DeveloperKey); headers.Add("Content-Type", "application/json"); } PostManifestResponseAction = callback; EditorNetwork.Post(url, json, PostManifestResponse, headers, false);//AUTH }
//static System.Action RefreshSceneVersionComplete; /// <summary> /// get collection of versions of scene /// </summary> /// <param name="refreshSceneVersionComplete"></param> public static void RefreshMediaSources() { Debug.Log("refresh media sources"); //gets the scene version from api and sets it to the current scene string currentSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; var currentSettings = CognitiveVR_Preferences.FindScene(currentSceneName); if (currentSettings != null) { if (!IsDeveloperKeyValid) { Debug.Log("Developer key invalid"); return; } if (currentSettings == null) { Debug.Log("SendSceneVersionRequest no scene settings!"); return; } string url = CognitiveStatics.GETMEDIASOURCELIST(); Dictionary <string, string> headers = new Dictionary <string, string>(); if (EditorCore.IsDeveloperKeyValid) { headers.Add("Authorization", "APIKEY:DEVELOPER " + EditorCore.DeveloperKey); } EditorNetwork.Get(url, GetMediaSourcesResponse, headers, true, "Get Scene Version");//AUTH } else { Debug.Log("No scene versions for scene: " + currentSceneName); } }
public static void UploadScreenshot() { //get scene id var currentScene = CognitiveVR_Preferences.FindCurrentScene(); if (currentScene == null) { Debug.Log("Could not find current scene"); return; } if (string.IsNullOrEmpty(currentScene.SceneId)) { Debug.Log(currentScene.SceneName + " scene has not been uploaded!"); return; } //file popup string path = EditorUtility.OpenFilePanel("Select Screenshot", "", "png"); if (path.Length == 0) { return; } string filename = Path.GetFileName(path); if (EditorUtility.DisplayDialog("Upload Screenshot", "Upload " + filename + " to " + currentScene.SceneName + " version " + currentScene.VersionNumber + "?", "Upload", "Cancel")) { string url = CognitiveStatics.POSTSCREENSHOT(currentScene.SceneId, currentScene.VersionNumber); var bytes = File.ReadAllBytes(path); WWWForm form = new WWWForm(); form.AddBinaryData("screenshot", bytes, "screenshot.png"); var headers = new Dictionary <string, string>(); foreach (var v in form.headers) { headers[v.Key] = v.Value; } if (EditorCore.IsDeveloperKeyValid) { headers.Add("Authorization", "APIKEY:DEVELOPER " + EditorCore.DeveloperKey); } EditorNetwork.Post(url, form, UploadScreenhotResponse, headers, false); } }
/// <summary> /// get collection of versions of scene /// </summary> /// <param name="refreshSceneVersionComplete"></param> public static void RefreshSceneVersion(System.Action refreshSceneVersionComplete) { Debug.Log("refresh scene version"); //gets the scene version from api and sets it to the current scene string currentSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; var currentSettings = CognitiveVR_Preferences.FindScene(currentSceneName); if (currentSettings != null) { if (!IsDeveloperKeyValid) { Debug.Log("Developer key invalid"); return; } if (currentSettings == null) { Debug.Log("SendSceneVersionRequest no scene settings!"); return; } if (string.IsNullOrEmpty(currentSettings.SceneId)) { if (refreshSceneVersionComplete != null) { refreshSceneVersionComplete.Invoke(); } return; } RefreshSceneVersionComplete = refreshSceneVersionComplete; string url = CognitiveStatics.GETSCENEVERSIONS(currentSettings.SceneId); Dictionary <string, string> headers = new Dictionary <string, string>(); if (EditorCore.IsDeveloperKeyValid) { headers.Add("Authorization", "APIKEY:DEVELOPER " + EditorCore.DeveloperKey); } EditorNetwork.Get(url, GetSceneVersionResponse, headers, true, "Get Scene Version");//AUTH } else { Debug.Log("No scene versions for scene: " + currentSceneName); } }
//get dynamic object aggregation manifest for the current scene void GetManifest() { var currentSceneSettings = CognitiveVR_Preferences.FindCurrentScene(); if (currentSceneSettings == null) { return; } if (string.IsNullOrEmpty(currentSceneSettings.SceneId)) { Util.logWarning("Get Manifest current scene doesn't have an id!"); return; } string url = Constants.GETDYNAMICMANIFEST(currentSceneSettings.VersionId); Dictionary <string, string> headers = new Dictionary <string, string>(); if (EditorCore.IsDeveloperKeyValid) { headers.Add("Authorization", "APIKEY:DEVELOPER " + EditorCore.DeveloperKey); } EditorNetwork.Get(url, GetManifestResponse, headers, false);//AUTH }
public static void UploadDecimatedScene(CognitiveVR_Preferences.SceneSettings settings, System.Action uploadComplete) { //if uploadNewScene POST //else PUT to sceneexplorer/sceneid if (settings == null) { UploadSceneSettings = null; return; } UploadSceneSettings = settings; bool hasExistingSceneId = settings != null && !string.IsNullOrEmpty(settings.SceneId); bool uploadConfirmed = false; string sceneName = settings.SceneName; string[] filePaths = new string[] { }; string sceneExportDirectory = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "CognitiveVR_SceneExplorerExport" + Path.DirectorySeparatorChar + settings.SceneName + Path.DirectorySeparatorChar; var SceneExportDirExists = Directory.Exists(sceneExportDirectory); if (SceneExportDirExists) { filePaths = Directory.GetFiles(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "CognitiveVR_SceneExplorerExport" + Path.DirectorySeparatorChar + sceneName + Path.DirectorySeparatorChar); } //custom confirm upload popup windows if ((!SceneExportDirExists || filePaths.Length <= 1)) { if (EditorUtility.DisplayDialog("Upload Scene", "Scene " + settings.SceneName + " has no exported geometry. Upload anyway?", "Yes", "No")) { uploadConfirmed = true; //create a json.settings file in the directory string objPath = CognitiveVR_SceneExplorerExporter.GetDirectory(sceneName); Directory.CreateDirectory(objPath); string jsonSettingsContents = "{ \"scale\":1, \"sceneName\":\"" + settings.SceneName + "\",\"sdkVersion\":\"" + Core.SDK_VERSION + "\"}"; File.WriteAllText(objPath + "settings.json", jsonSettingsContents); } } else { uploadConfirmed = true; /*if (EditorUtility.DisplayDialog("Upload Scene", "Do you want to upload \"" + settings.SceneName + "\" to your Dashboard?", "Yes", "No")) * { * * }*/ } if (!uploadConfirmed) { UploadSceneSettings = null; return; //just exit now } //after confirmation because uploading an empty scene creates a settings.json file if (Directory.Exists(sceneExportDirectory)) { filePaths = Directory.GetFiles(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "CognitiveVR_SceneExplorerExport" + Path.DirectorySeparatorChar + sceneName + Path.DirectorySeparatorChar); } string[] screenshotPath = new string[0]; if (Directory.Exists(sceneExportDirectory + "screenshot")) { screenshotPath = Directory.GetFiles(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "CognitiveVR_SceneExplorerExport" + Path.DirectorySeparatorChar + sceneName + Path.DirectorySeparatorChar + "screenshot"); } else { Debug.Log("SceneExportWindow Upload can't find directory to screenshot"); } string fileList = "Upload Files:\n"; string mtlFilepath = ""; string objFilepath = ""; WWWForm wwwForm = new WWWForm(); foreach (var f in filePaths) { if (f.ToLower().EndsWith(".ds_store")) { Debug.Log("skip file " + f); continue; } //set obj file. prefer decimated if (f.EndsWith(".obj")) { if (f.EndsWith("_decimated.obj")) { objFilepath = f; } else if (string.IsNullOrEmpty(objFilepath)) { objFilepath = f; } continue; } //set mtl file. prefer decimated if (f.EndsWith(".mtl")) { if (f.EndsWith("_decimated.mtl")) { mtlFilepath = f; } else if (string.IsNullOrEmpty(mtlFilepath)) { mtlFilepath = f; } continue; } fileList += f + "\n"; var data = File.ReadAllBytes(f); wwwForm.AddBinaryData("file", data, Path.GetFileName(f)); } if (!string.IsNullOrEmpty(objFilepath)) { //add obj and mtl files wwwForm.AddBinaryData("file", File.ReadAllBytes(objFilepath), Path.GetFileName(objFilepath)); fileList += objFilepath + "\n"; wwwForm.AddBinaryData("file", File.ReadAllBytes(mtlFilepath), Path.GetFileName(mtlFilepath)); fileList += mtlFilepath + "\n"; } Debug.Log(fileList); if (screenshotPath.Length == 0) { Debug.Log("SceneExportWindow Upload can't find files in screenshot directory"); } else { wwwForm.AddBinaryData("screenshot", File.ReadAllBytes(screenshotPath[0]), "screenshot.png"); } if (hasExistingSceneId) //upload new verison of existing scene { Dictionary <string, string> headers = new Dictionary <string, string>(); if (EditorCore.IsDeveloperKeyValid) { headers.Add("Authorization", "APIKEY:DEVELOPER " + EditorCore.DeveloperKey); //headers.Add("Content-Type", "multipart/form-data; boundary=\""+) foreach (var v in wwwForm.headers) { headers[v.Key] = v.Value; } } EditorNetwork.Post(Constants.POSTUPDATESCENE(settings.SceneId), wwwForm.data, PostSceneUploadResponse, headers, true, "Upload", "Uploading new version of scene");//AUTH } else //upload as new scene { //posting wwwform with headers //sceneUploadWWW = new WWW(Constants.POSTNEWSCENE(), wwwForm); Dictionary <string, string> headers = new Dictionary <string, string>(); if (EditorCore.IsDeveloperKeyValid) { headers.Add("Authorization", "APIKEY:DEVELOPER " + EditorCore.DeveloperKey); //headers.Add("Content-Type", "multipart/form-data; boundary=\""+) foreach (var v in wwwForm.headers) { headers[v.Key] = v.Value; } } EditorNetwork.Post(Constants.POSTNEWSCENE(), wwwForm.data, PostSceneUploadResponse, headers, true, "Upload", "Uploading new scene");//AUTH //Debug.Log("Upload new scene"); } UploadComplete = uploadComplete; //EditorApplication.update += UpdateUploadData; }