Skip to content

Commit 9832fc8

Browse files
author
Unity Technologies
committed
Unity 2020.1.0a21 C# reference source code
1 parent 8f0f22c commit 9832fc8

File tree

104 files changed

+2716
-1431
lines changed

Some content is hidden

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

104 files changed

+2716
-1431
lines changed

Editor/Mono/Animation/ZoomableArea.cs

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -923,31 +923,41 @@ public void SetTransform(Vector2 newTranslation, Vector2 newScale)
923923

924924
public void EnforceScaleAndRange()
925925
{
926-
// Minimum scale might also be constrained by maximum range
927-
float constrainedHScaleMin = rect.width / m_HScaleMin;
928-
float constrainedVScaleMin = rect.height / m_VScaleMin;
929-
if (hRangeMax != Mathf.Infinity && hRangeMin != Mathf.NegativeInfinity)
930-
constrainedHScaleMin = Mathf.Min(constrainedHScaleMin, hRangeMax - hRangeMin);
931-
if (vRangeMax != Mathf.Infinity && vRangeMin != Mathf.NegativeInfinity)
932-
constrainedVScaleMin = Mathf.Min(constrainedVScaleMin, vRangeMax - vRangeMin);
933-
934926
Rect oldArea = m_LastShownAreaInsideMargins;
935927
Rect newArea = shownAreaInsideMargins;
936928
if (newArea == oldArea)
937929
return;
938930

939-
float epsilon = 0.00001f;
940931
float minChange = 0.01f;
941932

942933
if (!Mathf.Approximately(newArea.width, oldArea.width))
943934
{
944-
float constrainedValue = newArea.width < oldArea.width - epsilon ? rect.width / m_HScaleMax : constrainedHScaleMin;
945-
constrainedValue = GetWidthInsideMargins(constrainedValue, true);
946-
float xLerp = Mathf.InverseLerp(oldArea.width, newArea.width, constrainedValue);
935+
float constrainedWidth = newArea.width;
936+
if (newArea.width < oldArea.width)
937+
{
938+
// The shown area decreasing in size means the scale is increasing. This happens e.g. while zooming in.
939+
// Only the max scale restricts the shown area size here, range has no influence.
940+
constrainedWidth = GetWidthInsideMargins(drawRect.width / m_HScaleMax, false);
941+
}
942+
else
943+
{
944+
constrainedWidth = GetWidthInsideMargins(drawRect.width / m_HScaleMin, false);
945+
946+
if (hRangeMax != Mathf.Infinity && hRangeMin != Mathf.NegativeInfinity)
947+
{
948+
// range only has an influence if it is enforced, i.e. not infinity
949+
float denum = hRangeMax - hRangeMin;
950+
if (denum < kMinWidth) denum = kMinWidth;
951+
952+
constrainedWidth = Mathf.Min(constrainedWidth, denum);
953+
}
954+
}
955+
956+
float xLerp = Mathf.InverseLerp(oldArea.width, newArea.width, constrainedWidth);
947957
float newWidth = Mathf.Lerp(oldArea.width, newArea.width, xLerp);
948958
float widthChange = Mathf.Abs(newWidth - newArea.width);
949959
newArea = new Rect(
950-
// only affect the position if there was any significant change in width (the unit is in pixels so technically anything under 0.05f would already be impossible to see)
960+
// only affect the position if there was any significant change in width
951961
// this fixes an issue where if width was only different due to rounding issues, position changes are ignored as xLerp comes back 0 (or very nearly 0)
952962
widthChange > minChange ? Mathf.Lerp(oldArea.x, newArea.x, xLerp) : newArea.x,
953963
newArea.y,
@@ -957,14 +967,32 @@ public void EnforceScaleAndRange()
957967
}
958968
if (!Mathf.Approximately(newArea.height, oldArea.height))
959969
{
960-
float constrainedValue = newArea.height < oldArea.height - epsilon ? rect.height / m_VScaleMax : constrainedVScaleMin;
961-
constrainedValue = GetHeightInsideMargins(constrainedValue, true);
962-
float yLerp = Mathf.InverseLerp(oldArea.height, newArea.height, constrainedValue);
970+
float constrainedHeight = newArea.height;
971+
if (newArea.height < oldArea.height)
972+
{
973+
// The shown area decreasing in size means the scale is increasing. This happens e.g. while zooming in.
974+
// Only the max scale restricts the shown area size here, range has no influence.
975+
constrainedHeight = GetHeightInsideMargins(drawRect.height / m_VScaleMax, false);
976+
}
977+
else
978+
{
979+
constrainedHeight = GetHeightInsideMargins(drawRect.height / m_VScaleMin, false);
980+
981+
if (vRangeMax != Mathf.Infinity && vRangeMin != Mathf.NegativeInfinity)
982+
{
983+
// range only has an influence if it is enforced, i.e. not infinity
984+
float denum = vRangeMax - vRangeMin;
985+
if (denum < kMinHeight) denum = kMinHeight;
986+
constrainedHeight = Mathf.Min(constrainedHeight, denum);
987+
}
988+
}
989+
990+
float yLerp = Mathf.InverseLerp(oldArea.height, newArea.height, constrainedHeight);
963991
float newHeight = Mathf.Lerp(oldArea.height, newArea.height, yLerp);
964992
float heightChange = Mathf.Abs(newHeight - newArea.height);
965993
newArea = new Rect(
966994
newArea.x,
967-
// only affect the position if there was any significant change in height (the unit is in pixels so technically anything under 0.05f would already be impossible to see)
995+
// only affect the position if there was any significant change in height
968996
// this fixes an issue where if height was only different due to rounding issues, position changes are ignored as yLerp comes back 0 (or very nearly 0)
969997
heightChange > minChange ? Mathf.Lerp(oldArea.y, newArea.y, yLerp) : newArea.y,
970998
newArea.width,
@@ -983,7 +1011,7 @@ public void EnforceScaleAndRange()
9831011
newArea.y = vRangeMax - newArea.height;
9841012

9851013
shownAreaInsideMarginsInternal = newArea;
986-
m_LastShownAreaInsideMargins = newArea;
1014+
m_LastShownAreaInsideMargins = shownAreaInsideMargins;
9871015
}
9881016

9891017
public float PixelToTime(float pixelX, Rect rect)

Editor/Mono/Annotation/SceneViewCameraWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void Init()
4848
const int k_HeaderSpacing = 2;
4949
// FOV values chosen to be the smallest and largest before extreme visual corruption
5050
const float k_MinFieldOfView = 4f;
51-
const float k_MaxFieldOfView = 160f;
51+
const float k_MaxFieldOfView = 120f;
5252

5353
Vector2 m_WindowSize;
5454
Vector2 m_Scroll;

Editor/Mono/Collab/CollabEditorHooks.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,12 @@ public static Texture2D LoadTextureFromApplicationContents(string path)
177177

178178
try
179179
{
180-
var fs = File.OpenRead(path);
181-
var bytes = new byte[fs.Length];
182-
fs.Read(bytes, 0, (int)fs.Length);
183-
if (!tex.LoadImage(bytes)) return null;
180+
using (var fs = File.OpenRead(path))
181+
{
182+
var bytes = new byte[fs.Length];
183+
fs.Read(bytes, 0, (int)fs.Length);
184+
if (!tex.LoadImage(bytes)) return null;
185+
}
184186
}
185187
catch (Exception)
186188
{

Editor/Mono/Commands/GOCreationCommands.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ static void CreateEmptyChild(MenuCommand menuCommand)
6363
parent = activeGO;
6464
}
6565

66+
// If selected GameObject is a Sub Scene header, place GameObject in active scene
67+
// similar to what happens when other scene headers are selected.
68+
SceneHierarchyHooks.SubSceneInfo info = SubSceneGUI.GetSubSceneInfo(parent);
69+
if (info.isValid)
70+
parent = null;
71+
6672
var go = ObjectFactory.CreateGameObject("GameObject");
6773
Place(go, parent);
6874
}

Editor/Mono/ContainerWindow.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)
127127
// Show the editor window.
128128
public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately, bool setFocus)
129129
{
130+
bool useMousePos = showMode == ShowMode.AuxWindow;
130131
if (showMode == ShowMode.AuxWindow)
131132
showMode = ShowMode.Utility;
132133

@@ -138,9 +139,12 @@ public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately,
138139
// Load previous position/size
139140
if (!isPopup)
140141
Load(loadPosition);
142+
if (useMousePos)
143+
LoadInCurrentMousePosition();
141144

142145
var initialMaximizedState = m_Maximized;
143146

147+
144148
Internal_Show(m_PixelRect, m_ShowMode, m_MinSize, m_MaxSize);
145149

146150
// Tell the main view its now in this window (quick hack to get platform-specific code to move its views to the right window)
@@ -157,7 +161,7 @@ public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately,
157161
return;
158162

159163
// Fit window to screen - needs to be done after bringing the window live
160-
position = FitWindowRectToScreen(m_PixelRect, true, false);
164+
position = FitWindowRectToScreen(m_PixelRect, true, useMousePos);
161165
rootView.position = new Rect(0, 0, Mathf.Ceil(m_PixelRect.width), Mathf.Ceil(m_PixelRect.height));
162166

163167
rootView.Reflow();
@@ -291,6 +295,16 @@ internal void LoadGeometry(bool loadPosition)
291295
m_PixelRect = p;
292296
}
293297

298+
internal void LoadInCurrentMousePosition()
299+
{
300+
Vector2 mousePos = Editor.GetCurrentMousePosition();
301+
302+
Rect p = m_PixelRect;
303+
p.x = mousePos.x;
304+
p.y = mousePos.y;
305+
m_PixelRect = p;
306+
}
307+
294308
private void Load(bool loadPosition)
295309
{
296310
if (!IsMainWindow() && IsNotDocked())

Editor/Mono/EditorGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7811,7 +7811,7 @@ internal static GUIContent[] GetEnumTypeLocalizedGUIContents(Type enumType, Enum
78117811

78127812
internal static GUIContent[] GetEnumLocalizedGUIContents(SerializedProperty property)
78137813
{
7814-
var propertyHash = property.hashCodeForPropertyPath;
7814+
var propertyHash = property.hashCodeForPropertyPathWithoutArrayIndex;
78157815
GUIContent[] result;
78167816
if (s_SerializedPropertyEnumLocalizedGUIContents.TryGetValue(propertyHash, out result))
78177817
{

Editor/Mono/EditorSceneManager.bindings.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ namespace UnityEditor.SceneManagement
1616
[NativeHeader("Editor/Mono/EditorSceneManager.bindings.h")]
1717
public sealed partial class EditorSceneManager : SceneManager
1818
{
19+
[StaticAccessor("GetSceneManager()", StaticAccessorType.Dot)]
20+
[NativeMethod("IsReloading")]
21+
public extern static bool IsReloading(Scene scene);
22+
1923
public extern static int loadedSceneCount
2024
{
2125
[StaticAccessor("GetSceneManager()", StaticAccessorType.Dot)]
2226
[NativeMethod("GetLoadedSceneCount")]
2327
get;
2428
}
2529

30+
public extern static int loadedRootSceneCount
31+
{
32+
[StaticAccessor("GetSceneManager()", StaticAccessorType.Dot)]
33+
[NativeMethod("GetLoadedRootSceneCount")]
34+
get;
35+
}
36+
2637
public extern static int previewSceneCount
2738
{
2839
[StaticAccessor("GetSceneManager()", StaticAccessorType.Dot)]

Editor/Mono/GUI/AppStatusBar.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Globalization;
7+
using System.Linq;
78
using UnityEngine;
89
using UnityEngine.Scripting;
910

@@ -82,7 +83,7 @@ private bool showProgress
8283
{
8384
get
8485
{
85-
return Progress.IsRunning && m_LastElapsedTime > 1.5f;
86+
return Progress.running && m_LastElapsedTime > 0.5f;
8687
}
8788
}
8889

@@ -92,16 +93,16 @@ protected override void OnEnable()
9293
s_AppStatusBar = this;
9394
m_ManagedDebuggerToggle = new ManagedDebuggerToggle();
9495

95-
Progress.OnAdded += RefreshProgressBar;
96-
Progress.OnRemoved += RefreshProgressBar;
97-
Progress.OnUpdated += RefreshProgressBar;
96+
Progress.added += RefreshProgressBar;
97+
Progress.removed += RefreshProgressBar;
98+
Progress.updated += RefreshProgressBar;
9899
}
99100

100101
protected override void OnDisable()
101102
{
102-
Progress.OnAdded -= RefreshProgressBar;
103-
Progress.OnRemoved -= RefreshProgressBar;
104-
Progress.OnUpdated -= RefreshProgressBar;
103+
Progress.added -= RefreshProgressBar;
104+
Progress.removed -= RefreshProgressBar;
105+
Progress.updated -= RefreshProgressBar;
105106
base.OnDisable();
106107
}
107108

@@ -127,7 +128,7 @@ private void DelayCheckProgressUnresponsive()
127128

128129
private void CheckProgressUnresponsive()
129130
{
130-
if (Progress.IsRunning)
131+
if (Progress.running)
131132
{
132133
var progressItem = Progress.GetProgressById(m_LastProgressId);
133134
if (progressItem != null && !progressItem.responding)
@@ -227,7 +228,7 @@ private void DrawProgressBar()
227228
var fade = Mathf.Min(Mathf.Max(0.25f, Mathf.Cos((float)EditorApplication.timeSinceStartup * 2.0f) / 2.0f + 0.75f), 0.85f);
228229
GUI.color = new Color(fade, fade, fade);
229230
}
230-
var globalProgress = Progress.GlobalProgress;
231+
var globalProgress = Progress.globalProgress;
231232
var progressBarStyle = GetProgressBarStyle(globalProgress);
232233
var progressBarContent = GetProgressBarContent(globalProgress, m_ProgressPercentageStatus);
233234
var progressRect = EditorGUILayout.GetControlRect(false, position.height, Styles.progressBarBack, Styles.progressBarWidth);
@@ -323,7 +324,7 @@ private void DrawStatusText()
323324
GUILayout.EndVertical();
324325
}
325326

326-
private void RefreshProgressBar(ProgressItem[] progressItems)
327+
private void RefreshProgressBar(Progress.Item[] progressItems)
327328
{
328329
var taskCount = Progress.GetRunningProgressCount();
329330
if (taskCount == 0)
@@ -339,14 +340,18 @@ private void RefreshProgressBar(ProgressItem[] progressItems)
339340
var currentItem = progressItems[0];
340341
if (!String.IsNullOrEmpty(currentItem.description))
341342
m_ProgressStatus.tooltip = currentItem.name + "\r\n" + currentItem.description;
342-
m_ProgressPercentageStatus.text = Progress.GlobalProgress.ToString("P", percentageFormat);
343+
m_ProgressPercentageStatus.text = Progress.globalProgress.ToString("P", percentageFormat);
343344

344-
if (taskCount > 1)
345+
var remainingTimeText = "";
346+
if (Progress.EnumerateItems().Any(item => item.timeDisplayMode == Progress.TimeDisplayMode.ShowRemainingTime) && Progress.EnumerateItems().All(item => !item.indefinite) && Progress.globalRemainingTime.TotalSeconds > 0)
345347
{
346-
m_ProgressStatus.text = $"Multiple tasks ({taskCount})";
348+
remainingTimeText = $" [{Progress.globalRemainingTime:g}]";
347349
}
350+
351+
if (taskCount > 1)
352+
m_ProgressStatus.text = $"Multiple tasks ({taskCount}){remainingTimeText}";
348353
else
349-
m_ProgressStatus.text = currentItem.name;
354+
m_ProgressStatus.text = $"{currentItem.name}{remainingTimeText}";
350355

351356

352357
m_LastProgressId = currentItem.id;
@@ -369,13 +374,13 @@ private void RefreshProgressBar(ProgressItem[] progressItems)
369374
RepaintProgress(progressItems);
370375
}
371376

372-
private void RepaintProgress(ProgressItem[] progressItems)
377+
private void RepaintProgress(Progress.Item[] progressItems)
373378
{
374379
bool hasSynchronous = false;
375380
bool hasIndefinite = false;
376381
foreach (var item in progressItems)
377382
{
378-
if ((item.options & ProgressOptions.Synchronous) == ProgressOptions.Synchronous)
383+
if ((item.options & Progress.Options.Synchronous) == Progress.Options.Synchronous)
379384
{
380385
hasSynchronous = true;
381386
break;

Editor/Mono/GUI/ReorderableList.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,11 @@ public int count
384384
int smallerArraySize = m_Elements.arraySize;
385385
foreach (Object targetObject in m_Elements.serializedObject.targetObjects)
386386
{
387-
SerializedObject serializedObject = new SerializedObject(targetObject);
388-
SerializedProperty property = serializedObject.FindProperty(m_Elements.propertyPath);
389-
smallerArraySize = Math.Min(property.arraySize, smallerArraySize);
387+
using (SerializedObject serializedObject = new SerializedObject(targetObject))
388+
{
389+
SerializedProperty property = serializedObject.FindProperty(m_Elements.propertyPath);
390+
smallerArraySize = Math.Min(property.arraySize, smallerArraySize);
391+
}
390392
}
391393
return smallerArraySize;
392394
}

Editor/Mono/GUI/Toolbar.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ static class Styles
3333

3434

3535
[SerializeField]
36-
List<EditorToolbar> m_LoadedToolbars = new List<EditorToolbar>();
36+
List<EditorToolbar> m_LoadedToolbars;
3737

3838
internal EditorToolbar GetSingleton(Type type)
3939
{
40+
if (m_LoadedToolbars == null)
41+
m_LoadedToolbars = new List<EditorToolbar>();
4042
m_LoadedToolbars = m_LoadedToolbars.Where(x => x != null).ToList();
4143
var res = m_LoadedToolbars.FirstOrDefault(x => x.GetType() == type);
4244
if (res != null)
@@ -65,11 +67,10 @@ internal EditorToolbar mainToolbar
6567

6668
if (m_MainToolbar != null)
6769
{
68-
m_MainToolbar.m_Parent = this;
69-
70-
70+
m_MainToolbar.m_Parent = null;
7171
if (m_MainToolbar.rootVisualElement != null)
7272
m_MainToolbar.rootVisualElement.RemoveFromHierarchy();
73+
DestroyImmediate(m_MainToolbar);
7374
}
7475

7576
m_MainToolbar = value == null ? GetSingleton(k_DefaultToolbarType) : value;

0 commit comments

Comments
 (0)