Beispiel #1
0
        /// <summary>Opens a blocking dialogue in the given window.</summary>
        public static BlockingDialogue Open(string type, Window window, object message)
        {
            // Get the thread:
            System.Threading.Thread thread = System.Threading.Thread.CurrentThread;

            // Safety check: We can only block the 'blockable' thread.
            // This prevents it from blocking the Unity main thread.
            if (thread != window.BlockableThread)
            {
                UnityEngine.Debug.LogWarning("Failed to open a '" + type + "' dialogue because it was on a thread other than the window's main Javascript thread (and we don't want to block it).");
                return(null);
            }

            if (window.BlockingDialogue != null)
            {
                // Hmm, one is already open - we shouldn't open another.
                UnityEngine.Debug.LogWarning("Unexpected '" + type + "' dialogue request. One is already open.");
                return(null);
            }

            // Create the dialogue:
            BlockingDialogue bd = new BlockingDialogue(type, window);

            // Pop now:
            string text;

            Templates.TryGetValue(bd.Type, out text);

            if (string.IsNullOrEmpty(text))
            {
                // UI unavailable.
                return(null);
            }

            if (window.document.html == null)
            {
                Dom.Log.Add("Can't prompt without a html node.");
                return(null);
            }

            // Append it:
            HtmlElement background = window.document.createElement("div") as HtmlElement;

            background.id        = "spark-prompt-background";
            background.innerHTML = "<div id='spark-prompt'>" + text + "</div>";
            window.document.html.appendChild(background);

            // Get the message zone:
            HtmlElement content = background.getElementById("spark-prompt-content-zone") as HtmlElement;

            if (content != null && message != null)
            {
                // Write the message:
                content.innerHTML = message.ToString();
            }

            // Add the element:
            bd.Element = background;

            // Add to the window:
            window.BlockingDialogue = bd;

            // Cache the thread:
            bd.Thread = thread;

            try{
                // Going down! Sleep now:
                System.Threading.Thread.Sleep(Timeout.Infinite);
            }catch (System.Threading.ThreadInterruptedException) {
                // Back up again!
            }

            return(bd);
        }