Skip to content

Commit 2fb1127

Browse files
author
Unity Technologies
committed
Unity 2023.1.0b8 C# reference source code
1 parent a6e2578 commit 2fb1127

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+655
-398
lines changed

Editor/Mono/PerformanceTools/FrameDebugger.cs

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

Editor/Mono/PerformanceTools/FrameDebuggerStyles.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ internal struct EventDetails
225225
internal const string k_WarningMultiThreadedMsg = "The Frame Debugger requires multi-threaded renderer. If this error persists, try starting the Editor with -force-gfx-mt command line argument.";
226226
internal const string k_WarningLinuxOpenGLMsg = k_WarningMultiThreadedMsg + " On Linux, the editor does not support a multi-threaded renderer when using OpenGL.";
227227
internal const string k_DescriptionString = "Frame Debugger lets you step through draw calls and see how exactly frame is rendered. Click Enable!";
228+
internal const string k_TabbedWithPlaymodeErrorString = "Frame Debugger can not be docked with the Game Window when trying to debug the editor.";
228229
internal static readonly GUIContent s_RenderTargetText = EditorGUIUtility.TrTextContent("RenderTarget");
229230
internal static readonly GUIContent s_CopyEventText = EditorGUIUtility.TrTextContent("Copy Event Info");
230231
internal static readonly GUIContent s_CopyPropertyText = EditorGUIUtility.TrTextContent("Copy Property");

Editor/Mono/PerformanceTools/FrameDebuggerToolbarView.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ private void DrawConnectionDropdown(FrameDebuggerWindow frameDebuggerWindow, ICo
6868
if (isEnabled && ProfilerDriver.connectedProfiler != FrameDebuggerUtility.GetRemotePlayerGUID())
6969
{
7070
// Switch from local to remote debugger or vice versa
71-
FrameDebuggerUtility.SetEnabled(false, FrameDebuggerUtility.GetRemotePlayerGUID());
72-
FrameDebuggerUtility.SetEnabled(true, ProfilerDriver.connectedProfiler);
71+
frameDebuggerWindow.OnConnectedProfilerChange();
7372
}
7473
}
7574

Editor/Mono/UIElements/Controls/LayerField.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace UnityEditor.UIElements
1212
{
1313
/// <summary>
14-
/// A <see cref="LayerField"/> editor.
14+
/// A LayerField editor.
1515
/// </summary>
1616
public class LayerField : PopupField<int>
1717
{

Editor/Mono/UIElements/Controls/LayerMaskField.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace UnityEditor.UIElements
1212
{
1313
/// <summary>
14-
/// Make a field for layer as masks.
14+
/// A LayerMaskField editor.
1515
/// </summary>
1616
public class LayerMaskField : MaskField
1717
{

ModuleOverrides/com.unity.ui/Core/Clickable.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,32 @@ public class Clickable : PointerManipulator
1717
/// <summary>
1818
/// Callback triggered when the target element is clicked, including event data.
1919
/// </summary>
20+
/// <remarks>
21+
/// Encapsulates a method that has an <see cref="EventBase"/> parameter and does not return a value.
22+
/// </remarks>
2023
public event System.Action<EventBase> clickedWithEventInfo;
24+
2125
/// <summary>
2226
/// Callback triggered when the target element is clicked.
2327
/// </summary>
28+
/// <remarks>
29+
/// Encapsulates a method that has no parameters and does not return a value.
30+
/// </remarks>
31+
/// <example>
32+
/// <code>
33+
/// <![CDATA[
34+
/// public VisualElement CreateButton()
35+
/// {
36+
/// var button = new Button { text = "Press Me" };
37+
/// button.clicked += () =>
38+
/// {
39+
/// Debug.Log("Button was pressed!");
40+
/// };
41+
/// return button;
42+
/// }
43+
/// ]]>
44+
/// </code>
45+
/// </example>
2446
public event System.Action clicked;
2547

2648
private readonly long m_Delay; // in milliseconds
@@ -61,8 +83,8 @@ internal bool acceptClicksIfDisabled
6183
/// <summary>
6284
/// Constructor.
6385
/// </summary>
64-
/// <param name="delay">Determines when the event begins. Applies if delay > 0.</param>
65-
/// <param name="interval">Determines the time delta between event repetition. Applies if interval > 0.</param>
86+
/// <param name="delay">Determines when the event begins. Value is defined in milliseconds. Applies if delay > 0.</param>
87+
/// <param name="interval">Determines the time delta between event repetition. Value is defined in milliseconds. Applies if interval > 0.</param>
6688
public Clickable(System.Action handler, long delay, long interval) : this(handler)
6789
{
6890
m_Delay = delay;

ModuleOverrides/com.unity.ui/Core/Controls/BaseBoolField.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace UnityEngine.UIElements
88
{
99
/// <summary>
10-
/// A <see cref="BaseBoolField"/> is a clickable element that represents a boolean value.
10+
/// A BaseBoolField is a clickable element that represents a boolean value.
1111
/// </summary>
1212
public abstract class BaseBoolField : BaseField<bool>
1313
{

ModuleOverrides/com.unity.ui/Core/Controls/BaseVerticalCollectionView.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext
141141
}
142142

143143
/// <summary>
144-
/// Callback triggered when the user acts on a selection of one or more items, for example by double-clicking or pressing Enter.
144+
/// Obsolete. Use <see cref="BaseVerticalCollectionView.itemsChosen"/> instead.
145145
/// </summary>
146146
/// <remarks>
147147
/// This callback receives an enumerable that contains the item or items chosen.
@@ -162,7 +162,7 @@ public event Action<IEnumerable<object>> onItemsChosen
162162
public event Action<IEnumerable<object>> itemsChosen;
163163

164164
/// <summary>
165-
/// Callback triggered when the selection changes.
165+
/// Obsolete. Use <see cref="BaseVerticalCollectionView.selectionChanged"/> instead.
166166
/// </summary>
167167
/// <remarks>
168168
/// This callback receives an enumerable that contains the item or items selected.
@@ -183,7 +183,7 @@ public event Action<IEnumerable<object>> onSelectionChange
183183
public event Action<IEnumerable<object>> selectionChanged;
184184

185185
/// <summary>
186-
/// Callback triggered when the selection changes.
186+
/// Obsolete. Use <see cref="BaseVerticalCollectionView.selectedIndicesChanged"/> instead.
187187
/// </summary>
188188
/// <remarks>
189189
/// This callback receives an enumerable that contains the item index or item indices selected.
@@ -254,7 +254,7 @@ public IList itemsSource
254254
internal virtual bool sourceIncludesArraySize => false;
255255

256256
/// <summary>
257-
/// Callback for constructing the VisualElement that is the template for each recycled and re-bound element in the list.
257+
/// Obsolete. Use <see cref="ListView.makeItem"> or <see cref="TreeView.makeItem"/> instead.
258258
/// </summary>
259259
[Obsolete("makeItem has been moved to ListView and TreeView. Use these ones instead.")]
260260
public Func<VisualElement> makeItem
@@ -264,7 +264,7 @@ public Func<VisualElement> makeItem
264264
}
265265

266266
/// <summary>
267-
/// Callback for binding a data item to the visual element.
267+
/// Obsolete. Use <see cref="ListView.bindItem"> or <see cref="TreeView.bindItem"/> instead.
268268
/// </summary>
269269
[Obsolete("bindItem has been moved to ListView and TreeView. Use these ones instead.")]
270270
public Action<VisualElement, int> bindItem
@@ -274,7 +274,7 @@ public Action<VisualElement, int> bindItem
274274
}
275275

276276
/// <summary>
277-
/// Callback for unbinding a data item from the VisualElement.
277+
/// Obsolete. Use <see cref="ListView.unbindItem"> or <see cref="TreeView.unbindItem"/> instead.
278278
/// </summary>
279279
[Obsolete("unbindItem has been moved to ListView and TreeView. Use these ones instead.")]
280280
public Action<VisualElement, int> unbindItem
@@ -284,7 +284,7 @@ public Action<VisualElement, int> unbindItem
284284
}
285285

286286
/// <summary>
287-
/// Callback invoked when a <see cref="VisualElement"/> created via <see cref="makeItem"/> is no longer needed and will be destroyed.
287+
/// Obsolete. Use <see cref="ListView.destroyItem"> or <see cref="TreeView.destroyItem"/> instead.
288288
/// </summary>
289289
[Obsolete("destroyItem has been moved to ListView and TreeView. Use these ones instead.")]
290290
public Action<VisualElement> destroyItem
@@ -384,7 +384,7 @@ public int selectedIndex
384384
public CollectionViewController viewController => m_ViewController;
385385

386386
/// <summary>
387-
/// The computed pixel-aligned height for the list elements.
387+
/// Obsolete, will be removed from the API.
388388
/// </summary>
389389
/// <remarks>
390390
/// This value changes depending on the current panel's DPI scaling.
@@ -543,7 +543,7 @@ public CollectionVirtualizationMethod virtualizationMethod
543543
}
544544

545545
/// <summary>
546-
/// The height of a single item in the list, in pixels.
546+
/// Obsolete. Use <see cref="BaseVerticalCollectionView.fixedItemHeight"> instead.
547547
/// </summary>
548548
/// <remarks>
549549
/// This property must be set when using the <see cref="virtualizationMethod"/> is set to <c>FixedHeight</c>, for the collection view to function.
@@ -841,7 +841,7 @@ public BaseVerticalCollectionView(IList itemsSource, float itemHeight = ItemHeig
841841
}
842842

843843
/// <summary>
844-
/// Constructs a <see cref="BaseVerticalCollectionView"/>, with all required properties provided.
844+
/// Obsolete. Use <see cref="ListView"> or <see cref="TreeView"> constructor directly.
845845
/// </summary>
846846
/// <param name="itemsSource">The list of items to use as a data source.</param>
847847
/// <param name="itemHeight">The height of each item, in pixels. For <c>FixedHeight</c> virtualization only.</param>
@@ -941,6 +941,9 @@ public void RefreshItems()
941941
}
942942
}
943943

944+
/// <summary>
945+
/// Obsolete. Use <see cref="BaseVerticalCollectionView.Rebuild"> instead.
946+
/// </summary>
944947
[Obsolete("Refresh() has been deprecated. Use Rebuild() instead. (UnityUpgradable) -> Rebuild()", false)]
945948
public void Refresh()
946949
{
@@ -1025,7 +1028,7 @@ public void ScrollToItem(int index)
10251028
}
10261029

10271030
/// <summary>
1028-
/// Scrolls to a specific item id and makes it visible.
1031+
/// Obsolete. Use <see cref="BaseVerticalCollectionView.ScrollToItemById"> instead.
10291032
/// </summary>
10301033
/// <param name="id">Item id to scroll to.</param>
10311034
[Obsolete("ScrollToId() has been deprecated. Use ScrollToItemById() instead. (UnityUpgradable) -> ScrollToItemById(*)", false)]

ModuleOverrides/com.unity.ui/Core/Controls/Button.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace UnityEngine.UIElements
1010
/// This is a clickable button.
1111
/// </summary>
1212
/// <remarks>
13-
/// A <see cref="Button"/> consists of a text label element that can respond to pointer and mouse events.
14-
/// You can replace or add to the content of the button by adding elements to its hierarchy.
15-
/// For example, to use a separate image as an icon for the button, you can make an <see cref="Image"/>
16-
/// element a child of the button.
13+
/// A Button has a text label element that can respond to pointer and mouse events.
14+
/// You can customize a button by adding child elements to its hierarchy.
15+
/// For example, to use a separate image as an icon for the button, you can add an <see cref="Image"/>
16+
/// element as a child of the button.
1717
///
1818
/// By default, a single left mouse click activates the Button's <see cref="Clickable"/> property button.
1919
/// To remove this activator, or add more activators, modify the <c>clickable.activators</c> property.

ModuleOverrides/com.unity.ui/Core/Controls/Image.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace UnityEngine.UIElements
1111
{
1212
/// <summary>
1313
/// A <see cref="VisualElement"/> representing a source texture.
14+
///
15+
/// **Note**: This is not related to the `UnityEngine.UI.Image` uGUI control. This is the Image control for the UI Toolkit framework.
1416
/// </summary>
1517
public class Image : VisualElement
1618
{
@@ -53,7 +55,7 @@ public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescri
5355
private bool m_TintColorIsInline;
5456

5557
/// <summary>
56-
/// The texture to display in this image.
58+
/// The texture to display in this image. If you assign a `Texture` or `Texture2D`, the Image element will resize and show the assigned texture.
5759
/// </summary>
5860
[CreateProperty]
5961
public Texture image

0 commit comments

Comments
 (0)