Skip to content

Commit 5e1aa94

Browse files
author
Unity Technologies
committed
Unity 2021.1.0a8 C# reference source code
1 parent dee28cd commit 5e1aa94

File tree

237 files changed

+7695
-1700
lines changed

Some content is hidden

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

237 files changed

+7695
-1700
lines changed

Editor/Mono/Animation/AnimationWindow/CurveEditor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,11 +1326,16 @@ void DragTangents()
13261326
key.inTangent = tangentDirection.y / tangentDirection.x;
13271327
key.inWeight = Mathf.Clamp(Mathf.Abs(tangentDirection.x / dx), 0f, 1f);
13281328
}
1329-
else
1329+
else if (tangentDirection.y > 0)
13301330
{
13311331
key.inTangent = Mathf.Infinity;
13321332
key.inWeight = 0f;
13331333
}
1334+
else
1335+
{
1336+
key.inTangent = -Mathf.Infinity;
1337+
key.inWeight = 0f;
1338+
}
13341339
AnimationUtility.SetKeyLeftTangentMode(ref key, TangentMode.Free);
13351340

13361341
if (!AnimationUtility.GetKeyBroken(key))
@@ -1350,11 +1355,16 @@ void DragTangents()
13501355
key.outTangent = tangentDirection.y / tangentDirection.x;
13511356
key.outWeight = Mathf.Clamp(Mathf.Abs(tangentDirection.x / dx), 0f, 1f);
13521357
}
1353-
else
1358+
else if (tangentDirection.y > 0)
13541359
{
13551360
key.outTangent = Mathf.Infinity;
13561361
key.outWeight = 0f;
13571362
}
1363+
else
1364+
{
1365+
key.outTangent = -Mathf.Infinity;
1366+
key.outWeight = 0f;
1367+
}
13581368
AnimationUtility.SetKeyRightTangentMode(ref key, TangentMode.Free);
13591369

13601370
if (!AnimationUtility.GetKeyBroken(key))
@@ -3112,6 +3122,7 @@ Vector2 GetPosition(CurveSelection selection)
31123122
{
31133123
Vector2 dir = new Vector2(1.0F, key.inTangent);
31143124
if (key.inTangent == Mathf.Infinity) dir = new Vector2(0, -1);
3125+
else if (key.inTangent == -Mathf.Infinity) dir = new Vector2(0, 1);
31153126

31163127
Vector2 viewDir = NormalizeInViewSpace(dir);
31173128

@@ -3135,6 +3146,7 @@ Vector2 GetPosition(CurveSelection selection)
31353146
{
31363147
Vector2 dir = new Vector2(1.0F, key.outTangent);
31373148
if (key.outTangent == Mathf.Infinity) dir = new Vector2(0, -1);
3149+
else if (key.outTangent == -Mathf.Infinity) dir = new Vector2(0, 1);
31383150

31393151
Vector2 viewDir = NormalizeInViewSpace(dir);
31403152

Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ internal enum BuildCallbacks
143143
//common comparer for all callback types
144144
internal static int CompareICallbackOrder(IOrderedCallback a, IOrderedCallback b)
145145
{
146-
return a.callbackOrder - b.callbackOrder;
146+
return a.callbackOrder.CompareTo(b.callbackOrder);
147147
}
148148

149149
static void AddToList<T>(object o, ref List<T> list) where T : class

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private void ActiveBuildTargetsGUI()
244244

245245
// Switching build target in the editor
246246
BuildTarget selectedTarget = EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget();
247-
BuildTargetGroup selectedTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
247+
BuildTargetGroup selectedTargetGroup = EditorUserBuildSettingsUtils.CalculateSelectedBuildTargetGroup();
248248

249249
GUILayout.BeginHorizontal();
250250

@@ -596,7 +596,7 @@ void ShowBuildTargetSettings()
596596
EditorGUIUtility.labelWidth = Mathf.Min(180, (position.width - 265) * 0.47f);
597597

598598
BuildTarget buildTarget = EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget();
599-
BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
599+
BuildTargetGroup buildTargetGroup = EditorUserBuildSettingsUtils.CalculateSelectedBuildTargetGroup();
600600
BuildPlatform platform = BuildPlatforms.instance.BuildPlatformFromTargetGroup(buildTargetGroup);
601601
bool licensed = BuildPipeline.LicenseCheck(buildTarget);
602602

@@ -967,7 +967,7 @@ private static void GUIBuildButtons(IBuildWindowExtension buildWindowExtension,
967967

968968
// Switching build target in the editor
969969
BuildTarget selectedTarget = EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget();
970-
BuildTargetGroup selectedTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
970+
BuildTargetGroup selectedTargetGroup = EditorUserBuildSettingsUtils.CalculateSelectedBuildTargetGroup();
971971

972972
bool selectedTargetIsActive = EditorUserBuildSettings.activeBuildTarget == selectedTarget &&
973973
EditorUserBuildSettings.activeBuildTargetGroup == selectedTargetGroup;

Editor/Mono/ConsoleWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ internal void OnGUI()
639639

640640
if (string.IsNullOrEmpty(m_SearchText))
641641
errorModeStyle.Draw(textRect, tempContent, id, m_ListView.row == el.row);
642-
else
642+
else if (text != null)
643643
{
644644
//the whole text contains the searchtext, we have to know where it is
645645
int startIndex = text.IndexOf(m_SearchText, StringComparison.OrdinalIgnoreCase);

Editor/Mono/ContainerWindow.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal partial class ContainerWindow : ScriptableObject
3838
static internal bool linuxEditor => Application.platform == RuntimePlatform.LinuxEditor;
3939

4040
static internal bool s_Modal = false;
41-
private static bool hasMainWindow = false;
41+
private static ContainerWindow s_MainWindow;
4242

4343
private static class Styles
4444
{
@@ -137,7 +137,7 @@ internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)
137137
// Show the editor window.
138138
public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately, bool setFocus)
139139
{
140-
if (hasMainWindow && showMode == ShowMode.MainWindow)
140+
if (showMode == ShowMode.MainWindow && s_MainWindow && s_MainWindow != this)
141141
throw new InvalidOperationException("Trying to create a second main window from layout when one already exists.");
142142

143143
bool useMousePos = showMode == ShowMode.AuxWindow;
@@ -173,7 +173,7 @@ public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately,
173173
return;
174174

175175
if (showMode == ShowMode.MainWindow)
176-
hasMainWindow = true;
176+
s_MainWindow = this;
177177

178178
// Fit window to screen - needs to be done after bringing the window live
179179
position = FitWindowRectToScreen(m_PixelRect, true, useMousePos);
@@ -290,8 +290,8 @@ internal void InternalCloseWindow()
290290
{
291291
Save();
292292

293-
if (m_ShowMode == (int)ShowMode.MainWindow)
294-
hasMainWindow = false;
293+
if (m_ShowMode == (int)ShowMode.MainWindow && s_MainWindow == this)
294+
s_MainWindow = null;
295295

296296
if (m_RootView)
297297
{

Editor/Mono/EditorUserBuildSettingsUtils.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ internal static class EditorUserBuildSettingsUtils
1010
{
1111
public static BuildTarget CalculateSelectedBuildTarget()
1212
{
13-
BuildTargetGroup targetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
13+
BuildTargetGroup targetGroup = CalculateSelectedBuildTargetGroup();
1414
switch (targetGroup)
1515
{
1616
case BuildTargetGroup.Standalone:
17-
return DesktopStandaloneBuildWindowExtension.GetBestStandaloneTarget(EditorUserBuildSettings.selectedStandaloneTarget);
17+
{
18+
BuildTarget target = EditorUserBuildSettings.selectedStandaloneTarget;
19+
if (target == BuildTarget.NoTarget)
20+
target = EditorUserBuildSettings.activeBuildTarget;
21+
return DesktopStandaloneBuildWindowExtension.GetBestStandaloneTarget(target);
22+
}
1823
default:
1924
if (BuildPlatforms.instance == null)
2025
throw new System.Exception("Build platforms are not initialized.");
@@ -24,5 +29,13 @@ public static BuildTarget CalculateSelectedBuildTarget()
2429
return platform.defaultTarget;
2530
}
2631
}
32+
33+
public static BuildTargetGroup CalculateSelectedBuildTargetGroup()
34+
{
35+
BuildTargetGroup targetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
36+
if (targetGroup == BuildTargetGroup.Unknown)
37+
targetGroup = EditorUserBuildSettings.activeBuildTargetGroup;
38+
return targetGroup;
39+
}
2740
}
2841
}

Editor/Mono/EditorUtility.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ internal static void DisplayObjectContextMenu(Rect position, Object[] context, i
552552
// Handle modified component.
553553
if (hasPrefabOverride)
554554
{
555-
bool defaultOverrides =
556-
PrefabUtility.IsObjectOverrideAllDefaultOverridesComparedToAnySource(targetObject);
555+
bool isObjectOverrideAllDefaultOverridesComparedToOriginalSource =
556+
PrefabUtility.IsObjectOverrideAllDefaultOverridesComparedToOriginalSource(targetObject);
557557

558558
PrefabUtility.HandleApplyRevertMenuItems(
559559
"Modified Component",
@@ -573,7 +573,7 @@ internal static void DisplayObjectContextMenu(Rect position, Object[] context, i
573573
{
574574
pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabObjectOverride, targetObject);
575575
},
576-
defaultOverrides
576+
isObjectOverrideAllDefaultOverridesComparedToOriginalSource
577577
);
578578
}
579579
}

Editor/Mono/EditorWindow.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,12 @@ internal void SetMainPlayModeViewSize(Vector2 targetSize)
10641064
m_Parent.SetMainPlayModeViewSize(targetSize);
10651065
}
10661066

1067+
internal void SetDisplayViewSize(int displayId, Vector2 targetSize)
1068+
{
1069+
if (m_Parent != null)
1070+
m_Parent.SetDisplayViewSize(displayId, targetSize);
1071+
}
1072+
10671073
internal void SetPlayModeView(bool value)
10681074
{
10691075
m_IsPlayModeView = value;

Editor/Mono/GUI/ReorderableList.cs

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class ReorderableList
6464

6565
private SerializedObject m_SerializedObject;
6666
private SerializedProperty m_Elements;
67-
private string m_PropertyPath;
67+
private string m_PropertyPath = string.Empty;
6868
private IList m_ElementList;
6969
private bool m_Draggable;
7070
private float m_DraggedY;
@@ -75,6 +75,8 @@ public class ReorderableList
7575
public bool displayAdd;
7676
public bool displayRemove;
7777

78+
bool scheduleRemove;
79+
7880
internal bool m_IsEditable;
7981
internal bool m_HasPropertyDrawer;
8082

@@ -202,7 +204,7 @@ public void DrawFooter(Rect rect, ReorderableList list)
202204
|| (list.onCanRemoveCallback != null && !list.onCanRemoveCallback(list))
203205
|| list.isOverMaxMultiEditLimit))
204206
{
205-
if (GUI.Button(removeRect, iconToolbarMinus, preButton))
207+
if (GUI.Button(removeRect, iconToolbarMinus, preButton) || GUI.enabled && list.scheduleRemove)
206208
{
207209
if (list.onRemoveCallback == null)
208210
{
@@ -213,9 +215,12 @@ public void DrawFooter(Rect rect, ReorderableList list)
213215

214216
list.onChangedCallback?.Invoke(list);
215217
list.ClearCacheRecursive();
218+
GUI.changed = true;
216219
}
217220
}
218221
}
222+
223+
list.scheduleRemove = false;
219224
}
220225

221226
// default add button behavior
@@ -460,7 +465,7 @@ public IList list
460465
public int index
461466
{
462467
get { return m_Selection.Count > 0 ? m_Selection[0] : count - 1; }
463-
set { Select(value < 0 ? count - 1 : value); }
468+
set { Select(value > count - 1 ? 0 : value < 0 ? count - 1 : value); }
464469
}
465470

466471
public ReadOnlyCollection<int> selectedIndices => new ReadOnlyCollection<int>(m_Selection);
@@ -973,6 +978,7 @@ private void DoListElements(Rect listRect, Rect visibleRect)
973978
index = i;
974979
handlingInput = false;
975980
}
981+
976982
// Element drawing could be changed from distant properties or controls
977983
// so if we detect any change in the way the property is drawn, clear cache
978984
int currentControlCount = EditorGUI.s_PropertyCount - initialProperties;
@@ -982,6 +988,11 @@ private void DoListElements(Rect listRect, Rect visibleRect)
982988
GUI.changed = true;
983989
}
984990
m_PropertyCache[i].lastControlCount = currentControlCount;
991+
992+
// If an event was consumed in the course of running this for loop, then there is
993+
// a good chance the array data has changed and it is dangerous for us to continue
994+
// rendering it in this frame.
995+
if (Event.current.type == EventType.Used) break;
985996
}
986997
}
987998

@@ -1035,6 +1046,12 @@ private void DoListElements(Rect listRect, Rect visibleRect)
10351046

10361047
private void DoListHeader(Rect headerRect)
10371048
{
1049+
// Ensure there's proper Prefab and context menu handling for the list as a whole.
1050+
// This ensures a deleted element in the list is displayed as an override and can
1051+
// be handled by the user via the context menu. Case 1292522
1052+
if (m_Elements != null)
1053+
EditorGUI.BeginProperty(headerRect, GUIContent.none, m_Elements);
1054+
10381055
recursionCounter = 0;
10391056
// draw the background on repaint
10401057
if (showDefaultBackground && Event.current.type == EventType.Repaint)
@@ -1051,6 +1068,9 @@ private void DoListHeader(Rect headerRect)
10511068
drawHeaderCallback(headerRect);
10521069
else if (m_DisplayHeader)
10531070
defaultBehaviours.DrawHeader(headerRect, m_SerializedObject, m_Elements, m_ElementList);
1071+
1072+
if (m_Elements != null)
1073+
EditorGUI.EndProperty();
10541074
}
10551075

10561076
private void DoListFooter(Rect footerRect)
@@ -1070,7 +1090,7 @@ private void DoDraggingAndSelection(Rect listRect)
10701090
switch (evt.GetTypeForControl(id))
10711091
{
10721092
case EventType.KeyDown:
1073-
if (GUIUtility.keyboardControl != id)
1093+
if (GUIUtility.keyboardControl != id || m_Dragging || clicked)
10741094
return;
10751095
// if we have keyboard focus, arrow through the list
10761096
if (evt.keyCode == KeyCode.DownArrow)
@@ -1083,6 +1103,42 @@ private void DoDraggingAndSelection(Rect listRect)
10831103
index -= 1;
10841104
evt.Use();
10851105
}
1106+
if (evt.keyCode == KeyCode.LeftArrow)
1107+
{
1108+
if (m_Elements != null)
1109+
{
1110+
foreach (var index in m_Selection)
1111+
{
1112+
if (index < 0) continue;
1113+
1114+
m_Elements.GetArrayElementAtIndex(index).isExpanded = false;
1115+
}
1116+
}
1117+
InvalidateParentCaches(m_PropertyPath);
1118+
GUI.changed = true;
1119+
evt.Use();
1120+
}
1121+
if (evt.keyCode == KeyCode.RightArrow)
1122+
{
1123+
if (m_Elements != null)
1124+
{
1125+
foreach (var index in selectedIndices)
1126+
{
1127+
if (index < 0) continue;
1128+
1129+
m_Elements.GetArrayElementAtIndex(index).isExpanded = true;
1130+
}
1131+
}
1132+
InvalidateParentCaches(m_PropertyPath);
1133+
GUI.changed = true;
1134+
evt.Use();
1135+
}
1136+
if (evt.keyCode == KeyCode.Delete)
1137+
{
1138+
scheduleRemove = true;
1139+
InvalidateParentCaches(m_PropertyPath);
1140+
evt.Use();
1141+
}
10861142
if (evt.keyCode == KeyCode.Escape && GUIUtility.hotControl == id)
10871143
{
10881144
GUIUtility.hotControl = 0;
@@ -1092,7 +1148,7 @@ private void DoDraggingAndSelection(Rect listRect)
10921148
if (evt.type == EventType.Used)
10931149
{
10941150
// don't allow arrowing through the ends of the list
1095-
index = Mathf.Clamp(index, 0, (m_Elements != null) ? m_Elements.arraySize - 1 : m_ElementList.Count - 1);
1151+
m_Selection = m_Selection.Where(i => i >= 0 && i < (m_Elements != null ? m_Elements.arraySize : m_ElementList.Count)).ToList();
10961152
}
10971153
break;
10981154

@@ -1172,6 +1228,7 @@ private void DoDraggingAndSelection(Rect listRect)
11721228
break;
11731229

11741230
case EventType.MouseUp:
1231+
clicked = false;
11751232
if (!m_Draggable)
11761233
{
11771234
// if mouse up was on the same index as mouse down we fire a mouse up callback (useful if for beginning renaming on mouseup)

Editor/Mono/GUI/SearchField.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public string OnGUI(Rect rect, string text, GUIStyle style, GUIStyle cancelButto
6161
buttonRect.width = cancelButtonWidth;
6262
if (Event.current.type == EventType.MouseUp && buttonRect.Contains(Event.current.mousePosition))
6363
{
64-
text = "";
64+
text = string.Empty;
6565
GUIUtility.keyboardControl = 0;
6666
}
6767

@@ -70,7 +70,7 @@ public string OnGUI(Rect rect, string text, GUIStyle style, GUIStyle cancelButto
7070
text = EditorGUI.TextFieldInternal(m_ControlID, textRect, text, style);
7171

7272
GUI.Button(buttonRect, GUIContent.none,
73-
text != "" ? cancelButtonStyle : emptyCancelButtonStyle);
73+
!string.IsNullOrEmpty(text) ? cancelButtonStyle : emptyCancelButtonStyle);
7474
return text;
7575
}
7676

0 commit comments

Comments
 (0)