Skip to content

Commit 9cd0206

Browse files
author
Unity Technologies
committed
Unity 2022.1.0b5 C# reference source code
1 parent e8f201a commit 9cd0206

33 files changed

Lines changed: 494 additions & 220 deletions

File tree

Editor/Mono/EditorGUI.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ internal static void ClearStacks()
247247
{
248248
s_PropertyCount = 0;
249249
s_EnabledStack.Clear();
250+
s_IsInsideListStack.Clear();
251+
GUI.isInsideList = false;
250252
s_ChangedStack.Clear();
251253
s_PropertyStack.Clear();
252254
MaterialProperty.ClearStack();
@@ -261,6 +263,7 @@ internal static void ClearStacks()
261263
private static readonly Stack<PropertyGUIData> s_PropertyStack = new Stack<PropertyGUIData>();
262264

263265
private static readonly Stack<bool> s_EnabledStack = new Stack<bool>();
266+
private static readonly Stack<(bool insideList, int depth)> s_IsInsideListStack = new Stack<(bool insideList, int depth)>();
264267

265268
// @TODO: API soon to be deprecated but still in a grace period; documentation states that users
266269
// are encouraged to use EditorGUI.DisabledScope instead. Uncomment next line when appropriate.
@@ -368,6 +371,28 @@ internal static void EndDisabled()
368371
GUI.enabled = s_EnabledStack.Pop();
369372
}
370373

374+
internal static void BeginIsInsideList(int depth)
375+
{
376+
s_IsInsideListStack.Push((GUI.isInsideList, depth));
377+
GUI.isInsideList = true;
378+
}
379+
380+
internal static int GetInsideListDepth()
381+
{
382+
if (s_IsInsideListStack.Count > 0)
383+
return s_IsInsideListStack.Peek().depth;
384+
return -1;
385+
}
386+
387+
internal static void EndIsInsideList()
388+
{
389+
// Stack might have been cleared with ClearStack(), check before pop.
390+
if (s_IsInsideListStack.Count > 0)
391+
GUI.isInsideList = s_IsInsideListStack.Pop().insideList;
392+
else
393+
GUI.isInsideList = false;
394+
}
395+
371396
private static readonly Stack<bool> s_ChangedStack = new Stack<bool>();
372397

373398
public class ChangeCheckScope : GUI.Scope

Editor/Mono/EditorWindow.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,6 @@ public bool active
13271327
}
13281328
}
13291329

1330-
13311330
[Shortcut("Overlays/Toggle All Overlays", typeof(OverlayShortcutContext), KeyCode.BackQuote)]
13321331
static void ToggleAllOverlays(ShortcutArguments args)
13331332
{
@@ -1365,6 +1364,15 @@ public bool TryGetOverlay(string id, out Overlay match)
13651364
match = null;
13661365
return false;
13671366
}
1367+
1368+
internal void OnBackingScaleFactorChangedInternal()
1369+
{
1370+
if(overlayCanvas != null)
1371+
overlayCanvas.Rebuild();
1372+
OnBackingScaleFactorChanged();
1373+
}
1374+
1375+
protected virtual void OnBackingScaleFactorChanged() { }
13681376
}
13691377

13701378
[AttributeUsage(AttributeTargets.Class)]

Editor/Mono/FileUtil.bindings.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ namespace UnityEditor
1717
public partial class FileUtil
1818
{
1919
// Deletes a file or a directory given a path.
20-
[FreeFunction]
21-
public static extern bool DeleteFileOrDirectory(string path);
20+
public static bool DeleteFileOrDirectory(string path)
21+
{
22+
if (path is null) throw new ArgumentNullException("path");
23+
if (path == string.Empty) throw new ArgumentException("path", "The path cannot be empty.");
24+
25+
return DeleteFileOrDirectoryInternal(path);
26+
}
27+
28+
[FreeFunction("DeleteFileOrDirectory")]
29+
private static extern bool DeleteFileOrDirectoryInternal(string path);
2230

2331
[FreeFunction("IsPathCreated")]
2432
private static extern bool PathExists(string path);

Editor/Mono/GUI/EditorApplicationLayout.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ static internal void FinalizePlaymodeLayout()
155155
{
156156
foreach (var playModeView in m_PlayModeViewList)
157157
{
158-
if (playModeView != null && playModeView.enterPlayModeBehavior == PlayModeView.EnterPlayModeBehavior.PlayMaximized)
158+
if (playModeView != null)
159159
{
160160
if (m_MaximizePending)
161161
WindowLayout.MaximizePresent(playModeView);
162162

163+
// All StartView references on all play mode views must be cleared before play mode starts. Otherwise it may cause issues
164+
// with input being routed to the correct game window. See case 1381985
163165
playModeView.m_Parent.ClearStartView();
164166
}
165167
}

Editor/Mono/GUI/ObjectField.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ static Object DoObjectField(Rect position, Rect dropRect, int id, Object obj, Ob
364364
var parentArrayProperty = property.serializedObject.FindProperty(parentArrayPropertyPath);
365365
bool isReorderableList = PropertyHandler.s_reorderableLists.ContainsKey(ReorderableListWrapper.GetPropertyIdentifier(parentArrayProperty));
366366

367-
// If it's an element of an non-orderable array, remove that element from the array
368-
if (!isReorderableList)
367+
// If it's an element of an non-orderable array and it is displayed inside a list, remove that element from the array (cases 1379541 & 1335322)
368+
if (!isReorderableList && GUI.isInsideList && GetInsideListDepth() == parentArrayProperty.depth)
369369
TargetChoiceHandler.DeleteArrayElement(property);
370370
else
371371
property.objectReferenceValue = null;

Editor/Mono/GUI/Toolbar.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,24 @@ internal static string lastLoadedLayoutName
7777
protected override void OnEnable()
7878
{
7979
base.OnEnable();
80-
8180
EditorApplication.modifierKeysChanged += Repaint;
82-
8381
get = this;
82+
m_EventInterests.wantsLessLayoutEvents = true;
83+
CreateContents();
84+
}
8485

86+
void CreateContents()
87+
{
8588
m_MainToolbarVisual = (MainToolbarVisual)Activator.CreateInstance(EditorUIService.instance.GetDefaultToolbarType());
86-
89+
m_Root?.RemoveFromHierarchy();
8790
m_Root = CreateRoot();
88-
if (windowBackend.visualTree is VisualElement visualTree)
91+
92+
if (windowBackend?.visualTree is VisualElement visualTree)
8993
{
9094
visualTree.Add(m_Root);
9195
m_Root.Add(m_MainToolbarVisual.root);
9296
}
9397

94-
m_EventInterests.wantsLessLayoutEvents = true;
9598
RepaintToolbar();
9699
}
97100

@@ -131,6 +134,11 @@ static VisualElement CreateRoot()
131134
return root;
132135
}
133136

137+
protected override void OnBackingScaleFactorChanged()
138+
{
139+
CreateContents();
140+
}
141+
134142
internal static void RepaintToolbar()
135143
{
136144
if (get != null)

Editor/Mono/GUIView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ internal IWindowBackend windowBackend
155155
set
156156
{
157157
if (m_WindowBackend != null)
158-
{
159158
m_WindowBackend.OnDestroy(this);
160-
}
161159

162160
m_WindowBackend = value;
163161
m_WindowBackend?.OnCreate(this);
@@ -195,6 +193,8 @@ protected virtual void OldOnGUI() {}
195193
// In that case, commands are not delegated (e.g., keyboard-based delete in Hierarchy/Project)
196194
protected virtual void OnGUI() {}
197195

196+
protected virtual void OnBackingScaleFactorChanged() { }
197+
198198
protected override void SetPosition(Rect newPos)
199199
{
200200
Rect oldWinPos = windowPosition;

Editor/Mono/HostView.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ internal void OnLostFocus()
307307
Repaint();
308308
}
309309

310+
protected override void OnBackingScaleFactorChanged()
311+
{
312+
if (m_ActualView != null)
313+
m_ActualView.OnBackingScaleFactorChangedInternal();
314+
}
315+
310316
protected override void OnDestroy()
311317
{
312318
if (m_ActualView)

Editor/Mono/Inspector/GenericInspector.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ internal override bool OnOptimizedInspectorGUI(Rect contentRect)
125125
{
126126
while (property.NextVisible(childrenAreExpanded))
127127
{
128+
if (GUI.isInsideList && property.depth <= EditorGUI.GetInsideListDepth())
129+
EditorGUI.EndIsInsideList();
130+
131+
if (property.isArray)
132+
EditorGUI.BeginIsInsideList(property.depth);
133+
128134
var handler = ScriptAttributeUtility.GetHandler(property);
129135
var hasPropertyDrawer = handler.propertyDrawer != null;
130136
childrenAreExpanded = !hasPropertyDrawer && property.isExpanded && EditorGUI.HasVisibleChildFields(property);

Editor/Mono/Inspector/TagManagerInspector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ void AddToSortLayerList(ReorderableList list)
244244

245245
public void ReorderSortLayerList(ReorderableList list)
246246
{
247+
serializedObject.ApplyModifiedProperties();
247248
tagManager.UpdateSortingLayersOrder();
248249
}
249250

0 commit comments

Comments
 (0)