示例#1
0
    // Publish file to Sketchfab
    private IEnumerator publishCoroutine(Dictionary <string, string> parameters, string accessToken)
    {
        state = ExporterState.PUBLISH_MODEL;
        done  = false;
        WWWForm postForm = new WWWForm();

        if (!System.IO.File.Exists(localFileName))
        {
            Debug.LogError("File has not been exported. Aborting publish.");
        }

        // Export
        byte[] data = File.ReadAllBytes(localFileName);
        postForm.AddBinaryData("modelFile", data, localFileName, "application/zip");
        foreach (string param in parameters.Keys)
        {
            postForm.AddField(param, parameters[param]);
        }

        postForm.AddField("source", "Unity-exporter");
        //postForm.AddField("isPublished", true ? "1" : "0");
        //postForm.AddField("private", true ? "1" : "0");

        Dictionary <string, string> headers = postForm.headers;

        headers["Authorization"] = "Bearer " + accessToken;
        www = new WWW(skfbUrl + "v3/models", postForm.data, headers);
        yield return(www);
    }
示例#2
0
    // Update is called once per frame
    void OnInspectorUpdate()
    {
        Repaint();
        float currentTimeSecond = convertToSeconds(DateTime.Now);


        if (publisher != null && publisher.www != null && publisher.www.isDone)
        {
            state = publisher.getState();
            www   = publisher.www;
            switch (state)
            {
            case ExporterState.CHECK_VERSION:
                JSONNode githubResponse = JSON.Parse(this.jsonify(www.text));
                if (githubResponse != null && githubResponse[0]["tag_name"] != null)
                {
                    latestVersion = githubResponse[0]["tag_name"];
                    if (exporterVersion != latestVersion)
                    {
                        bool update = EditorUtility.DisplayDialog("Exporter update", "A new version is available \n(you have version " + exporterVersion + ")\nIt's strongly rsecommended that you update now. The latest version may include important bug fixes and improvements", "Update", "Skip");
                        if (update)
                        {
                            Application.OpenURL(latestReleaseUrl);
                        }
                    }
                    else
                    {
                        resizeWindow(fullSize);
                    }
                }
                else
                {
                    latestVersion = "";
                    resizeWindow(fullSize + new Vector2(0, 15));
                }
                publisher.setIdle();
                break;


            case ExporterState.PUBLISH_MODEL:

                if (www.responseHeaders["STATUS"].Contains("201") == true)
                {
                    string urlid = www.responseHeaders["LOCATION"].Split('/')[www.responseHeaders["LOCATION"].Split('/').Length - 1];
                    string url   = skfbUrl + "models/" + urlid;
                    Application.OpenURL(url);
                }
                else
                {
                    EditorUtility.DisplayDialog("Upload failed", www.responseHeaders["STATUS"], "Ok");
                }
                publisher.setIdle();
                break;
            }
        }
    }
示例#3
0
    private IEnumerator userAccountCoroutine(string access_token)
    {
        done  = false;
        state = ExporterState.USER_ACCOUNT_TYPE;
        WWWForm oform = new WWWForm();
        Dictionary <string, string> headers = oform.headers;

        headers["Authorization"] = "Bearer " + access_token;
        www = new WWW(skfbUrl + "v3/me", null, headers);
        yield return(www);
    }
示例#4
0
    // Request access_token
    private IEnumerator oauthCoroutine(string user_name, string user_password)
    {
        done  = false;
        state = ExporterState.REQUEST_CODE;
        WWWForm oform = new WWWForm();

        oform.AddField("username", user_name);
        oform.AddField("password", user_password);
        www = new WWW(skfbUrl + "oauth2/token/?grant_type=password&client_id=" + dummyClientId, oform);
        yield return(www);
    }
 public void requestUserCanPrivate()
 {
     if (_currentUserPlan.label == "BASIC")
     {
         _userCanPrivate = false;
     }
     else
     {
         _state = ExporterState.CAN_PRIVATE;
         _publisher.requestUserCanPrivate();
     }
 }
示例#6
0
 private IEnumerator checkVersionCoroutine()
 {
     state = ExporterState.CHECK_VERSION;
     www   = new WWW(latestVersionCheckUrl);
     yield return(www);
 }
示例#7
0
 private IEnumerator categoriesCoroutine()
 {
     state = ExporterState.GET_CATEGORIES;
     www   = new WWW(skfbUrl + "v3/categories");
     yield return(www);
 }
示例#8
0
 public void setIdle()
 {
     state = ExporterState.IDLE;
 }
示例#9
0
 public void setState(ExporterState newState)
 {
     this.state = newState;
 }
示例#10
0
 public void Start()
 {
     state = ExporterState.IDLE;
     done  = false;
 }
示例#11
0
    // Update is called once per frame
    void OnInspectorUpdate()
    {
        Repaint();
        float currentTimeSecond = convertToSeconds(DateTime.Now);

        if (access_token.Length > 0 && currentTimeSecond - lastTokenTime > expiresIn)
        {
            access_token = "";
            relog();
        }

        if (publisher != null && publisher.www != null && publisher.www.isDone)
        {
            state = publisher.getState();
            www   = publisher.www;
            switch (state)
            {
            case ExporterState.CHECK_VERSION:
                JSONNode githubResponse = JSON.Parse(this.jsonify(www.text));
                if (githubResponse != null && githubResponse[0]["tag_name"] != null)
                {
                    latestVersion = githubResponse[0]["tag_name"];
                    if (exporterVersion != latestVersion)
                    {
                        bool update = EditorUtility.DisplayDialog("Exporter update", "A new version is available \n(you have version " + exporterVersion + ")\nIt's strongly rsecommended that you update now. The latest version may include important bug fixes and improvements", "Update", "Skip");
                        if (update)
                        {
                            Application.OpenURL(latestReleaseUrl);
                        }
                    }
                    else
                    {
                        resizeWindow(fullSize);
                    }
                }
                else
                {
                    latestVersion = "";
                    resizeWindow(fullSize + new Vector2(0, 15));
                }
                publisher.setIdle();
                break;

            case ExporterState.REQUEST_CODE:
                JSONNode accessResponse = JSON.Parse(this.jsonify(www.text));
                if (accessResponse["access_token"] != null)
                {
                    access_token  = accessResponse["access_token"];
                    expiresIn     = accessResponse["expires_in"].AsFloat;
                    lastTokenTime = convertToSeconds(DateTime.Now);
                    publisher.getAccountType(access_token);
                    if (exporterVersion != latestVersion)
                    {
                        resizeWindow(fullSize + new Vector2(0, 20));
                    }
                    else
                    {
                        resizeWindow(fullSize);
                    }
                }
                else
                {
                    string errorDesc = accessResponse["error_description"];
                    EditorUtility.DisplayDialog("Authentication failed", "Failed to authenticate on Sketchfab.com.\nPlease check your credentials\n\nError: " + errorDesc, "Ok");
                    publisher.setIdle();
                }

                break;

            case ExporterState.PUBLISH_MODEL:
                //foreach(string key in www.responseHeaders.Keys)
                //{
                //    Debug.Log("[" + key + "] = " + www.responseHeaders[key]);
                //}
                if (www.responseHeaders["STATUS"].Contains("201") == true)
                {
                    string urlid = www.responseHeaders["LOCATION"].Split('/')[www.responseHeaders["LOCATION"].Split('/').Length - 1];
                    string url   = skfbUrl + "models/" + urlid;
                    Application.OpenURL(url);
                }
                else
                {
                    EditorUtility.DisplayDialog("Upload failed", www.responseHeaders["STATUS"], "Ok");
                }
                publisher.setIdle();
                break;

            case ExporterState.GET_CATEGORIES:
                string jsonify = this.jsonify(www.text);
                if (!jsonify.Contains("results"))
                {
                    Debug.Log(jsonify);
                    Debug.Log("Failed to retrieve categories");
                    publisher.setIdle();
                    break;
                }

                JSONArray categoriesArray = JSON.Parse(jsonify)["results"].AsArray;
                foreach (JSONNode node in categoriesArray)
                {
                    categories.Add(node["name"], node["slug"]);
                    categoriesNames.Add(node["name"]);
                }
                publisher.setIdle();
                break;

            case ExporterState.USER_ACCOUNT_TYPE:
                string accountRequest = this.jsonify(www.text);
                if (!accountRequest.Contains("account"))
                {
                    Debug.Log(accountRequest);
                    Debug.Log("Failed to retrieve user account type");
                    publisher.setIdle();
                    break;
                }

                var userSettings = JSON.Parse(accountRequest);
                isUserPro       = userSettings["account"].ToString().Contains("free") == false;
                userDisplayName = userSettings["displayName"];
                publisher.setIdle();
                break;
            }
        }
    }
 private void setIdle()
 {
     _state = ExporterState.IDLE;
 }
 public void publishModel(Dictionary <string, string> parameters, string zipPath)
 {
     _state = ExporterState.PUBLISH_MODEL;
     _publisher.postModel(parameters, zipPath);
 }
 public void requestUserAccountInfo()
 {
     _state = ExporterState.USER_ACCOUNT_TYPE;
     _publisher.requestAccountInfo();
 }
 public void checkLatestExporterVersion()
 {
     _state = ExporterState.CHECK_VERSION;
     _publisher.requestExporterReleaseInfo();
 }
 public void authenticateUser(string username, string password)
 {
     _state = ExporterState.REQUEST_CODE;
     _publisher.requestAccessToken(username, password);
 }