Skip to content

Commit dee28cd

Browse files
author
Unity Technologies
committed
Unity 2021.1.0a7 C# reference source code
1 parent 234186e commit dee28cd

File tree

398 files changed

+10445
-4513
lines changed

Some content is hidden

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

398 files changed

+10445
-4513
lines changed

Editor/Mono/AssetDatabase/AssetDatabase.deprecated.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public struct CacheServerConnectionChangedParameters
137137
public extern static UInt32 UnregisterCustomDependencyPrefixFilter(string prefixFilter);
138138

139139
[FreeFunction("AssetDatabase::IsAssetImportProcess")]
140-
[Obsolete("AssetDatabaseExperimental.IsAssetImportWorkerProcess() has been deprecated. Use AssetDatabase.IsAssetImportWorkerProcess()", false)]
140+
[Obsolete("AssetDatabaseExperimental.IsAssetImportWorkerProcess() has been deprecated. Use AssetDatabase.IsAssetImportWorkerProcess() instead (UnityUpgradable) -> UnityEditor.AssetDatabase.IsAssetImportWorkerProcess(*)", false)]
141141
public extern static bool IsAssetImportWorkerProcess();
142142

143143
[Obsolete("Has been replaced by AssetDatabaseExperimental.RefreshSettings", true)]

Editor/Mono/AssetPipeline/TextureImporterEnums.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,27 +295,28 @@ public enum TextureImporterSingleChannelComponent
295295
public enum TextureImporterType
296296
{
297297
Default = 0,
298-
[System.Obsolete("Use Default (UnityUpgradable) -> Default")]
299-
Image = 0,
300-
[System.Obsolete("Use NormalMap (UnityUpgradable) -> NormalMap")]
301-
Bump = 1,
302298
NormalMap = 1,
303299
GUI = 2,
304300
Sprite = 8,
305301
Cursor = 7,
306-
[System.Obsolete("Use importer.textureShape = TextureImporterShape.TextureCube")]
307-
Cubemap = 3,
308-
[System.Obsolete("Use a texture setup as a cubemap with glossy reflection instead")]
309-
Reflection = 3,
310302
Cookie = 4,
311303
Lightmap = 6,
312-
[System.Obsolete("HDRI is not supported anymore")]
313-
HDRI = 9,
314-
[System.Obsolete("Use Default instead. All texture types now have an Advanced foldout (UnityUpgradable) -> Default")]
315-
Advanced = 5,
316304
SingleChannel = 10,
317305
Shadowmask = 11,
318306
DirectionalLightmap = 12,
307+
308+
[System.Obsolete("Use Default (UnityUpgradable) -> Default", true)]
309+
Image = Int32.MinValue,
310+
[System.Obsolete("Use NormalMap (UnityUpgradable) -> NormalMap", true)]
311+
Bump = -1,
312+
[System.Obsolete("Use importer.textureShape = TextureImporterShape.TextureCube", true)]
313+
Cubemap = -3,
314+
[System.Obsolete("Use a texture setup as a cubemap with glossy reflection instead", true)]
315+
Reflection = -3,
316+
[System.Obsolete("Use Default instead. All texture types now have an Advanced foldout (UnityUpgradable) -> Default", true)]
317+
Advanced = -5,
318+
[System.Obsolete("HDRI is not supported anymore", true)]
319+
HDRI = -9,
319320
}
320321

321322
public enum TextureImporterCompression

Editor/Mono/BuildPipeline.bindings.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public enum BuildAssetBundleOptions
176176
AssetBundleStripUnityVersion = 32768 // 1 << 15
177177
}
178178

179+
// Keep in sync with CanAppendBuild in EditorUtility.h
180+
public enum CanAppendBuild
181+
{
182+
Unsupported = 0,
183+
Yes = 1,
184+
No = 2,
185+
}
186+
179187
public struct AssetBundleBuild
180188
{
181189
public string assetBundleName;
@@ -261,6 +269,9 @@ private static void LogBuildExceptionAndExit(string buildFunctionName, System.Ex
261269
EditorApplication.Exit(1);
262270
}
263271

272+
[FreeFunction]
273+
public extern static CanAppendBuild BuildCanBeAppended(BuildTarget target, string location);
274+
264275
public static BuildReport BuildPlayer(EditorBuildSettingsScene[] levels, string locationPathName, BuildTarget target, BuildOptions options)
265276
{
266277
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
@@ -302,10 +313,10 @@ private static BuildReport BuildPlayer(string[] scenes, string locationPathName,
302313

303314
if ((options & BuildOptions.AcceptExternalModificationsToPlayer) == BuildOptions.AcceptExternalModificationsToPlayer)
304315
{
305-
UnityEditorInternal.CanAppendBuild canAppend = UnityEditorInternal.InternalEditorUtility.BuildCanBeAppended(target, locationPathName);
306-
if (canAppend == UnityEditorInternal.CanAppendBuild.Unsupported)
316+
CanAppendBuild canAppend = BuildCanBeAppended(target, locationPathName);
317+
if (canAppend == CanAppendBuild.Unsupported)
307318
throw new InvalidOperationException("The build target does not support build appending.");
308-
if (canAppend == UnityEditorInternal.CanAppendBuild.No)
319+
if (canAppend == CanAppendBuild.No)
309320
throw new InvalidOperationException("The build cannot be appended.");
310321
}
311322

Editor/Mono/BuildPipeline/Il2Cpp/Il2CppNativeCodeBuilderUtils.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ namespace UnityEditorInternal
1212
{
1313
public static class Il2CppNativeCodeBuilderUtils
1414
{
15+
public static string GetConfigurationName(Il2CppCompilerConfiguration compilerConfiguration)
16+
{
17+
// In IL2CPP, Master config is called "ReleasePlus"
18+
return compilerConfiguration != Il2CppCompilerConfiguration.Master ? compilerConfiguration.ToString() : "ReleasePlus";
19+
}
20+
1521
public static IEnumerable<string> AddBuilderArguments(Il2CppNativeCodeBuilder builder, string outputRelativePath, IEnumerable<string> includeRelativePaths, IEnumerable<string> additionalLibs, Il2CppCompilerConfiguration compilerConfiguration)
1622
{
1723
var arguments = new List<string>();
@@ -21,10 +27,7 @@ public static IEnumerable<string> AddBuilderArguments(Il2CppNativeCodeBuilder bu
2127
arguments.Add("--libil2cpp-static");
2228
arguments.Add(FormatArgument("platform", builder.CompilerPlatform));
2329
arguments.Add(FormatArgument("architecture", builder.CompilerArchitecture));
24-
25-
// In IL2CPP, Master config is called "ReleasePlus"
26-
string configurationName = compilerConfiguration != Il2CppCompilerConfiguration.Master ? compilerConfiguration.ToString() : "ReleasePlus";
27-
arguments.Add(FormatArgument("configuration", configurationName));
30+
arguments.Add(FormatArgument("configuration", GetConfigurationName(compilerConfiguration)));
2831

2932
arguments.Add(FormatArgument("outputpath", builder.ConvertOutputFileToFullPath(outputRelativePath)));
3033

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ private static void GUIBuildButtons(IBuildWindowExtension buildWindowExtension,
941941
}
942942
GUILayout.BeginHorizontal();
943943
GUILayout.FlexibleSpace();
944-
if (EditorGUILayout.LinkLabel(styles.learnAboutUnityCloudBuild))
944+
if (EditorGUILayout.LinkButton(styles.learnAboutUnityCloudBuild))
945945
{
946946
Application.OpenURL(string.Format("{0}/from/editor/buildsettings?upid={1}&pid={2}&currentplatform={3}&selectedplatform={4}&unityversion={5}",
947947
UnityEditorInternal.WebURLs.cloudBuildPage, CloudProjectSettings.projectId, PlayerSettings.productGUID, EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettingsUtils.CalculateSelectedBuildTarget(), Application.unityVersion));

Editor/Mono/BuildPlayerWindowBuildMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ internal static BuildPlayerOptions GetBuildPlayerOptionsInternal(bool askForBuil
279279

280280
if (!askForBuildLocation)
281281
{
282-
switch (UnityEditorInternal.InternalEditorUtility.BuildCanBeAppended(buildTarget, newLocation))
282+
switch (BuildPipeline.BuildCanBeAppended(buildTarget, newLocation))
283283
{
284284
case CanAppendBuild.Unsupported:
285285
break;

Editor/Mono/Commands/CommandService.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Linq;
9+
using System.Reflection;
910
using UnityEngine;
1011
using UnityEngine.Internal;
1112

@@ -67,7 +68,7 @@ public class CommandExecuteContext
6768

6869
public T GetArgument<T>(int index, T defaultValue = default(T))
6970
{
70-
if (0 < index || index >= args.Length)
71+
if (index < 0 || index >= args.Length)
7172
throw new ArgumentOutOfRangeException(nameof(index));
7273
return (T)args[index];
7374
}
@@ -149,22 +150,22 @@ public static object Execute(string id, CommandHint hint, params object[] args)
149150
private static IEnumerable<Command> ScanAttributes()
150151
{
151152
var commands = new List<Command>();
152-
var commandAttributes = AttributeHelper.GetMethodsWithAttribute<CommandHandlerAttribute>();
153-
foreach (var method in commandAttributes.methodsWithAttributes)
153+
foreach (var mi in TypeCache.GetMethodsWithAttribute<CommandHandlerAttribute>())
154154
{
155-
var callback = Delegate.CreateDelegate(typeof(CommandHandler), method.info) as CommandHandler;
156-
if (callback == null)
155+
if (!(Delegate.CreateDelegate(typeof(CommandHandler), mi) is CommandHandler callback))
157156
continue;
158-
var attr = (CommandHandlerAttribute)method.attribute;
159157

160-
if (commands.Any(c => c.id == attr.id))
158+
foreach (var attr in mi.GetCustomAttributes<CommandHandlerAttribute>())
161159
{
162-
Debug.LogWarning($"There is already a command with the ID {attr.id}. " +
163-
"Commands need to have a unique ID, i.e. \"Unity/Category/Command_42\".");
164-
continue;
160+
if (commands.Any(c => c.id == attr.id))
161+
{
162+
Debug.LogWarning($"There is already a command with the ID {attr.id}. " +
163+
"Commands need to have a unique ID, i.e. \"Unity/Category/Command_42\".");
164+
continue;
165+
}
166+
167+
commands.Add(new Command { id = attr.id, label = attr.label ?? attr.id, hint = attr.hint, handler = callback, managed = true });
165168
}
166-
167-
commands.Add(new Command {id = attr.id, label = attr.label ?? attr.id, hint = attr.hint, handler = callback, managed = true});
168169
}
169170

170171
return commands;

Editor/Mono/ConsoleWindow.cs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ private static void UpdateLogStyleFixedHeights()
129129

130130
Vector2 m_TextScroll = Vector2.zero;
131131

132+
int m_LastActiveEntryIndex = -1;
133+
bool m_RestoreLatestSelection;
134+
132135
//Make sure the minimum height of the panels can accomodate the cpmplete scroll bar icons
133136
SplitterState spl = SplitterState.FromRelative(new float[] {70, 30}, new float[] {60, 60}, null);
134137

@@ -557,7 +560,10 @@ internal void OnGUI()
557560
bool setErrorFlag = GUILayout.Toggle(HasFlag(ConsoleFlags.LogLevelError), new GUIContent((errorCount <= 999 ? errorCount.ToString() : "999+"), errorCount > 0 ? iconErrorSmall : iconErrorMono), Constants.MiniButtonRight);
558561
// Active entry index may no longer be valid
559562
if (EditorGUI.EndChangeCheck())
563+
{
560564
SetActiveEntry(null);
565+
m_LastActiveEntryIndex = -1;
566+
}
561567

562568
SetFlag(ConsoleFlags.LogLevelLog, setLogFlag);
563569
SetFlag(ConsoleFlags.LogLevelWarning, setWarningFlag);
@@ -578,11 +584,27 @@ internal void OnGUI()
578584
int selectedRow = -1;
579585
bool openSelectedItem = false;
580586
bool collapsed = HasFlag(ConsoleFlags.Collapse);
587+
float scrollPosY = m_ListView.scrollPos.y;
588+
581589
foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, ListViewOptions.wantsRowMultiSelection, Constants.Box))
582590
{
591+
// Destroy latest restore entry if needed
592+
if (e.type == EventType.ScrollWheel || e.type == EventType.Used)
593+
DestroyLatestRestoreEntry();
594+
595+
// Make sure that scrollPos.y is always up to date after restoring last entry
596+
if (m_RestoreLatestSelection)
597+
{
598+
m_ListView.scrollPos.y = scrollPosY;
599+
}
600+
583601
if (e.type == EventType.MouseDown && e.button == 0 && el.position.Contains(e.mousePosition))
584602
{
585603
selectedRow = m_ListView.row;
604+
DestroyLatestRestoreEntry();
605+
LogEntry entry = new LogEntry();
606+
LogEntries.GetEntryInternal(m_ListView.row, entry);
607+
m_LastActiveEntryIndex = entry.globalLineIndex;
586608
if (e.clickCount == 2)
587609
openSelectedItem = true;
588610
}
@@ -663,21 +685,28 @@ internal void OnGUI()
663685
if (m_ListView.totalRows == 0 || m_ListView.row >= m_ListView.totalRows || m_ListView.row < 0)
664686
{
665687
if (m_ActiveText.Length != 0)
688+
{
666689
SetActiveEntry(null);
690+
DestroyLatestRestoreEntry();
691+
}
667692
}
668693
else
669694
{
670695
LogEntry entry = new LogEntry();
671696
LogEntries.GetEntryInternal(m_ListView.row, entry);
672697
SetActiveEntry(entry);
698+
m_LastActiveEntryIndex = entry.globalLineIndex;
699+
673700

674701
// see if selected entry changed. if so - clear additional info
675702
LogEntries.GetEntryInternal(m_ListView.row, entry);
676703
if (m_ListView.selectionChanged || !m_ActiveText.Equals(entry.message))
677704
{
678705
SetActiveEntry(entry);
706+
m_LastActiveEntryIndex = entry.globalLineIndex;
679707
}
680708

709+
681710
// If copy, get the messages from selected rows
682711
if (e.type == EventType.ExecuteCommand && e.commandName == EventCommandNames.Copy && m_ListView.selectedItems != null)
683712
{
@@ -751,13 +780,16 @@ private void SearchField(Event e)
751780
}
752781

753782
string searchText = m_SearchText;
783+
754784
if (e.type == EventType.KeyDown)
755785
{
756786
if (e.keyCode == KeyCode.Escape)
757787
{
758788
searchText = string.Empty;
759789
GUIUtility.keyboardControl = m_ListView.ID;
760790
Repaint();
791+
if (!String.IsNullOrEmpty(m_SearchText))
792+
RestoreLastActiveEntry();
761793
}
762794
else if ((e.keyCode == KeyCode.UpArrow || e.keyCode == KeyCode.DownArrow) &&
763795
GUI.GetNameOfFocusedControl() == searchBarName)
@@ -941,6 +973,7 @@ private void AddStackTraceLoggingMenu(GenericMenu menu)
941973

942974
private void SetFilter(string filteringText)
943975
{
976+
m_RestoreLatestSelection = String.IsNullOrEmpty(filteringText) && !String.IsNullOrEmpty(m_SearchText) && m_LastActiveEntryIndex != -1;
944977
if (filteringText == null)
945978
{
946979
m_SearchText = "";
@@ -951,7 +984,38 @@ private void SetFilter(string filteringText)
951984
m_SearchText = filteringText;
952985
LogEntries.SetFilteringText(filteringText); // Reset the active entry when we change the filtering text
953986
}
954-
SetActiveEntry(null);
987+
988+
if (m_RestoreLatestSelection)
989+
{
990+
RestoreLastActiveEntry();
991+
}
992+
else
993+
{
994+
SetActiveEntry(null);
995+
DestroyLatestRestoreEntry();
996+
}
997+
}
998+
999+
void RestoreLastActiveEntry()
1000+
{
1001+
int rowIndex = LogEntries.GetEntryRowIndex(m_LastActiveEntryIndex);
1002+
if (rowIndex != -1)
1003+
{
1004+
ShowConsoleRow(rowIndex);
1005+
m_ListView.selectedItems = new bool[rowIndex + 1];
1006+
m_ListView.selectedItems[rowIndex] = true;
1007+
m_ListView.scrollPos.y = rowIndex * m_ListView.rowHeight;
1008+
}
1009+
else
1010+
{
1011+
SetActiveEntry(null);
1012+
}
1013+
}
1014+
1015+
void DestroyLatestRestoreEntry()
1016+
{
1017+
m_LastActiveEntryIndex = -1;
1018+
m_RestoreLatestSelection = false;
9551019
}
9561020

9571021
[UsedImplicitly] private static event EntryDoubleClickedDelegate entryWithManagedCallbackDoubleClicked;

0 commit comments

Comments
 (0)