internal static void RunGUIAction(ActionDelegate action) { if (EditorDispatcher.IsOnMainThread) { action(); return; } ManualResetEvent syncEvent = new ManualResetEvent(false); EditorDispatcher.Dispatch(delegate { try { action(); } catch (Exception e) { mLog.ErrorFormat("GUI action failed: {0}", e.Message); mLog.DebugFormat("Stack trace:{0}{1}", Environment.NewLine, e.StackTrace); throw; } finally { syncEvent.Set(); } }); syncEvent.WaitOne(); }
void OnDestroy() { SaveSettings(); if (!mIsCompleted) { var cloneModal = CloneModal(); EditorDispatcher.Dispatch(() => { cloneModal.RunModal(mParentWindow); }); } else { mParentWindow.Focus(); } }
void OnTimerTick() { if (mThreadOperation.IsRunning) { if (mTimerTickDelegate != null) { EditorDispatcher.Dispatch(() => mTimerTickDelegate()); } return; } mPlasticTimer.Stop(); if (mbCancelled) { return; } EditorDispatcher.Dispatch(() => mAfterOperationDelegate()); }
protected void OnGUI() { try { if (Event.current.type == EventType.Layout) { EditorDispatcher.Update(); } if (!mFocusedOnce) { // Somehow the prevents the dialog from jumping when dragged // NOTE(rafa): We cannot do every frame because the modal kidnaps focus for all processes (in mac at least) Focus(); mFocusedOnce = true; } ProcessKeyActions(); if (mIsClosed) { return; } GUI.Box(new Rect(0, 0, position.width, position.height), GUIContent.none); GUI.Box(new Rect(0, 0, position.width, 16), GUIContent.none, EditorStyles.toolbar); float margin = 25; float marginTop = 40; using (new EditorGUILayout.HorizontalScope(GUILayout.Height(position.height))) { GUILayout.Space(margin); using (new EditorGUILayout.VerticalScope(GUILayout.Height(position.height))) { GUILayout.Space(marginTop); OnModalGUI(); GUILayout.Space(margin); } GUILayout.Space(margin); } var lastRect = GUILayoutUtility.GetLastRect(); float desiredHeight = lastRect.yMax; Rect newPos = position; newPos.height = desiredHeight; if (position.height < desiredHeight) { position = newPos; } if (Event.current.type == EventType.Repaint) { if (mIsCompleted) { mIsClosed = true; Close(); } } } finally { if (mIsClosed) { EditorGUIUtility.ExitGUI(); } } }