Skip to content

Commit 3f0dae7

Browse files
author
Unity Technologies
committed
Unity 2023.1.0a2 C# reference source code
1 parent 667dd8b commit 3f0dae7

File tree

194 files changed

+11193
-3200
lines changed

Some content is hidden

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

194 files changed

+11193
-3200
lines changed

Editor/Mono/2D/SpriteAtlas/SpriteAtlasImporterInspector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ protected override void Apply()
412412
base.Apply();
413413
}
414414

415+
protected override bool useAssetDrawPreview { get { return false; } }
416+
415417
protected void PackPreviewGUI()
416418
{
417419
EditorGUILayout.Space();

Editor/Mono/AssemblyValidation.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Globalization;
88
using System.IO;
9+
using System.Linq;
910
using System.Runtime.InteropServices;
1011
using Mono.Cecil;
1112
using UnityEditor.Scripting.ScriptCompilation;
@@ -195,14 +196,14 @@ public static bool PluginCompatibleWithEditor(string path)
195196
return pluginImporter.GetCompatibleWithEditor();
196197
}
197198

198-
public static bool ShouldValidateReferences(string path)
199+
public static bool ShouldValidateReferences(string path,
200+
Dictionary<string, PrecompiledAssembly> allPrecompiledAssemblies)
199201
{
200-
var pluginImporter = AssetImporter.GetAtPath(path) as PluginImporter;
201202

202-
if (pluginImporter == null)
203+
if (!allPrecompiledAssemblies.TryGetValue(path, out var precompiledAssembly))
203204
return true;
204205

205-
return pluginImporter.ValidateReferences;
206+
return precompiledAssembly.Flags.HasFlag(AssemblyFlags.ValidateAssembly);
206207
}
207208

208209
public static void PrintAssemblyDefinitions(AssemblyDefinition[] assemblyDefinitions)
@@ -289,6 +290,11 @@ public static void CheckAssemblyReferences(string[] assemblyPaths,
289290
};
290291
}
291292

293+
var precompiledAssemblies = EditorCompilationInterface.Instance
294+
.PrecompiledAssemblyProvider.GetAllPrecompiledAssemblies()
295+
.Where(x => x.Flags.HasFlag(AssemblyFlags.UserAssembly));
296+
var allPrecompiledAssemblies = precompiledAssemblies.ToDictionary(x => AssetPath.ReplaceSeparators(x.Path));
297+
292298
for (int i = 0; i < assemblyPaths.Length; ++i)
293299
{
294300
if (errors[i].HasFlag(ErrorFlags.IncompatibleWithEditor))
@@ -298,7 +304,7 @@ public static void CheckAssemblyReferences(string[] assemblyPaths,
298304

299305
// Check if "Validate References" option is enabled
300306
// in the PluginImporter
301-
if (!ShouldValidateReferences(assemblyPath))
307+
if (!ShouldValidateReferences(AssetPath.ReplaceSeparators(assemblyPath), allPrecompiledAssemblies))
302308
continue;
303309

304310
ResolveAndSetupReferences(i,

Editor/Mono/Audio/Mixer/GUI/TreeViewForAudioMixerGroups.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public override void FetchData()
243243
List<int> allowedInstanceIDs = ObjectSelector.get.allowedInstanceIDs;
244244

245245
var controllers = new List<AudioMixerController>();
246-
foreach (var prop in AssetDatabase.FindAllAssets(new SearchFilter() { classNames = new[] { "AudioMixerController" } }))
246+
foreach (var prop in AssetDatabase.FindAllAssets(new SearchFilter() { classNames = new[] { "AudioMixerController" }, searchArea = SearchFilter.SearchArea.AllAssets }))
247247
{
248248
var controller = prop.pptrValue as AudioMixerController;
249249
if (ShouldShowController(controller, allowedInstanceIDs))

Editor/Mono/CodeEditor/CodeEditor.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public struct Installation
3131
private Installation m_CurrentInstallation;
3232
internal const string SystemDefaultPath = "";
3333

34-
public IExternalCodeEditor CurrentCodeEditor {
34+
public IExternalCodeEditor CurrentCodeEditor
35+
{
3536
get
3637
{
37-
if(m_CurrentEditor == m_DefaultEditor && !IsCurrentEditorPathExplicitlySet)
38+
if (m_CurrentEditor == m_DefaultEditor && !IsCurrentEditorPathExplicitlySet)
3839
{
3940
// try to resolve first found visual studio installation and enable it
4041
try
@@ -46,7 +47,7 @@ public IExternalCodeEditor CurrentCodeEditor {
4647
SetCodeEditor(installs[0].Path);
4748
}
4849
}
49-
catch(Exception ex)
50+
catch (Exception ex)
5051
{
5152
Debug.LogWarning($"Can't locate Visual Studio installation: {ex.Message}");
5253
}
@@ -234,7 +235,7 @@ public static bool OSOpenFile(string appPath, string arguments)
234235
public static string ParseArgument(string arguments, string path, int line, int column)
235236
{
236237
var newArgument = arguments.Replace("$(ProjectPath)", QuoteForProcessStart(Directory.GetParent(Application.dataPath).FullName));
237-
newArgument = newArgument.Replace("$(File)", QuoteForProcessStart(path));
238+
newArgument = newArgument.Replace("$(File)", string.IsNullOrEmpty(path) ? "" : QuoteForProcessStart(path));
238239
newArgument = newArgument.Replace("$(Line)", line >= 0 ? line.ToString() : "0");
239240
newArgument = newArgument.Replace("$(Column)", column >= 0 ? column.ToString() : "0");
240241
return newArgument;

Editor/Mono/ConsoleWindow.cs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ internal class ConsoleWindow : EditorWindow, IHasCustomMenu
2929
private static Font m_MonospaceFont;
3030
private static int m_DefaultFontSize;
3131
private static List<MethodInfo> s_MethodsToHideInCallstack = null;
32-
private static Dictionary<HideInCallstackGenericMethodKey, Regex> s_GenericMethodSignatureRegex = null;
33-
34-
internal struct HideInCallstackGenericMethodKey
35-
{
36-
internal string namespaceName;
37-
internal string className;
38-
internal string methodName;
39-
}
32+
private static Dictionary<MethodInfo, Regex> s_GenericMethodSignatureRegex = null;
4033

4134
//TODO: move this out of here
4235
internal class Constants
@@ -908,7 +901,7 @@ internal static string StacktraceWithHyperlinks(string stacktraceText, int calls
908901
return textWithHyperlinks.ToString();
909902
}
910903

911-
internal static string GetCallstackFormattedSignatureFromGenericMethod(Dictionary<HideInCallstackGenericMethodKey, Regex> methodSignatureRegex, MethodInfo method, string line)
904+
internal static string GetCallstackFormattedSignatureFromGenericMethod(Dictionary<MethodInfo, Regex> methodSignatureRegex, MethodInfo method, string line)
912905
{
913906
if (string.IsNullOrEmpty(line) || method == null || methodSignatureRegex == null)
914907
return null;
@@ -917,14 +910,7 @@ internal static string GetCallstackFormattedSignatureFromGenericMethod(Dictionar
917910
if (classType == null)
918911
return null;
919912

920-
var ns = classType.Namespace;
921-
var key = new HideInCallstackGenericMethodKey()
922-
{
923-
namespaceName = ns,
924-
className = classType.Name,
925-
methodName = method.Name
926-
};
927-
if (!methodSignatureRegex.TryGetValue(key, out Regex regex))
913+
if (!methodSignatureRegex.TryGetValue(method, out Regex regex))
928914
return null;
929915

930916
if (regex == null)
@@ -1004,7 +990,7 @@ internal static string GetCallstackFormattedScriptingExceptionSignature(MethodIn
1004990
return sb.ToString();
1005991
}
1006992

1007-
internal static string[] StripCallstack(Mode mode, Dictionary<HideInCallstackGenericMethodKey, Regex> methodSignatureRegex, List<MethodInfo> methodsToHideInCallstack, string[] lines)
993+
internal static string[] StripCallstack(Mode mode, Dictionary<MethodInfo, Regex> methodSignatureRegex, List<MethodInfo> methodsToHideInCallstack, string[] lines)
1008994
{
1009995
if (methodsToHideInCallstack == null || methodSignatureRegex == null || lines == null)
1010996
return lines;
@@ -1140,14 +1126,14 @@ private static void OnStripLoggingCallstackButtonValueChange()
11401126
SetFlag(ConsoleFlags.StripLoggingCallstack, s_StripLoggingCallstack);
11411127
}
11421128

1143-
internal static (List<MethodInfo>, Dictionary<HideInCallstackGenericMethodKey, Regex>) InitializeHideInCallstackMethodsCache()
1129+
internal static (List<MethodInfo>, Dictionary<MethodInfo, Regex>) InitializeHideInCallstackMethodsCache()
11441130
{
11451131
var methods = TypeCache.GetMethodsWithAttribute<HideInCallstackAttribute>();
11461132
if (methods.Count == 0)
11471133
return (null, null);
11481134

11491135
var methodsToHideInCallstack = new List<MethodInfo>();
1150-
var genericMethodSignatureRegexes = new Dictionary<HideInCallstackGenericMethodKey, Regex>();
1136+
var genericMethodSignatureRegexes = new Dictionary<MethodInfo, Regex>();
11511137
foreach (var method in methods)
11521138
{
11531139
methodsToHideInCallstack.Add(method);
@@ -1161,13 +1147,8 @@ internal static (List<MethodInfo>, Dictionary<HideInCallstackGenericMethodKey, R
11611147
var pattern = $"{(string.IsNullOrEmpty(ns) ? "" : $@"({ns})\.")}(" + classType.Name +
11621148
@")\:(" + method.Name + @")([^\(]*)\s*\(([^\)]+)\)";
11631149
var regex = new Regex(pattern, RegexOptions.Compiled);
1164-
var key = new HideInCallstackGenericMethodKey()
1165-
{
1166-
namespaceName = ns,
1167-
className = classType.Name,
1168-
methodName = method.Name
1169-
};
1170-
genericMethodSignatureRegexes.Add(key, regex);
1150+
if (!genericMethodSignatureRegexes.TryAdd(method, regex))
1151+
continue;
11711152
}
11721153
}
11731154

Editor/Mono/EditorGUI.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,11 +2972,10 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
29722972

29732973
Object targetObject = property.serializedObject.targetObject;
29742974

2975-
var shouldDisplayPrefabContextMenuItems = property.prefabOverride || (linkedProperty?.prefabOverride ?? false);
2975+
bool shouldDisplayPrefabContextMenuItems = property.prefabOverride || (linkedProperty?.prefabOverride ?? false);
29762976

29772977
// Only display the custom apply/revert menu for GameObjects/Components that are not part of a Prefab instance & variant.
2978-
var shouldDisplayApplyRevertProviderContextMenuItems = targetObject is IApplyRevertPropertyContextMenuItemProvider
2979-
&& PrefabUtility.HasApplicableObjectOverrides(targetObject, false);
2978+
var shouldDisplayApplyRevertProviderContextMenuItems = targetObject is IApplyRevertPropertyContextMenuItemProvider;
29802979

29812980
if (shouldDisplayPrefabContextMenuItems || shouldDisplayApplyRevertProviderContextMenuItems)
29822981
{

Editor/Mono/EditorUserBuildSettings.deprecated.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,29 @@ internal static void Internal_ActiveBuildTargetChanged()
3232
[Obsolete("forceOptimizeScriptCompilation is obsolete - will always return false. Control script optimization using the 'IL2CPP optimization level' configuration in Player Settings / Other.")]
3333
public static bool forceOptimizeScriptCompilation { get { return false; } }
3434

35-
[Obsolete(@"androidDebugMinification is obsolete. Use PlayerSettings.Android.minifyDebug and PlayerSettings.Android.minifyWithR8.")]
35+
[Obsolete(@"androidDebugMinification is obsolete. Use PlayerSettings.Android.minifyDebug")]
3636
public static AndroidMinification androidDebugMinification
3737
{
3838
get
3939
{
40-
if (PlayerSettings.Android.minifyDebug)
41-
{
42-
return PlayerSettings.Android.minifyWithR8 ? AndroidMinification.Gradle : AndroidMinification.Proguard;
43-
}
44-
return AndroidMinification.None;
40+
return PlayerSettings.Android.minifyDebug ? AndroidMinification.Gradle : AndroidMinification.None;
4541
}
4642
set
4743
{
4844
PlayerSettings.Android.minifyDebug = value != AndroidMinification.None;
49-
PlayerSettings.Android.minifyWithR8 = value == AndroidMinification.Gradle;
5045
}
5146
}
5247

53-
[Obsolete(@"androidReleaseMinification is obsolete. Use PlayerSettings.Android.minifyRelease and PlayerSettings.Android.minifyWithR8.")]
48+
[Obsolete(@"androidReleaseMinification is obsolete. Use PlayerSettings.Android.minifyRelease")]
5449
public static AndroidMinification androidReleaseMinification
5550
{
5651
get
5752
{
58-
if (PlayerSettings.Android.minifyRelease)
59-
{
60-
return PlayerSettings.Android.minifyWithR8 ? AndroidMinification.Gradle : AndroidMinification.Proguard;
61-
}
62-
return AndroidMinification.None;
53+
return PlayerSettings.Android.minifyRelease ? AndroidMinification.Gradle : AndroidMinification.None;
6354
}
6455
set
6556
{
6657
PlayerSettings.Android.minifyRelease = value != AndroidMinification.None;
67-
PlayerSettings.Android.minifyWithR8 = value == AndroidMinification.Gradle;
6858
}
6959
}
7060
}

Editor/Mono/EditorWindow.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ static public EditorWindow focusedWindow
408408
}
409409
}
410410

411+
static public Action focusedWindowChanged;
412+
411413
// The EditorWindow currently under the mouse cursor (RO)
412414
static public EditorWindow mouseOverWindow
413415
{
@@ -1223,6 +1225,13 @@ private void OnDisableINTERNAL()
12231225
SaveViewDataToDisk();
12241226
}
12251227

1228+
internal void ReleaseViewData()
1229+
{
1230+
SaveViewDataToDisk();
1231+
DestroyImmediate(m_ViewDataDictionary);
1232+
m_ViewDataDictionary = null;
1233+
}
1234+
12261235
// Internal stuff:
12271236
// Helper to show this EditorWindow
12281237
internal static void CreateNewWindowForEditorWindow(EditorWindow window, bool loadPosition, bool showImmediately, bool setFocus = true)

Editor/Mono/GUI/AppStatusBar.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ protected override void OldOnGUI()
168168
{
169169
GUILayout.Space(2);
170170
DrawStatusText();
171-
GUILayout.FlexibleSpace();
171+
172+
if(EditorPrefs.GetBool("EnableHelperBar", false)) ShortcutManagement.HelperWindow.StatusBarShortcuts();
173+
else GUILayout.FlexibleSpace();
174+
172175
if (m_DrawExtraFeatures)
173176
DrawSpecialModeLabel();
174177
DrawProgressBar();
@@ -437,8 +440,10 @@ private GUILayoutOption GetStatusTextLayoutOption(float consoleIconWidth)
437440
{
438441
int iconWidth = 25;
439442
float specialModeLabelWidth = Styles.statusLabel.CalcSize(new GUIContent(m_SpecialModeLabel)).x + k_SpaceBeforeProgress + 8;
443+
float helperBarWidth = (EditorPrefs.GetBool("EnableHelperBar", false) ? ShortcutManagement.HelperWindow.kHelperBarMinWidth : 0);
440444
float statusRightReservedSpace =
441445
specialModeLabelWidth +
446+
helperBarWidth + // helper bar
442447
iconWidth + // script debugger
443448
iconWidth + // cache server
444449
(showBakeMode ? iconWidth : 0) + // bake

Editor/Mono/GUI/Tools/EditorToolUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ internal static EditorTool GetEditorToolWithEnum(Tool type, EditorToolContext ct
135135
// Tool types can resolve to either global or instance tools
136136
if (IsComponentTool(resolved))
137137
{
138-
var instance = EditorToolManager.GetComponentTool(resolved);
138+
var instance = EditorToolManager.GetComponentTool(resolved, true);
139139
if (instance == null)
140140
{
141141
Debug.LogError($"{context} resolved Tool.{type} to a Component tool of type `{resolved}`, but " +

0 commit comments

Comments
 (0)