示例#1
0
    public UploadUrls GetS3PresignedUrls(string game_deployment_id)
    {
        try
        {
            List <IMultipartFormSection> form = new List <IMultipartFormSection>();
            string dirToBuildFiles            = Path.Combine(this.webglBuildFolder, buildFolder);

            form.Add(new MultipartFormFileSection("file", System.IO.File.ReadAllBytes(Path.Combine(dirToBuildFiles, "UnityLoader.js")), "UnityLoader.js", "javascript"));
            form.Add(new MultipartFormFileSection("file", System.IO.File.ReadAllBytes(Path.Combine(dirToBuildFiles, "webgl_build.json")), "webgl_build.json", "json"));
            form.Add(new MultipartFormDataSection("version", "1.1.0"));
            form.Add(new MultipartFormDataSection("access_key", game_deployment_id));

            string URL = "https://mxlvl-api.herokuapp.com/api/games/upload/";
            using (UnityWebRequest www = UnityWebRequest.Post(URL, form))
            {
                www.SendWebRequest();
                Debug.Log("Sent Request");
                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    while (www.responseCode == 0)
                    {
                    }
                    string text = System.Text.Encoding.ASCII.GetString(www.downloadHandler.data);
                    Debug.Log(text + " : " + www.responseCode + " " + www.downloadedBytes + " data leng: " + www.downloadHandler.data.Length);
                    UploadUrls url = JsonUtility.FromJson <UploadUrls>(text);
                    return(url);
                }
            }
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }
        return(null);
    }
示例#2
0
    protected virtual void OnGUI()
    {
        GUI.skin.label.wordWrap = true;

        // setup info text
        GUI.skin.label.richText = true;
        GUILayout.Label("Welcome to the Mxlvl Publisher tool for Unity.\nThis window will let you publish your game to the Mxlvl platform <b>AFTER</b> you have built a WebGL platform version of your game.\n\n<b>-</b>Enter the Publisher ID below\n<b>-</b>Select folder location of the WebGL platform build\n<b>-</b>Click Publish\n\n*upload can take up to 5 minutes");

        GUILayout.BeginHorizontal();
        GUILayout.Label("Version");
        this.version = EditorGUILayout.TextField(this.version).Trim();
        GUILayout.EndHorizontal();

        GUILayout.Label("Game Deployment ID");
        string setGameId = EditorGUILayout.TextField(this.gameId).Trim();

        GUILayout.Space(5);

        if (setGameId != this.gameId)
        {
            this.gameId = setGameId;
        }

        EditorGUILayout.TextField(this.webglBuildFolder).Trim();
        if (GUILayout.Button("Select WebGL Build Folder"))
        {
            this.webglBuildFolder = EditorUtility.OpenFolderPanel("WebGL Platform Build Folder", "", "");
            this.HasUpdated();
        }
        GUILayout.Space(5);

        string dirToBuildFiles = Path.Combine(this.webglBuildFolder, buildFolder);

        if (!string.IsNullOrEmpty(this.webglBuildFolder))
        {
            this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
            foreach (string file in this.uploadFiles)
            {
                string filePath = Path.Combine(dirToBuildFiles, file);
                if (!File.Exists(filePath))
                {
                    GUILayout.Label("File Not Found: " + file);
                    Debug.Log("File Not Found: " + file);
                }
            }
            GUILayout.EndScrollView();
        }
        EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(this.webglBuildFolder));
        if (GUILayout.Button("[Publish]"))
        {
            this.HasUpdated();

            try
            {
                UploadUrls urls = GetS3PresignedUrls(this.gameId);
                foreach (string file in this.uploadFiles)
                {
                    continue;
                    string upload_url_name = file.Replace(".unityweb", "");
                    upload_url_name = upload_url_name.Replace('.', '_');
                    string filePath = Path.Combine(dirToBuildFiles, file);
                    if (File.Exists(filePath))
                    {
                        if (file == "webgl_build.asm.code.unityweb")
                        {
                            Debug.Log(ExecCommand.ExecuteCommand(string.Format(urls.webgl_build_asm_code_unityweb, filePath)));
                        }
                        if (upload_url_name == "webgl_build_asm_framework")
                        {
                            Debug.Log(ExecCommand.ExecuteCommand(string.Format(urls.webgl_build_asm_framework_unityweb, filePath)));
                        }
                        if (upload_url_name == "webgl_build_asm_memory")
                        {
                            Debug.Log(ExecCommand.ExecuteCommand(string.Format(urls.webgl_build_asm_memory_unityweb, filePath)));
                        }
                        if (upload_url_name == "webgl_build_data")
                        {
                            Debug.Log(ExecCommand.ExecuteCommand(string.Format(urls.webgl_build_data_unityweb, filePath)));
                        }
                    }
                }
            }catch (Exception e)
            {
            }
        }
        EditorGUI.EndDisabledGroup();

        GUI.skin.label.richText = false;
    }
 /// <summary>
 /// Setups the manager.
 /// </summary>
 private void SetUploadUrls()
 {
     var uploadUrls = new UploadUrls { SecurityPhotoUploadAddress = "http://locathost" };
     this.personRepository.Setup(data => data.RetrieveGuestUploadsUrls()).Returns(Task.FromResult(uploadUrls));
     this.personRepository.Setup(data => data.RetrieveCrewUploadsUrls()).Returns(Task.FromResult(uploadUrls));
     this.personRepository.Setup(data => data.RetrieveVisitorUploadsUrls()).Returns(Task.FromResult(uploadUrls));
 }