Skip to content

Commit b1dc88d

Browse files
author
Unity Technologies
committed
Unity 2019.1.0a6 C# reference source code
1 parent 1af97d8 commit b1dc88d

199 files changed

Lines changed: 6641 additions & 3549 deletions

File tree

Some content is hidden

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public override void OnInspectorGUI()
313313
{
314314
if (GUILayout.Button(s_Styles.disabledPackLabel, EditorStyles.helpBox))
315315
{
316-
SettingsWindow.OpenProjectSettings("Project/Editor");
316+
SettingsService.OpenProjectSettings("Project/Editor");
317317
}
318318
}
319319

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModuleBaseView.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ private void AddMainUI(VisualElement mainView)
200200
if (hasSelected)
201201
{
202202
var border = selectedSpriteBorder;
203-
border.y = evt.newValue;
203+
border.w = evt.newValue;
204204
selectedSpriteBorder = border;
205-
m_BorderFieldT.SetValueWithoutNotify((long)selectedSpriteBorder.y);
205+
m_BorderFieldT.SetValueWithoutNotify((long)selectedSpriteBorder.w);
206206
evt.StopPropagation();
207207
}
208208
});
@@ -225,9 +225,9 @@ private void AddMainUI(VisualElement mainView)
225225
if (hasSelected)
226226
{
227227
var border = selectedSpriteBorder;
228-
border.w = evt.newValue;
228+
border.y = evt.newValue;
229229
selectedSpriteBorder = border;
230-
m_BorderFieldB.SetValueWithoutNotify((long)selectedSpriteBorder.w);
230+
m_BorderFieldB.SetValueWithoutNotify((long)selectedSpriteBorder.y);
231231
}
232232
});
233233

@@ -335,9 +335,9 @@ protected void PopulateSpriteFrameInspectorField()
335335
m_PositionFieldH.SetValueWithoutNotify(Mathf.RoundToInt(spriteRect.height));
336336
var spriteBorder = selectedSpriteBorder;
337337
m_BorderFieldL.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.x));
338-
m_BorderFieldT.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.y));
338+
m_BorderFieldT.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.w));
339339
m_BorderFieldR.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.z));
340-
m_BorderFieldB.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.w));
340+
m_BorderFieldB.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.y));
341341
m_PivotField.SetValueWithoutNotify(selectedSpriteAlignment);
342342
m_PivotUnitModeField.SetValueWithoutNotify(m_PivotUnitMode);
343343
Vector2 pivot = selectedSpritePivotInCurUnitMode;

Editor/Mono/Animation/AnimationWindow/CurveEditor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public CurveWrapper()
5151
setAxisUiScalarsCallback = null;
5252
}
5353

54+
// Fix for case 1086532 - Audio source inspector leaks memory
55+
~CurveWrapper()
56+
{
57+
if (m_Renderer != null)
58+
m_Renderer.FlushCache();
59+
}
60+
5461
internal enum SelectionMode
5562
{
5663
None = 0,

Editor/Mono/AssemblyHelper.cs

Lines changed: 128 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using UnityEditor.Modules;
1212
using UnityEditorInternal;
1313
using UnityEngine;
14+
using System.Runtime.InteropServices;
15+
using UnityEngine.Scripting;
1416

1517
namespace UnityEditor
1618
{
@@ -317,30 +319,48 @@ public static void ExtractAllClassesThatAreUserExtendedScripts(string path, out
317319
originalClassNameSpacesArray = originalNamespaces.ToArray();
318320
}
319321

322+
struct GetAssemblyResolverData
323+
{
324+
public IAssemblyResolver Resolver;
325+
public string[] SearchDirs;
326+
}
327+
328+
static GetAssemblyResolverData GetAssemblyResolver(BuildTarget targetPlatform, bool isEditor, string assemblyPathName, string[] searchDirs)
329+
{
330+
var target = ModuleManager.GetTargetStringFromBuildTarget(targetPlatform);
331+
var extension = ModuleManager.GetCompilationExtension(target);
332+
var extraPaths = extension.GetCompilerExtraAssemblyPaths(isEditor, assemblyPathName);
333+
if (extraPaths != null && extraPaths.Length > 0)
334+
{
335+
var dirs = new List<string>(searchDirs);
336+
dirs.AddRange(extraPaths);
337+
searchDirs = dirs.ToArray();
338+
}
339+
340+
var assemblyResolver = extension.GetAssemblyResolver(isEditor, assemblyPathName, searchDirs);
341+
342+
return new GetAssemblyResolverData
343+
{
344+
Resolver = assemblyResolver,
345+
SearchDirs = searchDirs
346+
};
347+
}
348+
320349
/// Extract information about all types in the specified assembly, searchDirs might be used to resolve dependencies.
321350
static public AssemblyTypeInfoGenerator.ClassInfo[] ExtractAssemblyTypeInfo(BuildTarget targetPlatform, bool isEditor, string assemblyPathName, string[] searchDirs)
322351
{
323352
try
324353
{
325-
var target = ModuleManager.GetTargetStringFromBuildTarget(targetPlatform);
326-
var extension = ModuleManager.GetCompilationExtension(target);
327-
var extraPaths = extension.GetCompilerExtraAssemblyPaths(isEditor, assemblyPathName);
328-
if (extraPaths != null && extraPaths.Length > 0)
329-
{
330-
var dirs = new List<string>(searchDirs);
331-
dirs.AddRange(extraPaths);
332-
searchDirs = dirs.ToArray();
333-
}
334-
var assemblyResolver = extension.GetAssemblyResolver(isEditor, assemblyPathName, searchDirs);
354+
var assemblyResolverData = GetAssemblyResolver(targetPlatform, isEditor, assemblyPathName, searchDirs);
335355

336356
AssemblyTypeInfoGenerator gen;
337-
if (assemblyResolver == null)
357+
if (assemblyResolverData.Resolver == null)
338358
{
339-
gen = new AssemblyTypeInfoGenerator(assemblyPathName, searchDirs);
359+
gen = new AssemblyTypeInfoGenerator(assemblyPathName, assemblyResolverData.SearchDirs);
340360
}
341361
else
342362
{
343-
gen = new AssemblyTypeInfoGenerator(assemblyPathName, assemblyResolver);
363+
gen = new AssemblyTypeInfoGenerator(assemblyPathName, assemblyResolverData.Resolver);
344364
}
345365

346366
return gen.GatherClassInfo();
@@ -351,6 +371,101 @@ static public AssemblyTypeInfoGenerator.ClassInfo[] ExtractAssemblyTypeInfo(Buil
351371
}
352372
}
353373

374+
[StructLayout(LayoutKind.Sequential)]
375+
public struct RuntimeInitializeOnLoadMethodsData
376+
{
377+
public RuntimeInitializeClassInfo[] classInfos;
378+
public int methodsCount;
379+
}
380+
381+
static void FindRuntimeInitializeOnLoadMethodAttributes(TypeDefinition type,
382+
string assemblyName,
383+
ref List<RuntimeInitializeClassInfo> classInfoList,
384+
ref int methodCount)
385+
{
386+
if (!type.HasMethods)
387+
return;
388+
389+
foreach (var method in type.Methods)
390+
{
391+
// RuntimeInitializeOnLoadMethod only works on static methods.
392+
if (!method.IsStatic)
393+
continue;
394+
395+
foreach (var attribute in method.CustomAttributes)
396+
{
397+
if (attribute.AttributeType.FullName == "UnityEngine.RuntimeInitializeOnLoadMethodAttribute")
398+
{
399+
RuntimeInitializeLoadType loadType = RuntimeInitializeLoadType.AfterSceneLoad;
400+
401+
if (attribute.ConstructorArguments != null && attribute.ConstructorArguments.Count > 0)
402+
loadType = (RuntimeInitializeLoadType)attribute.ConstructorArguments[0].Value;
403+
404+
RuntimeInitializeClassInfo classInfo = new RuntimeInitializeClassInfo();
405+
406+
classInfo.assemblyName = assemblyName;
407+
classInfo.className = type.FullName;
408+
classInfo.methodNames = new[] { method.Name };
409+
classInfo.loadTypes = new[] { loadType };
410+
classInfoList.Add(classInfo);
411+
methodCount++;
412+
}
413+
}
414+
}
415+
}
416+
417+
[RequiredByNativeCode]
418+
public static RuntimeInitializeOnLoadMethodsData ExtractPlayerRuntimeInitializeOnLoadMethods(BuildTarget targetPlatform, string[] assemblyPaths, string[] searchDirs)
419+
{
420+
var classInfoList = new List<RuntimeInitializeClassInfo>();
421+
int methodCount = 0;
422+
423+
foreach (var assemblyPath in assemblyPaths)
424+
{
425+
try
426+
{
427+
var assemblyResolverData = GetAssemblyResolver(targetPlatform, false, assemblyPath, searchDirs);
428+
429+
if (assemblyResolverData.Resolver == null)
430+
{
431+
var resolver = new DefaultAssemblyResolver();
432+
foreach (var searchDir in searchDirs)
433+
resolver.AddSearchDirectory(searchDir);
434+
435+
assemblyResolverData.Resolver = resolver;
436+
}
437+
438+
var assembly = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters
439+
{
440+
AssemblyResolver = assemblyResolverData.Resolver
441+
});
442+
443+
var assemblyName = assembly.Name.Name;
444+
445+
foreach (var module in assembly.Modules)
446+
{
447+
foreach (var type in module.Types)
448+
{
449+
FindRuntimeInitializeOnLoadMethodAttributes(type,
450+
assemblyName,
451+
ref classInfoList,
452+
ref methodCount);
453+
}
454+
}
455+
}
456+
catch (Exception ex)
457+
{
458+
throw new Exception("ExtractPlayerRuntimeInitializeOnLoadMethods: Failed to process " + assemblyPath + ", " + ex);
459+
}
460+
}
461+
462+
var data = new RuntimeInitializeOnLoadMethodsData();
463+
data.classInfos = classInfoList.ToArray();
464+
data.methodsCount = methodCount;
465+
466+
return data;
467+
}
468+
354469
internal static Type[] GetTypesFromAssembly(Assembly assembly)
355470
{
356471
if (assembly == null)

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@
9494
[assembly: InternalsVisibleTo("Unity.InternalAPIEditorBridgeDev.005")]
9595
[assembly: InternalsVisibleTo("Unity.XR.Remoting.Editor")]
9696
[assembly: InternalsVisibleTo("UnityEngine.Common")]
97+
[assembly: InternalsVisibleTo("Unity.GraphViewTestUtilities.Editor")]
9798

9899
[assembly: AssemblyIsEditorAssembly]

Editor/Mono/BuildPipeline/AssemblyStripper.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs,
8888
if (EditorUserBuildSettings.development)
8989
args.Add("--editor-settings-flag=Development");
9090

91-
// One final check to make sure we only run aggressive on latest runtime.
92-
if ((managedStrippingLevel == ManagedStrippingLevel.Aggressive) && (PlayerSettingsEditor.IsLatestApiCompatibility(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup))))
91+
args.Add($"--rule-set={GetRuleSetForStrippingLevel(managedStrippingLevel)}");
92+
93+
// One final check to make sure we only run high on latest runtime.
94+
if ((managedStrippingLevel == ManagedStrippingLevel.High) && (PlayerSettingsEditor.IsLatestApiCompatibility(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup))))
9395
{
94-
// Prepare the arguments to run the UnityLinker. When in aggressive mode, need to also
96+
// Prepare the arguments to run the UnityLinker. When in high mode, need to also
9597
// supply the IL2CPP compiler platform and compiler architecture. When the scripting backend
9698
// is not IL2CPP, we have to map those strings and use a utility function to figure out proper strings.
9799

@@ -108,7 +110,7 @@ private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs,
108110
{
109111
GetUnityLinkerPlatformStringsFromBuildTarget(platformProvider.target, out compilerPlatform, out compilerArchitecture);
110112
}
111-
args.Add("--aggressive");
113+
112114
args.Add($"--platform={compilerPlatform}");
113115
if (platformProvider.target != BuildTarget.Android)
114116
args.Add($"--architecture={compilerArchitecture}");
@@ -133,7 +135,7 @@ private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs,
133135

134136
var modulesAssetPath = Path.Combine(platformProvider.moduleStrippingInformationFolder, "../modules.asset");
135137
if (File.Exists(modulesAssetPath))
136-
args.Add($"--engine-modules-asset-file={modulesAssetPath}");
138+
args.Add($"--engine-modules-asset-file=\"{modulesAssetPath}\"");
137139
}
138140

139141
var additionalArgs = System.Environment.GetEnvironmentVariable("UNITYLINKER_ADDITIONAL_ARGS");
@@ -147,6 +149,21 @@ private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs,
147149
return RunAssemblyLinker(args, out output, out error, linkerPath, workingDirectory);
148150
}
149151

152+
private static string GetRuleSetForStrippingLevel(ManagedStrippingLevel managedStrippingLevel)
153+
{
154+
switch (managedStrippingLevel)
155+
{
156+
case ManagedStrippingLevel.Low:
157+
return "Conservative";
158+
case ManagedStrippingLevel.Medium:
159+
return "Aggressive";
160+
case ManagedStrippingLevel.High:
161+
return "Experimental";
162+
}
163+
164+
throw new ArgumentException($"Unhandled {nameof(ManagedStrippingLevel)} value of {managedStrippingLevel}");
165+
}
166+
150167
private static void GetUnityLinkerPlatformStringsFromBuildTarget(BuildTarget target, out string platform, out string architecture)
151168
{
152169
switch (target)
@@ -189,7 +206,7 @@ private static void GetUnityLinkerPlatformStringsFromBuildTarget(BuildTarget tar
189206
architecture = "ARM64";
190207
break;
191208
default:
192-
throw new NotSupportedException($"Aggressive stripping is not supported for mono backend on {target}.");
209+
throw new ArgumentException($"Mapping to UnityLinker platform not implemented for {nameof(BuildTarget)} `{target}`");
193210
}
194211
}
195212

Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,28 @@ internal static string GetIl2CppFolder()
141141
EditorApplication.applicationContentsPath,
142142
"il2cpp"));
143143
}
144+
145+
internal static string GetAdditionalArguments()
146+
{
147+
var arguments = new List<string>();
148+
var additionalArgs = PlayerSettings.GetAdditionalIl2CppArgs();
149+
if (!string.IsNullOrEmpty(additionalArgs))
150+
arguments.Add(additionalArgs);
151+
152+
additionalArgs = System.Environment.GetEnvironmentVariable("IL2CPP_ADDITIONAL_ARGS");
153+
if (!string.IsNullOrEmpty(additionalArgs))
154+
{
155+
arguments.Add(additionalArgs);
156+
}
157+
158+
additionalArgs = Debug.GetDiagnosticSwitch("VMIl2CppAdditionalArgs") as string;
159+
if (!string.IsNullOrEmpty(additionalArgs))
160+
{
161+
arguments.Add(additionalArgs);
162+
}
163+
164+
return arguments.Aggregate(String.Empty, (current, arg) => current + arg + " ");
165+
}
144166
}
145167

146168
internal class IL2CPPBuilder
@@ -177,6 +199,11 @@ public void Run()
177199
var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target);
178200

179201
var managedStrippingLevel = PlayerSettings.GetManagedStrippingLevel(buildTargetGroup);
202+
203+
// IL2CPP does not support a managed stripping level of disabled. If the player settings
204+
// do try this (which should not be possible from the editor), use Low instead.
205+
if (managedStrippingLevel == ManagedStrippingLevel.Disabled)
206+
managedStrippingLevel = ManagedStrippingLevel.Low;
180207
AssemblyStripper.StripAssemblies(managedDir, m_PlatformProvider, m_RuntimeClassRegistry, managedStrippingLevel);
181208

182209
// The IL2CPP editor integration here is responsible to give il2cpp.exe an empty directory to use.
@@ -289,22 +316,10 @@ private void ConvertPlayerDlltoCpp(string inputDirectory, string outputDirectory
289316

290317
arguments.Add(string.Format("--map-file-parser=\"{0}\"", GetMapFileParserPath()));
291318

292-
var additionalArgs = PlayerSettings.GetAdditionalIl2CppArgs();
319+
var additionalArgs = IL2CPPUtils.GetAdditionalArguments();
293320
if (!string.IsNullOrEmpty(additionalArgs))
294321
arguments.Add(additionalArgs);
295322

296-
additionalArgs = System.Environment.GetEnvironmentVariable("IL2CPP_ADDITIONAL_ARGS");
297-
if (!string.IsNullOrEmpty(additionalArgs))
298-
{
299-
arguments.Add(additionalArgs);
300-
}
301-
302-
additionalArgs = Debug.GetDiagnosticSwitch("VMIl2CppAdditionalArgs") as string;
303-
if (!string.IsNullOrEmpty(additionalArgs))
304-
{
305-
arguments.Add(additionalArgs);
306-
}
307-
308323
arguments.Add("--directory=\"" + Path.GetFullPath(inputDirectory) + "\"");
309324

310325
arguments.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(outputDirectory)));

Editor/Mono/BuildPipeline/Il2Cpp/Il2CppNativeCodeBuilder.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ public virtual bool LinkLibIl2CppStatically
8484
get { return true; }
8585
}
8686

87+
internal bool OverriddenCacheDirectory
88+
{
89+
get
90+
{
91+
var additionalArgs = IL2CPPUtils.GetAdditionalArguments();
92+
if (string.IsNullOrEmpty(additionalArgs))
93+
return false;
94+
95+
return additionalArgs.Contains("--cachedirectory=");
96+
}
97+
}
98+
8799
/// <summary>
88100
/// Change the relative include paths into absolute paths that can be passed to the C++ compiler.
89101
/// By default this method returns its input with each path relative to the current directory.

Editor/Mono/BuildPipeline/Il2Cpp/Il2CppNativeCodeBuilderUtils.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public static IEnumerable<string> AddBuilderArguments(Il2CppNativeCodeBuilder bu
2121
arguments.Add("--libil2cpp-static");
2222
arguments.Add(FormatArgument("platform", builder.CompilerPlatform));
2323
arguments.Add(FormatArgument("architecture", builder.CompilerArchitecture));
24-
arguments.Add(FormatArgument("configuration", compilerConfiguration.ToString()));
24+
25+
// In IL2CPP, Master config is called "ReleasePlus"
26+
string configurationName = compilerConfiguration != Il2CppCompilerConfiguration.Master ? compilerConfiguration.ToString() : "ReleasePlus";
27+
arguments.Add(FormatArgument("configuration", configurationName));
2528

2629
arguments.Add(FormatArgument("outputpath", builder.ConvertOutputFileToFullPath(outputRelativePath)));
2730

0 commit comments

Comments
 (0)