@@ -27,6 +27,8 @@ internal class FrameDebuggerWindow : EditorWindow
2727 private int m_EnablingWaitCounter = 0 ;
2828 private int m_RepaintFrames = k_NeedToRepaintFrames ;
2929 private int m_FrameEventsHash ;
30+ private bool m_ShowTabbedErrorBox ;
31+ private bool m_HasOpenedPlaymodeView ;
3032 private Rect m_SearchRect ;
3133 private string m_SearchString = String . Empty ;
3234 private IConnectionState m_AttachToPlayerState ;
@@ -103,6 +105,12 @@ internal void ChangeFrameEventLimit(int newLimit, FrameDebuggerTreeView.FrameDeb
103105 m_TreeView ? . SelectFrameEventIndex ( newLimit ) ;
104106 }
105107
108+ internal void OnConnectedProfilerChange ( )
109+ {
110+ DisableFrameDebugger ( ) ;
111+ EnableFrameDebugger ( ) ;
112+ }
113+
106114 internal static void RepaintAll ( )
107115 {
108116 foreach ( var fd in s_FrameDebuggers )
@@ -186,10 +194,17 @@ private void DrawDisabledFrameDebugger()
186194 }
187195
188196 EditorGUILayout . HelpBox ( FrameDebuggerStyles . EventDetails . k_DescriptionString , MessageType . Info , true ) ;
197+
198+ if ( m_ShowTabbedErrorBox )
199+ EditorGUILayout . HelpBox ( FrameDebuggerStyles . EventDetails . k_TabbedWithPlaymodeErrorString , MessageType . Error , true ) ;
189200 }
190201
191202 private void HandleEnablingFrameDebugger ( )
192203 {
204+ // Make sure the PlayMode window is enabled and shown...
205+ if ( ! OpenPlayModeView ( ) )
206+ return ;
207+
193208 if ( Event . current . type != EventType . Repaint )
194209 return ;
195210
@@ -203,19 +218,74 @@ private void HandleEnablingFrameDebugger()
203218 }
204219 }
205220
206- private void DrawEnabledFrameDebugger ( bool repaint )
221+ private bool CheckIfFDIsDockedWithGameWindow ( DockArea da , PlayModeView gameWindow )
207222 {
208- int oldLimit = FrameDebuggerUtility . limit ;
209- FrameDebuggerEvent [ ] descs = FrameDebuggerUtility . GetFrameEvents ( ) ;
223+ for ( int i = 0 ; i < da . m_Panes . Count ; i ++ )
224+ if ( gameWindow == da . m_Panes [ i ] )
225+ return true ;
226+ return false ;
227+ }
210228
211- // Make sure the PlayMode window is enabled and shown...
212- if ( FrameDebugger . IsLocalEnabled ( ) )
229+ private bool OpenPlayModeView ( )
230+ {
231+ if ( m_HasOpenedPlaymodeView )
232+ return true ;
233+
234+ // When debugging remote players, we can ignore this check as it doesn't render to the Game Window.
235+ if ( ! FrameDebugger . IsLocalEnabled ( ) && m_AttachToPlayerState . connectedToTarget != ConnectionTarget . Editor )
236+ return true ;
237+
238+ PlayModeView mainGameWindow = PlayModeView . GetMainPlayModeView ( ) ;
239+ List < PlayModeView > allGameWindows = PlayModeView . GetAllPlayModeViewWindows ( ) ;
240+ if ( mainGameWindow || allGameWindows . Count > 0 )
213241 {
214- PlayModeView playModeView = PlayModeView . GetMainPlayModeView ( ) ;
215- if ( playModeView )
216- playModeView . ShowTab ( ) ;
242+ PlayModeView gameWindowToUse = mainGameWindow ;
243+
244+ // The Frame Debugger and Game Window can not be docked together in
245+ // the panes list (tabs) as both need to be shown in the Editor.
246+ bool isFDInTheSamePaneAsGameWindow = false ;
247+ DockArea da = m_Parent as DockArea ;
248+ if ( da )
249+ isFDInTheSamePaneAsGameWindow |= CheckIfFDIsDockedWithGameWindow ( da , mainGameWindow ) ;
250+
251+ // If it's docked, check if there are other game windows available to use
252+ if ( isFDInTheSamePaneAsGameWindow && allGameWindows . Count > 1 )
253+ {
254+ for ( int i = 0 ; i < allGameWindows . Count ; i ++ )
255+ {
256+ if ( CheckIfFDIsDockedWithGameWindow ( da , allGameWindows [ i ] ) )
257+ continue ;
258+
259+ isFDInTheSamePaneAsGameWindow = false ;
260+ gameWindowToUse = allGameWindows [ i ] ;
261+ break ;
262+ }
263+ }
264+
265+ // When we can't enable the FD debugger, we display an error box informing the
266+ // user to undock the Frame Debugger Window so it's not tabbed with the Game Window.
267+ if ( isFDInTheSamePaneAsGameWindow )
268+ {
269+ m_ShowTabbedErrorBox = true ;
270+ return false ;
271+ }
272+ // Otherwise we show the Game Window
273+ else
274+ {
275+ gameWindowToUse . ShowTab ( ) ;
276+ m_HasOpenedPlaymodeView = true ;
277+ return true ;
278+ }
217279 }
218280
281+ return false ;
282+ }
283+
284+ private void DrawEnabledFrameDebugger ( bool repaint )
285+ {
286+ int oldLimit = FrameDebuggerUtility . limit ;
287+ FrameDebuggerEvent [ ] descs = FrameDebuggerUtility . GetFrameEvents ( ) ;
288+
219289 // captured frame event contents have changed, rebuild the tree data
220290 if ( HasEventHashChanged )
221291 {
@@ -319,13 +389,10 @@ private void EnableFrameDebugger()
319389 if ( enablingLocally && ! FrameDebuggerUtility . locallySupported )
320390 return ;
321391
322- // Make sure game view is visible when enabling frame debugger locally
323- if ( FrameDebugger . IsLocalEnabled ( ) )
324- {
325- PlayModeView playModeView = PlayModeView . GetMainPlayModeView ( ) ;
326- if ( playModeView )
327- playModeView . ShowTab ( ) ;
328- }
392+ m_ShowTabbedErrorBox = false ;
393+ m_HasOpenedPlaymodeView = false ;
394+ if ( ! OpenPlayModeView ( ) )
395+ return ;
329396
330397 // pause play mode if needed
331398 if ( enablingLocally )
@@ -342,7 +409,6 @@ private void EnableFrameDebugger()
342409
343410 m_EnablingWaitCounter = 0 ;
344411 m_EventDetailsView . Reset ( ) ;
345-
346412 RepaintOnLimitChange ( ) ;
347413 }
348414
@@ -363,6 +429,7 @@ private void DisableFrameDebugger()
363429 m_EventDetailsView = null ;
364430 }
365431
432+ m_HasOpenedPlaymodeView = false ;
366433 FrameDebuggerStyles . OnDisable ( ) ;
367434 m_TreeViewState = null ;
368435 m_TreeView = null ;
0 commit comments