Skip to content

Commit e97cf48

Browse files
author
Unity Technologies
committed
Unity 2019.3.0f3 C# reference source code
1 parent 3ad5f77 commit e97cf48

File tree

83 files changed

+1109
-562
lines changed

Some content is hidden

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

83 files changed

+1109
-562
lines changed

Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using Object = UnityEngine.Object;
1414

1515
using TangentMode = UnityEditor.AnimationUtility.TangentMode;
16-
using CurveModifiedType = UnityEditor.AnimationUtility.CurveModifiedType;
1716

1817
namespace UnityEditorInternal
1918
{
@@ -859,10 +858,14 @@ public static float GetPreviousKeyframeTime(AnimationWindowCurve[] curves, float
859858
{
860859
foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
861860
{
862-
if (keyframe.time > candidate && keyframe.time <= previousTime.time)
861+
AnimationKeyTime keyTime = AnimationKeyTime.Time(keyframe.time, frameRate);
862+
if (keyTime.frame == previousTime.frame)
863863
{
864-
candidate = keyframe.time;
865-
found = true;
864+
if (keyTime.time > candidate)
865+
{
866+
candidate = keyTime.time;
867+
found = true;
868+
}
866869
}
867870
}
868871
}

Editor/Mono/Animation/ZoomableArea.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,11 @@ void SliderGUI()
753753
}
754754
min = shownXMin;
755755
max = shownXMin + shownXRange;
756+
float rectWidthWithinMargins = GetWidthInsideMargins(rect.width, true);
756757
if (min > area.xMin)
757-
min = Mathf.Min(min, max - rect.width / m_HScaleMax);
758+
min = Mathf.Min(min, max - rectWidthWithinMargins / m_HScaleMax);
758759
if (max < area.xMax)
759-
max = Mathf.Max(max, min + rect.width / m_HScaleMax);
760+
max = Mathf.Max(max, min + rectWidthWithinMargins / m_HScaleMax);
760761
SetShownHRangeInsideMargins(min, max);
761762
}
762763

@@ -787,10 +788,11 @@ void SliderGUI()
787788
}
788789
min = -(shownYMin + shownYRange);
789790
max = -shownYMin;
791+
float rectHeightWithinMargins = GetHeightInsideMargins(rect.height, true);
790792
if (min > area.yMin)
791-
min = Mathf.Min(min, max - rect.height / m_VScaleMax);
793+
min = Mathf.Min(min, max - rectHeightWithinMargins / m_VScaleMax);
792794
if (max < area.yMax)
793-
max = Mathf.Max(max, min + rect.height / m_VScaleMax);
795+
max = Mathf.Max(max, min + rectHeightWithinMargins / m_VScaleMax);
794796
SetShownVRangeInsideMargins(min, max);
795797
}
796798
else
@@ -816,10 +818,11 @@ void SliderGUI()
816818
}
817819
min = shownYMin;
818820
max = shownYMin + shownYRange;
821+
float rectHeightWithinMargins = GetHeightInsideMargins(rect.height, true);
819822
if (min > area.yMin)
820-
min = Mathf.Min(min, max - rect.height / m_VScaleMax);
823+
min = Mathf.Min(min, max - rectHeightWithinMargins / m_VScaleMax);
821824
if (max < area.yMax)
822-
max = Mathf.Max(max, min + rect.height / m_VScaleMax);
825+
max = Mathf.Max(max, min + rectHeightWithinMargins / m_VScaleMax);
823826
SetShownVRangeInsideMargins(min, max);
824827
}
825828
}

Editor/Mono/ContainerWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ private void DragTitleBar(Rect titleBarRect)
446446
// If the mouse is inside the title bar rect, we say that we're the hot control
447447
if (titleBarRect.Contains(evt.mousePosition) && GUIUtility.hotControl == 0 && evt.button == 0)
448448
{
449-
if (Application.platform == RuntimePlatform.WindowsEditor)
449+
if (Application.platform != RuntimePlatform.LinuxEditor)
450450
{
451451
Event.current.Use();
452452
m_DraggingNativeTitleBarCaption = true;

Editor/Mono/EditorGUI.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ internal static Rect GetInspectorTitleBarObjectFoldoutRenderRect(Rect rect)
13821382

13831383
internal static Rect GetInspectorTitleBarObjectFoldoutRenderRect(Rect rect, GUIStyle baseStyle)
13841384
{
1385-
return new Rect(rect.x + EditorStyles.foldout.margin.left + 1f, rect.y + (rect.height - kInspTitlebarFoldoutIconWidth) / 2 + (baseStyle != null ? baseStyle.padding.top : 0), kInspTitlebarFoldoutIconWidth, kInspTitlebarFoldoutIconWidth);
1385+
return new Rect(rect.x + EditorStyles.titlebarFoldout.margin.left + 1f, rect.y + (rect.height - kInspTitlebarFoldoutIconWidth) / 2 + (baseStyle != null ? baseStyle.padding.top : 0), kInspTitlebarFoldoutIconWidth, kInspTitlebarFoldoutIconWidth);
13861386
}
13871387

13881388
[SuppressMessage("ReSharper", "RedundantCast.0")]
@@ -1551,7 +1551,7 @@ private static void DoObjectFoldoutInternal(bool foldout, Rect renderRect, int i
15511551
{
15521552
case EventType.Repaint:
15531553
bool isPressed = GUIUtility.hotControl == id;
1554-
EditorStyles.foldout.Draw(renderRect, isPressed, isPressed, foldout, false);
1554+
EditorStyles.titlebarFoldout.Draw(renderRect, isPressed, isPressed, foldout, false);
15551555
break;
15561556
}
15571557

@@ -5200,7 +5200,7 @@ internal static bool ToggleTitlebar(Rect position, GUIContent label, bool foldou
52005200

52015201
GUIStyle baseStyle = EditorStyles.inspectorTitlebar;
52025202
GUIStyle textStyle = EditorStyles.inspectorTitlebarText;
5203-
GUIStyle foldoutStyle = EditorStyles.foldout;
5203+
GUIStyle foldoutStyle = EditorStyles.titlebarFoldout;
52045204

52055205
Rect toggleRect = new Rect(position.x + baseStyle.padding.left, position.y + baseStyle.padding.top, kInspTitlebarIconWidth, kInspTitlebarIconWidth);
52065206
Rect textRect = new Rect(toggleRect.xMax + kInspTitlebarSpacing, toggleRect.y, 200, kInspTitlebarIconWidth);
@@ -5248,7 +5248,7 @@ internal static bool FoldoutTitlebar(Rect position, GUIContent label, bool foldo
52485248

52495249
break;
52505250
case EventType.Repaint:
5251-
GUIStyle foldoutStyle = EditorStyles.foldout;
5251+
GUIStyle foldoutStyle = EditorStyles.titlebarFoldout;
52525252
Rect textRect =
52535253
new Rect(
52545254
position.x + baseStyle.padding.left +

Editor/Mono/EditorMode/ModeService.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,15 @@ private static void LoadModes(bool checkStartupMode = false)
294294
}
295295

296296
SetModeIndex(currentModeIndex);
297-
EditorApplication.delayCall += () => RaiseModeChanged(-1, currentIndex);
297+
298+
EditorApplication.update -= DelayRaiseCurrentModeChanged;
299+
EditorApplication.update += DelayRaiseCurrentModeChanged;
300+
}
301+
302+
private static void DelayRaiseCurrentModeChanged()
303+
{
304+
EditorApplication.update -= DelayRaiseCurrentModeChanged;
305+
RaiseModeChanged(-1, currentIndex);
298306
}
299307

300308
private static void FillModeData(string path, Dictionary<string, object> modesData)
@@ -336,9 +344,9 @@ internal static void ScanModes()
336344
{
337345
searchArea = SearchFilter.SearchArea.InPackagesOnly,
338346
classNames = new[] { nameof(ModeDescriptor) },
339-
skipHidden = true,
340347
showAllHits = true
341348
});
349+
342350
while (modeDescriptors.MoveNext())
343351
{
344352
var md = modeDescriptors.Current.pptrValue as ModeDescriptor;
@@ -360,6 +368,15 @@ internal static void ScanModes()
360368
hasSwitchableModes |= !JsonUtils.JsonReadBoolean(modeFields, "builtin");
361369
modeIndex++;
362370
}
371+
372+
Array.Sort(modes, (m1, m2) =>
373+
{
374+
if (m1.id == "default")
375+
return -1;
376+
if (m2.id == "default")
377+
return 1;
378+
return m1.id.CompareTo(m2.id);
379+
});
363380
}
364381

365382
private static ModeEntry CreateEntry(string modeId, JSONObject data)

Editor/Mono/EditorResources.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ private static bool CanEnableExtendedStyles()
139139

140140
private static bool IsEditorStyleSheet(string path)
141141
{
142-
var pathLowerCased = path.ToLower();
143-
return pathLowerCased.Contains("/stylesheets/extensions/") && (pathLowerCased.EndsWith("common.uss") ||
144-
pathLowerCased.EndsWith(EditorGUIUtility.isProSkin ? "dark.uss" : "light.uss"));
142+
return path.IndexOf("/stylesheets/extensions/", StringComparison.OrdinalIgnoreCase) != -1 &&
143+
(path.EndsWith("common.uss", StringComparison.OrdinalIgnoreCase) || path.EndsWith(EditorGUIUtility.isProSkin ? "dark.uss" : "light.uss", StringComparison.OrdinalIgnoreCase));
145144
}
146145

147146
internal static string GetDefaultFont()
@@ -275,7 +274,7 @@ internal static void BuildCatalog()
275274
s_RefreshGlobalStyleCatalog = false;
276275

277276
var paths = GetDefaultStyleCatalogPaths();
278-
foreach (var editorUssPath in AssetDatabase.GetAllAssetPaths().Where(IsEditorStyleSheet))
277+
foreach (var editorUssPath in AssetDatabase.FindAssets("t:StyleSheet").Select(AssetDatabase.GUIDToAssetPath).Where(IsEditorStyleSheet))
279278
paths.Add(editorUssPath);
280279

281280
Console.WriteLine($"Building style catalogs ({paths.Count})\r\n\t{String.Join("\r\n\t", paths.ToArray())}");

Editor/Mono/GUI/EditorStyles.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public sealed class EditorStyles
150150
public static GUIStyle foldout { get { return s_Current.m_Foldout; } }
151151
private GUIStyle m_Foldout;
152152

153+
internal static GUIStyle titlebarFoldout { get { return s_Current.m_TitlebarFoldout; } }
154+
private GUIStyle m_TitlebarFoldout;
155+
153156
// Style used for headings for EditorGUI::ref::Foldout.
154157
public static GUIStyle foldoutPreDrop { get { return s_Current.m_FoldoutPreDrop; } }
155158
private GUIStyle m_FoldoutPreDrop;
@@ -477,6 +480,7 @@ private void InitSharedStyles()
477480
m_ToggleMixed = GetStyle("ToggleMixed");
478481
m_ColorField = GetStyle("ColorField");
479482
m_Foldout = GetStyle("Foldout");
483+
m_TitlebarFoldout = GetStyle("Titlebar Foldout");
480484
m_FoldoutSelected = GUIStyle.none;
481485
m_IconButton = GetStyle("IconButton");
482486
m_TextFieldDropDown = GetStyle("TextFieldDropDown");

Editor/Mono/GUI/PackageImportTreeView.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,6 @@ override public void OnRowGUI(Rect rowRect, TreeViewItem tvItem, int row, bool s
383383
GUI.Label(labelRect, Constants.badgeNew, Constants.paddinglessStyle);
384384
}
385385

386-
// 5. Optional badge ("Delete")
387-
if (repainting && projectAsset)
388-
{
389-
// FIXME: Need to enable tooltips here.
390-
Texture badge = Constants.badgeDelete.image;
391-
Rect labelRect = new Rect(rowRect.xMax - badge.width - 6, rowRect.y + (rowRect.height - badge.height) / 2, badge.width, badge.height);
392-
GUI.Label(labelRect, Constants.badgeDelete, Constants.paddinglessStyle);
393-
}
394-
395386
// 7. Show what stuff has changed
396387
if (repainting && validItem && (exists || pathConflict) && assetChanged)
397388
{

Editor/Mono/GUI/TreeView/LazyTreeViewDataSource.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace UnityEditor.IMGUI.Controls
1818

1919
internal abstract class LazyTreeViewDataSource : TreeViewDataSource
2020
{
21+
static readonly List<TreeViewItem> s_ChildListForCollapsedParent = new List<TreeViewItem>();
22+
2123
public LazyTreeViewDataSource(TreeViewController treeView)
2224
: base(treeView)
2325
{
@@ -27,7 +29,13 @@ public static List<TreeViewItem> CreateChildListForCollapsedParent()
2729
{
2830
// To mark a collapsed parent we use a list with one element that is null.
2931
// The null element in the children list ensures we show the collapse arrow.
30-
return new List<TreeViewItem>() { null };
32+
// Reuse read-only list to prevent allocations.
33+
if (s_ChildListForCollapsedParent.Count != 1 || s_ChildListForCollapsedParent[0] != null)
34+
{
35+
s_ChildListForCollapsedParent.Clear();
36+
s_ChildListForCollapsedParent.Add(null);
37+
}
38+
return s_ChildListForCollapsedParent;
3139
}
3240

3341
public static bool IsChildListForACollapsedParent(IList<TreeViewItem> childList)

Editor/Mono/GUI/TreeView/TreeViewGUI.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ public float k_LineHeight
3333
get
3434
{
3535
if (m_LineHeight < 0)
36-
return new SVC<float>("--treeview-line-height", 16f);
37-
else return m_LineHeight;
36+
m_LineHeight = new SVC<float>("--treeview-line-height", 16f);
37+
38+
return m_LineHeight;
3839
}
3940
set { m_LineHeight = value; }
4041
}
@@ -409,7 +410,7 @@ float GetFoldoutYPosition(float rectY)
409410
protected virtual Rect DoFoldout(Rect rect, TreeViewItem item, int row)
410411
{
411412
float indent = GetFoldoutIndent(item);
412-
Rect foldoutRect = new Rect(rect.x + indent, GetFoldoutYPosition(rect.y), foldoutStyleWidth, EditorGUIUtility.singleLineHeight);
413+
Rect foldoutRect = new Rect(rect.x + indent, GetFoldoutYPosition(rect.y), foldoutStyleWidth, k_LineHeight);
413414
FoldoutButton(foldoutRect, item, row, foldoutStyle);
414415
return foldoutRect;
415416
}

0 commit comments

Comments
 (0)