Skip to content

Commit 555f53c

Browse files
author
Unity Technologies
committed
Unity 2018.3.0a9 C# reference source code
1 parent 3a7bd40 commit 555f53c

83 files changed

Lines changed: 1956 additions & 1096 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/Animation/AnimationWindow/AnimationWindowHierarchyGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal class AnimationWindowHierarchyGUI : TreeViewGUI
3333
private const float k_RowRightOffset = 10;
3434
private const float k_ValueFieldDragWidth = 15;
3535
private const float k_ValueFieldWidth = 80;
36-
private const float k_ValueFieldOffsetFromRightSide = 90;
36+
private const float k_ValueFieldOffsetFromRightSide = 100;
3737
private const float k_ColorIndicatorTopMargin = 3;
3838
public static readonly float k_DopeSheetRowHeight = EditorGUI.kSingleLineHeight;
3939
public static readonly float k_DopeSheetRowHeightTall = k_DopeSheetRowHeight * 2f;

Editor/Mono/AssetPostprocessor.cs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void LogPostProcessorMissingDefaultConstructor(Type type)
7474
static void PostprocessAllAssets(string[] importedAssets, string[] addedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPathAssets)
7575
{
7676
object[] args = { importedAssets, deletedAssets, movedAssets, movedFromPathAssets };
77-
foreach (var assetPostprocessorClass in EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)))
77+
foreach (var assetPostprocessorClass in GetCachedAssetPostprocessorClasses())
7878
{
7979
MethodInfo method = assetPostprocessorClass.GetMethod("OnPostprocessAllAssets", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
8080
if (method != null)
@@ -152,7 +152,7 @@ static internal bool OnPreGeneratingCSProjectFiles()
152152

153153
private static IEnumerable<MethodInfo> AllPostProcessorMethodsNamed(string callbackName)
154154
{
155-
return EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)).Select(assetPostprocessorClass => assetPostprocessorClass.GetMethod(callbackName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)).Where(method => method != null);
155+
return GetCachedAssetPostprocessorClasses().Select(assetPostprocessorClass => assetPostprocessorClass.GetMethod(callbackName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)).Where(method => method != null);
156156
}
157157

158158
internal class CompareAssetImportPriority : IComparer
@@ -186,18 +186,15 @@ internal class PostprocessStack
186186

187187
static ArrayList m_PostprocessStack = null;
188188
static ArrayList m_ImportProcessors = null;
189-
static ArrayList m_PostprocessorClasses = null;
189+
static Type[] m_PostprocessorClasses = null;
190+
static string m_MeshProcessorsHashString = null;
191+
static string m_TextureProcessorsHashString = null;
192+
static string m_AudioProcessorsHashString = null;
190193

191-
static ArrayList GetCachedAssetPostprocessorClasses()
194+
static Type[] GetCachedAssetPostprocessorClasses()
192195
{
193196
if (m_PostprocessorClasses == null)
194-
{
195-
m_PostprocessorClasses = new ArrayList();
196-
foreach (var type in EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)))
197-
{
198-
m_PostprocessorClasses.Add(type);
199-
}
200-
}
197+
m_PostprocessorClasses = EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)).ToArray();
201198
return m_PostprocessorClasses;
202199
}
203200

@@ -254,9 +251,12 @@ static void CleanupPostprocessors()
254251
[RequiredByNativeCode]
255252
static string GetMeshProcessorsHashString()
256253
{
254+
if (m_MeshProcessorsHashString != null)
255+
return m_MeshProcessorsHashString;
256+
257257
var versionsByType = new SortedList<string, uint>();
258258

259-
foreach (var assetPostprocessorClass in EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)))
259+
foreach (var assetPostprocessorClass in GetCachedAssetPostprocessorClasses())
260260
{
261261
try
262262
{
@@ -280,8 +280,8 @@ static string GetMeshProcessorsHashString()
280280
Debug.LogException(e);
281281
}
282282
}
283-
284-
return BuildHashString(versionsByType);
283+
m_MeshProcessorsHashString = BuildHashString(versionsByType);
284+
return m_MeshProcessorsHashString;
285285
}
286286

287287
[RequiredByNativeCode]
@@ -408,9 +408,12 @@ static EditorCurveBinding[] PostprocessGameObjectWithAnimatedUserProperties(Game
408408
[RequiredByNativeCode]
409409
static string GetTextureProcessorsHashString()
410410
{
411+
if (m_TextureProcessorsHashString != null)
412+
return m_TextureProcessorsHashString;
413+
411414
var versionsByType = new SortedList<string, uint>();
412415

413-
foreach (var assetPostprocessorClass in EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)))
416+
foreach (var assetPostprocessorClass in GetCachedAssetPostprocessorClasses())
414417
{
415418
try
416419
{
@@ -435,7 +438,8 @@ static string GetTextureProcessorsHashString()
435438
}
436439
}
437440

438-
return BuildHashString(versionsByType);
441+
m_TextureProcessorsHashString = BuildHashString(versionsByType);
442+
return m_TextureProcessorsHashString;
439443
}
440444

441445
[RequiredByNativeCode]
@@ -480,9 +484,12 @@ static void PostprocessSprites(Texture2D tex, string pathName, Sprite[] sprites)
480484
[RequiredByNativeCode]
481485
static string GetAudioProcessorsHashString()
482486
{
487+
if (m_AudioProcessorsHashString != null)
488+
return m_AudioProcessorsHashString;
489+
483490
var versionsByType = new SortedList<string, uint>();
484491

485-
foreach (var assetPostprocessorClass in EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)))
492+
foreach (var assetPostprocessorClass in GetCachedAssetPostprocessorClasses())
486493
{
487494
try
488495
{
@@ -506,7 +513,8 @@ static string GetAudioProcessorsHashString()
506513
}
507514
}
508515

509-
return BuildHashString(versionsByType);
516+
m_AudioProcessorsHashString = BuildHashString(versionsByType);
517+
return m_AudioProcessorsHashString;
510518
}
511519

512520
[RequiredByNativeCode]
@@ -533,7 +541,7 @@ static void PostprocessAssetbundleNameChanged(string assetPAth, string prevoiusA
533541
{
534542
object[] args = { assetPAth, prevoiusAssetBundleName, newAssetBundleName };
535543

536-
foreach (var assetPostprocessorClass in EditorAssemblies.SubclassesOf(typeof(AssetPostprocessor)))
544+
foreach (var assetPostprocessorClass in GetCachedAssetPostprocessorClasses())
537545
{
538546
var assetPostprocessor = Activator.CreateInstance(assetPostprocessorClass) as AssetPostprocessor;
539547
AttributeHelper.InvokeMemberIfAvailable(assetPostprocessor, "OnPostprocessAssetbundleNameChanged", args);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal static void Popup(AudioMixerController controller, GUIStyle style, para
1818
Rect buttonRect = GUILayoutUtility.GetRect(content, style, options);
1919
if (EditorGUI.DropdownButton(buttonRect, content, FocusType.Passive, style))
2020
{
21-
PopupWindow.Show(buttonRect, new AudioMixerExposedParametersPopup(controller));
21+
PopupWindow.Show(buttonRect, new AudioMixerExposedParametersPopup(controller), null, ShowMode.PopupMenuWithKeyboardFocus);
2222
}
2323
}
2424

Editor/Mono/BuildPipeline/AssemblyStripper.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ private static void GetUnityLinkerPlatformStringsFromBuildTarget(BuildTarget tar
157157
platform = "MacOSX";
158158
architecture = "x64";
159159
break;
160+
case BuildTarget.WSAPlayer:
161+
platform = "WinRT";
162+
// Could be multiple values. We don't have use of this information yet so don't bother with trying to figure out what it should be
163+
architecture = "";
164+
break;
165+
case BuildTarget.iOS:
166+
platform = "iOS";
167+
architecture = "ARM64";
168+
break;
160169
default:
161170
throw new NotSupportedException($"Aggressive stripping is not supported for mono backend on {target}.");
162171
}
@@ -285,6 +294,9 @@ private static void RunAssemblyStripper(IEnumerable assemblies, string managedAs
285294
blacklists = blacklists.Concat(new[] {file});
286295
}
287296

297+
// Generated link xml files that would have been empty will be nulled out. Need to filter these out before running the linker
298+
blacklists = blacklists.Where(b => b != null);
299+
288300
var tempStripPath = Path.GetFullPath(Path.Combine(managedAssemblyFolderPath, "tempStrip"));
289301

290302
bool addedMoreBlacklists;
@@ -357,8 +369,11 @@ private static void RunAssemblyStripper(IEnumerable assemblies, string managedAs
357369

358370
private static string WriteMethodsToPreserveBlackList(RuntimeClassRegistry rcr, BuildTarget target)
359371
{
372+
var contents = GetMethodPreserveBlacklistContents(rcr, target);
373+
if (contents == null)
374+
return null;
360375
var methodPerserveBlackList = Path.GetTempFileName();
361-
File.WriteAllText(methodPerserveBlackList, GetMethodPreserveBlacklistContents(rcr, target));
376+
File.WriteAllText(methodPerserveBlackList, contents);
362377
return methodPerserveBlackList;
363378
}
364379

@@ -373,6 +388,9 @@ private static string WriteUnityEngineBlackList()
373388

374389
private static string GetMethodPreserveBlacklistContents(RuntimeClassRegistry rcr, BuildTarget target)
375390
{
391+
if (rcr.GetMethodsToPreserve().Count == 0)
392+
return null;
393+
376394
var sb = new StringBuilder();
377395
sb.AppendLine("<linker>");
378396

Editor/Mono/BuildPipeline/DesktopStandaloneBuildWindowExtension.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal abstract class DesktopStandaloneBuildWindowExtension : DefaultBuildWind
1212
{
1313
private GUIContent m_StandaloneTarget = EditorGUIUtility.TrTextContent("Target Platform", "Destination platform for standalone build");
1414
private GUIContent m_Architecture = EditorGUIUtility.TrTextContent("Architecture", "Build m_Architecture for standalone");
15-
15+
private GUIContent m_HeadlessMode = EditorGUIUtility.TrTextContent("Server Build");
1616
private BuildTarget[] m_StandaloneSubtargets;
1717
private GUIContent[] m_StandaloneSubtargetStrings;
1818

@@ -181,6 +181,8 @@ public override void ShowPlatformBuildOptions()
181181
GUIUtility.ExitGUI();
182182
}
183183

184+
EditorUserBuildSettings.enableHeadlessMode = EditorGUILayout.Toggle(m_HeadlessMode, EditorUserBuildSettings.enableHeadlessMode);
185+
184186
ShowIl2CppErrorIfNeeded();
185187
}
186188

Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ internal class IL2CPPBuilder
150150
private readonly IIl2CppPlatformProvider m_PlatformProvider;
151151
private readonly Action<string> m_ModifyOutputBeforeCompile;
152152
private readonly RuntimeClassRegistry m_RuntimeClassRegistry;
153-
private readonly LinkXmlReader m_linkXmlReader = new LinkXmlReader();
154153
private readonly bool m_BuildForMonoRuntime;
155154

156155
public IL2CPPBuilder(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool buildForMonoRuntime)
@@ -186,7 +185,7 @@ public void Run()
186185
if (m_ModifyOutputBeforeCompile != null)
187186
m_ModifyOutputBeforeCompile(outputDirectory);
188187

189-
ConvertPlayerDlltoCpp(GetUserAssembliesToConvert(managedDir), outputDirectory, managedDir, m_PlatformProvider.supportsManagedDebugging);
188+
ConvertPlayerDlltoCpp(managedDir, outputDirectory, managedDir, m_PlatformProvider.supportsManagedDebugging);
190189

191190
var compiler = m_PlatformProvider.CreateNativeCompiler();
192191
if (compiler != null && m_PlatformProvider.CreateIl2CppNativeCodeBuilder() == null)
@@ -234,29 +233,6 @@ private string OutputFileRelativePath()
234233
return nativeLibPath;
235234
}
236235

237-
internal List<string> GetUserAssembliesToConvert(string managedDir)
238-
{
239-
var userAssemblies = GetUserAssemblies(managedDir);
240-
userAssemblies.Add(Directory.GetFiles(managedDir, "UnityEngine.dll", SearchOption.TopDirectoryOnly).Single());
241-
userAssemblies.UnionWith(FilterUserAssemblies(Directory.GetFiles(managedDir, "*.dll", SearchOption.TopDirectoryOnly), m_linkXmlReader.IsDLLUsed, managedDir));
242-
243-
return userAssemblies.ToList();
244-
}
245-
246-
private HashSet<string> GetUserAssemblies(string managedDir)
247-
{
248-
HashSet<string> userAssemblies = new HashSet<string>();
249-
userAssemblies.UnionWith(FilterUserAssemblies(m_RuntimeClassRegistry.GetUserAssemblies(), m_RuntimeClassRegistry.IsDLLUsed, managedDir));
250-
userAssemblies.UnionWith(FilterUserAssemblies(Directory.GetFiles(managedDir, "I18N*.dll", SearchOption.TopDirectoryOnly), (assembly) => true, managedDir));
251-
252-
return userAssemblies;
253-
}
254-
255-
private IEnumerable<string> FilterUserAssemblies(IEnumerable<string> assemblies, Predicate<string> isUsed, string managedDir)
256-
{
257-
return assemblies.Where(assembly => isUsed(assembly)).Select(usedAssembly => Path.Combine(managedDir, usedAssembly));
258-
}
259-
260236
public string GetCppOutputDirectoryInStagingArea()
261237
{
262238
return GetCppOutputPath(m_TempFolder);
@@ -275,11 +251,8 @@ public static string GetMapFileParserPath()
275251
Application.platform == RuntimePlatform.WindowsEditor ? @"Tools\MapFileParser\MapFileParser.exe" : @"Tools/MapFileParser/MapFileParser"));
276252
}
277253

278-
private void ConvertPlayerDlltoCpp(ICollection<string> userAssemblies, string outputDirectory, string workingDirectory, bool platformSupportsManagedDebugging)
254+
private void ConvertPlayerDlltoCpp(string inputDirectory, string outputDirectory, string workingDirectory, bool platformSupportsManagedDebugging)
279255
{
280-
if (userAssemblies.Count == 0)
281-
return;
282-
283256
var arguments = new List<string>();
284257

285258
arguments.Add("--convert-to-cpp");
@@ -332,8 +305,7 @@ private void ConvertPlayerDlltoCpp(ICollection<string> userAssemblies, string ou
332305
arguments.Add(additionalArgs);
333306
}
334307

335-
var pathArguments = new List<string>(userAssemblies);
336-
arguments.AddRange(pathArguments.Select(arg => "--assembly=\"" + Path.GetFullPath(arg) + "\""));
308+
arguments.Add("--directory=\"" + Path.GetFullPath(inputDirectory) + "\"");
337309

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

@@ -563,28 +535,4 @@ public virtual CompilerOutputParserBase CreateIl2CppOutputParser()
563535
return null;
564536
}
565537
}
566-
567-
internal class LinkXmlReader
568-
{
569-
private readonly List<string> _assembliesInALinkXmlFile = new List<string>();
570-
571-
public LinkXmlReader()
572-
{
573-
foreach (var linkXmlFile in AssemblyStripper.GetUserBlacklistFiles())
574-
{
575-
XPathDocument linkXml = new XPathDocument(linkXmlFile);
576-
var navigator = linkXml.CreateNavigator();
577-
navigator.MoveToFirstChild();
578-
var iterator = navigator.SelectChildren("assembly", string.Empty);
579-
580-
while (iterator.MoveNext())
581-
_assembliesInALinkXmlFile.Add(iterator.Current.GetAttribute("fullname", string.Empty));
582-
}
583-
}
584-
585-
public bool IsDLLUsed(string assemblyFileName)
586-
{
587-
return _assembliesInALinkXmlFile.Contains(Path.GetFileNameWithoutExtension(assemblyFileName));
588-
}
589-
}
590538
}

Editor/Mono/BuildPipeline/MonoAssemblyStripping.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,37 @@ static public void MonoCilStrip(BuildTarget buildTarget, string managedLibraries
200200

201201
public static string GenerateLinkXmlToPreserveDerivedTypes(string librariesFolder, RuntimeClassRegistry usedClasses)
202202
{
203-
string path = Path.GetTempFileName();
203+
var sb = new StringBuilder();
204+
bool wrotePreservations = false;
204205

205-
using (TextWriter w = new StreamWriter(path))
206+
sb.AppendLine("<linker>");
207+
foreach (var assembly in CollectAllAssemblies(librariesFolder, usedClasses))
206208
{
207-
w.WriteLine("<linker>");
208-
foreach (var assembly in CollectAllAssemblies(librariesFolder, usedClasses))
209-
{
210-
if (AssemblyHelper.IsUnityEngineModule(assembly))
211-
continue;
209+
if (AssemblyHelper.IsUnityEngineModule(assembly))
210+
continue;
212211

213-
var typesToPreserve = new HashSet<TypeDefinition>();
214-
CollectBlackListTypes(typesToPreserve, assembly.MainModule.Types, usedClasses.GetAllManagedBaseClassesAsString());
212+
var typesToPreserve = new HashSet<TypeDefinition>();
213+
CollectBlackListTypes(typesToPreserve, assembly.MainModule.Types, usedClasses.GetAllManagedBaseClassesAsString());
215214

216-
// don't write out xml file for assemblies with no types since link.xml files on disk have special meaning to IL2CPP stripping
217-
if (typesToPreserve.Count == 0)
218-
continue;
215+
// don't write out xml file for assemblies with no types since link.xml files on disk have special meaning to IL2CPP stripping
216+
if (typesToPreserve.Count == 0)
217+
continue;
219218

220-
w.WriteLine("<assembly fullname=\"{0}\">", assembly.Name.Name);
221-
foreach (var typeToPreserve in typesToPreserve)
222-
w.WriteLine("<type fullname=\"{0}\" preserve=\"all\"/>", typeToPreserve.FullName);
223-
w.WriteLine("</assembly>");
224-
}
225-
w.WriteLine("</linker>");
219+
wrotePreservations = true;
220+
221+
sb.AppendLine(string.Format("<assembly fullname=\"{0}\">", assembly.Name.Name));
222+
foreach (var typeToPreserve in typesToPreserve)
223+
sb.AppendLine(string.Format("<type fullname=\"{0}\" preserve=\"all\"/>", typeToPreserve.FullName));
224+
sb.AppendLine("</assembly>");
226225
}
226+
sb.AppendLine("</linker>");
227227

228+
// Don't generate and pass xml files that are empty. While they are harmless, they are noisey and just cause useless clutter
229+
if (!wrotePreservations)
230+
return null;
231+
232+
string path = Path.GetTempFileName();
233+
File.WriteAllText(path, sb.ToString());
228234
return path;
229235
}
230236

Editor/Mono/BuildPipeline/RuntimeClassMetadata.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ protected void InitRuntimeClassRegistry()
165165
BuildTargetGroup group = UnityEditor.BuildPipeline.GetBuildTargetGroup(buildTarget);
166166

167167
// Don't strip any classes which extend the following base classes
168-
AddManagedBaseClass("UnityEngine.MonoBehaviour");
169-
AddManagedBaseClass("UnityEngine.ScriptableObject");
170168

171169
if (group == BuildTargetGroup.Android)
172170
{

0 commit comments

Comments
 (0)