示例#1
0
 private static void RemoveOnUpdateCallback(EditorApplication.CallbackFunction callback)
 {
     RunOnMainThread.Run(delegate
     {
         EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, callback);
     }, true);
 }
示例#2
0
        /// <summary>
        /// Enables / disables external package registries for Package Manager.
        /// </summary>
        static PackageManagerResolver()
        {
            logger.Log("Loaded PackageManagerResolver", level: LogLevel.Verbose);

            RunOnMainThread.Run(() => {
                // Load log preferences.
                VerboseLoggingEnabled = VerboseLoggingEnabled;
            }, runNow: false);
        }
示例#3
0
 /// <summary>
 /// Schedule the execution of a job.
 /// </summary>
 /// <param name="job">Action that will be called in future. This job should call
 /// Complete() to signal the end of the operation.</param>
 public void Schedule(Action job)
 {
     RunOnMainThread.Run(() => {
         jobs.Enqueue(job);
         if (jobs.Count == 1)
         {
             ExecuteNext();
         }
     }, runNow: false);
 }
示例#4
0
        /// <summary>
        /// Start a web request on the main thread.
        /// </summary>
        /// <param name="method">Method to use.</param>
        /// <param name="url">Target URL.</param>
        /// <param name="headers">Headers to use when performing the request.</param>
        /// <param name="payload">Payload to send if this is a Post request, ignored otherwise.</param>
        /// <returns>PortableWebRequest instance that provides the status of the request.</returns>
        private static IPortableWebRequestStatus StartRequestOnMainThread(
            HttpMethod method, string url, IDictionary <string, string> headers, WWWForm form)
        {
            var requestStatus = new RequestStatus();

            RunOnMainThread.Run(() => {
                requestStatus.Request = StartRequest(method, url, headers, form);
            });
            return(requestStatus);
        }
    /// <summary>
    /// Render the dialog according to the context.
    /// </summary>
    void OnGUI() {
        // Close the window if Option0String is empty.
        // After Unity reload assemblies, the EditorWindow will remain open but all the content
        // in the dialog will be cleared because dialogContext is not serializable. Therefore,
        // close the dialog after assembly reload. Close in the next editor frame or it may
        // generate error message like "OpenGL Context became invalid during rendering".
        // This is for Unity 5.
        if (String.IsNullOrEmpty(dialogContext.Option0String) && !terminating) {
            terminating = true;
            RunOnMainThread.Run(() => {
                Close();
            }, runNow: false);
        }

        InitializeStyles();

        Rect rect = EditorGUILayout.BeginVertical();

        if (!String.IsNullOrEmpty(dialogContext.Title)) {
            GUILayout.Label(dialogContext.Title, EditorStyles.boldLabel);
            EditorGUILayout.Space();
        }

        // Render the dialog message.
        GUILayout.Label(dialogContext.Message, DefaultMessageStyle);
        EditorGUILayout.Space();

        // Render the additional context.
        if (dialogContext.RenderContentAction != null) {
            dialogContext.RenderContentAction(this);
            EditorGUILayout.Space();
        }

        EditorGUILayout.BeginHorizontal();
        // Render additional buttons before the option buttons.
        if (dialogContext.RenderButtonsAction != null) {
            dialogContext.RenderButtonsAction(this);
        }
        // Render option buttons.
        RenderOptionButtons();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.EndVertical();

        // Adjust the dialog window size according to the rendered content.
        // Rect returned by BeginVertical() can be zeroes for a couple of frames, therefore
        // ignoring resizing for those frames.
        if (rect.width != 0.0f && rect.height != 0.0f) {
            // Additional space at the bottom of the window.
            const float FILLER_WINDOWS_HEIGHT = 15.0f;
            float windowHeight = rect.height + FILLER_WINDOWS_HEIGHT;
            minSize = new Vector2(dialogContext.WindowWidth, windowHeight);
            maxSize = new Vector2(dialogContext.WindowWidth, windowHeight);
        }
    }
示例#6
0
 private static void AddOnUpdateCallback(EditorApplication.CallbackFunction callback)
 {
     RunOnMainThread.Run(delegate
     {
         EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, callback);
         EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, callback);
         if (ExecutionEnvironment.InBatchMode)
         {
             callback();
         }
     }, true);
 }
示例#7
0
 /// <summary>
 /// Signal the end of job execution.
 /// </summary>
 public void Complete()
 {
     RunOnMainThread.Run(() => {
         var remaining = jobs.Count;
         if (remaining > 0)
         {
             jobs.Dequeue();
         }
         if (remaining > 1)
         {
             ExecuteNext();
         }
     }, runNow: false);
 }