/// <summary>Performs the translation now.</summary>
        public void Translate()
        {
            // Start a request:
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("post", "http://translate.kulestar.com/v2/machine");

            request.onerror = delegate(UIEvent e){
                // Failed:
                Errored(request.responseText);
            };

            request.onload = delegate(UIEvent e){
                // Parse the JSON:
                JSObject json    = JSON.Parse(request.responseText);
                JSArray  results = json == null ? null : (json["results"] as JSArray);

                if (results == null)
                {
                    // Failed:
                    Errored(request.responseText);
                }
                else
                {
                    // Let it know it completed:
                    Complete(results);
                }
            };

            // Send it off:
            request.send(Json);
        }
Ejemplo n.º 2
0
        /// <summary>Downloads the icons now.</summary>
        public static void DownloadIcons()
        {
            if (IsDownloading)
            {
                return;
            }
            IsDownloading = true;

            Request = new XMLHttpRequest();

            Request.open("get", "http://powerui.kulestar.com/emoji/phantomOpenEmoji.unitypackage");

            Request.onreadystatechange = delegate(UIEvent e){
                if (Request.readyState == 4)
                {
                    IsDownloading = false;

                    if (Request.ok)
                    {
                        // Create the directory, if needed:
                        if (!Directory.Exists(IconPath))
                        {
                            Directory.CreateDirectory(IconPath);
                        }

                        // Write out the bytes:
                        RemovePackage();

                        File.WriteAllBytes(IconPath + "phantomOpenEmoji.unitypackage", Request.responseBytes);
                        // Save the changes:
                        AssetDatabase.Refresh();

                        Status = 1;
                        if (Window != null)
                        {
                            Window.Repaint();
                        }

                        // Next, pull in the package:
                        AssetDatabase.ImportPackage(IconPath + "phantomOpenEmoji.unitypackage", false);

                        // Next, remove it:
                        RemovePackage();

                        // Make sure the database is up to date:
                        AssetDatabase.Refresh();
                        // And save all the changes:
                        AssetDatabase.SaveAssets();

                        Status = 2;
                        if (Window != null)
                        {
                            Window.Repaint();
                        }
                    }
                    else
                    {
                        Debug.LogError("HTTP Error getting " + Request.location.absolute + ": " + Request.statusCode);
                    }

                    if (Window != null)
                    {
                        Window.Repaint();
                    }
                }
            };

            // Send it off:
            Request.send();
        }