Skip to content

Commit a519a91

Browse files
author
Unity Technologies
committed
Unity 2017.3.0a6 C# reference source code
1 parent c644918 commit a519a91

63 files changed

Lines changed: 1077 additions & 798 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.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Linq;
9+
using UnityEditorInternal;
10+
using UnityEngine;
11+
using UnityEngine.Bindings;
12+
13+
namespace UnityEditor
14+
{
15+
public enum ForceReserializeAssetsOptions
16+
{
17+
ReserializeAssets = 1 << 0,
18+
ReserializeMetadata = 1 << 1,
19+
ReserializeAssetsAndMetadata = ReserializeAssets | ReserializeMetadata
20+
}
21+
22+
[NativeHeader("Modules/AssetDatabase/Editor/Public/AssetDatabaseUtility.h")]
23+
24+
public partial class AssetDatabase
25+
{
26+
[FreeFunction("AssetDatabase::ReSerializeAssetsForced")]
27+
extern private static void ReSerializeAssetsForced(GUID[] guids, ForceReserializeAssetsOptions options);
28+
29+
public static void ForceReserializeAssets(IEnumerable<string> assetPaths, ForceReserializeAssetsOptions options = ForceReserializeAssetsOptions.ReserializeAssetsAndMetadata)
30+
{
31+
if (EditorApplication.isPlaying)
32+
throw new Exception("AssetDatabase.ForceReserializeAssets cannot be used when in play mode");
33+
34+
HashSet<GUID> guidList = new HashSet<GUID>();
35+
36+
foreach (string path in assetPaths)
37+
{
38+
if (path == "")
39+
continue;
40+
41+
if (path.Equals("Assets") || path.Equals("Packages"))
42+
continue;
43+
44+
if (AssetDatabase.IsPackagedAssetPath(path))
45+
continue;
46+
47+
if (InternalEditorUtility.IsUnityExtensionRegistered(path))
48+
continue;
49+
50+
GUID guid = new GUID(AssetPathToGUID(path));
51+
52+
if (!guid.Empty())
53+
{
54+
guidList.Add(guid);
55+
}
56+
else
57+
{
58+
if (File.Exists(path))
59+
{
60+
Debug.LogWarningFormat("Cannot reserialize file \"{0}\": the file is not in the AssetDatabase. Skipping.", path);
61+
}
62+
else
63+
{
64+
Debug.LogWarningFormat("Cannot reserialize file \"{0}\": the file does not exist. Skipping.", path);
65+
}
66+
}
67+
}
68+
69+
GUID[] guids = new GUID[guidList.Count];
70+
guidList.CopyTo(guids);
71+
ReSerializeAssetsForced(guids, options);
72+
}
73+
74+
public static void ForceReserializeAssets()
75+
{
76+
ForceReserializeAssets(GetAllAssetPaths());
77+
}
78+
}
79+
}

Editor/Mono/BuildPipeline/CodeStrippingUtils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ static UnityType GameManagerTypeInfo
4040
// will otherwise be stripped if scene only uses default materials not explicitly referenced
4141
// (ie some components will get a default material if a material reference is null)
4242
"Material",
43+
4344
// those are used to create builtin textures and availability is checked at runtime
4445
"Cubemap",
4546
"Texture3D",
4647
"Texture2DArray",
4748
"RenderTexture",
49+
4850
"Mesh", // Used by IMGUI (even on empty projects, it draws development console & watermarks)
4951
"MeshFilter", // Used in the VR Splash screen.
5052
"MeshRenderer", // Used in the VR Splash screen.
5153
"Sprite", // Used by Unity splash screen.
5254
"LowerResBlitTexture",
55+
56+
"Transform", // well, Transform is always used
57+
"RectTransform", // Transform depends on RectTransform's TransformHierarchyChangeDispatch
5358
};
5459

5560
static UnityType[] s_blackListNativeClasses;

Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public void UpdateBootConfig(BuildTarget target, BootConfigData config, BuildOpt
3636
config.AddKey("single-instance");
3737
if (EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest)
3838
config.Set("scripting-runtime-version", "latest");
39+
if (IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(BuildPipeline.GetBuildTargetGroup(target)))
40+
config.Set("mono-codegen", "il2cpp");
3941
}
4042

4143
private void CopyNativePlugins()
@@ -174,6 +176,10 @@ protected virtual void SetupStagingArea()
174176
FileUtil.CreateOrCleanDirectory(metadataDirectory);
175177
IL2CPPUtils.CopyMetadataFiles(stagingAreaDirectory, metadataDirectory);
176178
IL2CPPUtils.CopySymmapFile(stagingAreaDirectory + "/Native/Data", managedDataDirectory);
179+
180+
// Are we using IL2CPP code generation with the Mono runtime? If so, strip the assemblies so we can use them for metadata.
181+
if (IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(BuildPipeline.GetBuildTargetGroup(m_PostProcessArgs.target)))
182+
StripAssembliesToLeaveOnlyMetadata(m_PostProcessArgs.target, managedDataDirectory);
177183
}
178184

179185
if (InstallingIntoBuildsFolder)
@@ -191,6 +197,15 @@ protected virtual void SetupStagingArea()
191197
m_PostProcessArgs.report.RelocateFiles(StagingArea, "");
192198
}
193199

200+
static void StripAssembliesToLeaveOnlyMetadata(BuildTarget target, string stagingAreaDataManaged)
201+
{
202+
AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
203+
checker.CollectReferences(stagingAreaDataManaged, true, 0.0f, false);
204+
205+
EditorUtility.DisplayProgressBar("Removing bytecode from assemblies", "Stripping assemblies so that only metadata remains", 0.95F);
206+
MonoAssemblyStripping.MonoCilStrip(target, stagingAreaDataManaged, checker.GetAssemblyFileNames());
207+
}
208+
194209
// Creates app.info which is used by Standalone player (when run in Low Integrity mode) when creating log file path at program start.
195210
// Log file path is created very early in the program execution, when none of the Unity managers are even created, that's why we can't get it from PlayerSettings
196211
// Note: In low integrity mode, we can only write to %USER PROFILE%\AppData\LocalLow on Windows
@@ -243,6 +258,17 @@ protected void CopyStagingAreaIntoDestination()
243258

244259
protected abstract void DeleteDestination();
245260

261+
protected void DeleteUnusedMono(string dataFolder)
262+
{
263+
// Mono is built by the il2cpp builder, so we dont need the libs copied
264+
bool deleteBoth = IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(BuildTargetGroup.Standalone);
265+
266+
if (deleteBoth || EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest)
267+
FileUtil.DeleteFileOrDirectory(Path.Combine(dataFolder, "Mono"));
268+
if (deleteBoth || EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Legacy)
269+
FileUtil.DeleteFileOrDirectory(Path.Combine(dataFolder, "MonoBleedingEdge"));
270+
}
271+
246272
protected abstract string DestinationFolderForInstallingIntoBuildsFolder { get; }
247273

248274
protected abstract void CopyDataForBuildsFolder();

Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ internal static IIl2CppPlatformProvider PlatformProviderForNotModularPlatform(Bu
3434

3535
internal static IL2CPPBuilder RunIl2Cpp(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool debugBuild)
3636
{
37-
var builder = new IL2CPPBuilder(tempFolder, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, debugBuild);
37+
var builder = new IL2CPPBuilder(tempFolder, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, debugBuild, IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(BuildPipeline.GetBuildTargetGroup(platformProvider.target)));
3838
builder.Run();
3939
return builder;
4040
}
4141

4242
internal static IL2CPPBuilder RunIl2Cpp(string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool debugBuild)
4343
{
44-
var builder = new IL2CPPBuilder(stagingAreaData, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, debugBuild);
44+
var builder = new IL2CPPBuilder(stagingAreaData, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, debugBuild, IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(BuildPipeline.GetBuildTargetGroup(platformProvider.target)));
4545
builder.Run();
4646
return builder;
4747
}
4848

4949
internal static IL2CPPBuilder RunCompileAndLink(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool debugBuild)
5050
{
51-
var builder = new IL2CPPBuilder(tempFolder, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, debugBuild);
51+
var builder = new IL2CPPBuilder(tempFolder, stagingAreaData, platformProvider, modifyOutputBeforeCompile, runtimeClassRegistry, debugBuild, IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(BuildPipeline.GetBuildTargetGroup(platformProvider.target)));
5252
builder.RunCompileAndLink();
5353
return builder;
5454
}
@@ -110,6 +110,13 @@ internal static string ApiCompatibilityLevelToDotNetProfileArgument(ApiCompatibi
110110
throw new NotSupportedException(string.Format("ApiCompatibilityLevel.{0} is not supported by IL2CPP!", compatibilityLevel));
111111
}
112112
}
113+
114+
internal static bool UseIl2CppCodegenWithMonoBackend(BuildTargetGroup targetGroup)
115+
{
116+
return EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest &&
117+
EditorApplication.useLibmonoBackendForIl2cpp &&
118+
PlayerSettings.GetScriptingBackend(targetGroup) == ScriptingImplementation.IL2CPP;
119+
}
113120
}
114121

115122
internal class IL2CPPBuilder
@@ -121,15 +128,17 @@ internal class IL2CPPBuilder
121128
private readonly RuntimeClassRegistry m_RuntimeClassRegistry;
122129
private readonly bool m_DebugBuild;
123130
private readonly LinkXmlReader m_linkXmlReader = new LinkXmlReader();
131+
private readonly bool m_BuildForMonoRuntime;
124132

125-
public IL2CPPBuilder(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool debugBuild)
133+
public IL2CPPBuilder(string tempFolder, string stagingAreaData, IIl2CppPlatformProvider platformProvider, Action<string> modifyOutputBeforeCompile, RuntimeClassRegistry runtimeClassRegistry, bool debugBuild, bool buildForMonoRuntime)
126134
{
127135
m_TempFolder = tempFolder;
128136
m_StagingAreaData = stagingAreaData;
129137
m_PlatformProvider = platformProvider;
130138
m_ModifyOutputBeforeCompile = modifyOutputBeforeCompile;
131139
m_RuntimeClassRegistry = runtimeClassRegistry;
132140
m_DebugBuild = debugBuild;
141+
m_BuildForMonoRuntime = buildForMonoRuntime;
133142
}
134143

135144
public void Run()
@@ -265,6 +274,9 @@ private void ConvertPlayerDlltoCpp(ICollection<string> userAssemblies, string ou
265274
if (m_PlatformProvider.developmentMode)
266275
arguments.Add("--development-mode");
267276

277+
if (m_BuildForMonoRuntime)
278+
arguments.Add("--mono-runtime");
279+
268280
var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target);
269281
if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6)
270282
arguments.Add("--dotnetprofile=\"net45\"");

Editor/Mono/BuildPipeline/MonoAssemblyStripping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static void ReplaceFile(string src, string dst)
177177

178178
static public void MonoCilStrip(BuildTarget buildTarget, string managedLibrariesDirectory, string[] fileNames)
179179
{
180-
string basePath = BuildPipeline.GetBuildToolsDirectory(buildTarget);
180+
string basePath = MonoInstallationFinder.GetProfileDirectory(BuildPipeline.CompatibilityProfileToClassLibFolder(ApiCompatibilityLevel.NET_4_6), MonoInstallationFinder.MonoBleedingEdgeInstallation);
181181
string cilStripper = Path.Combine(basePath, "mono-cil-strip.exe");
182182

183183
foreach (string fileName in fileNames)

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void AddOpenScenes()
233233
GUIUtility.ExitGUI();
234234
}
235235

236-
static BuildTarget CalculateSelectedBuildTarget()
236+
internal static BuildTarget CalculateSelectedBuildTarget()
237237
{
238238
BuildTargetGroup targetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
239239
switch (targetGroup)
@@ -319,7 +319,7 @@ void ShowAlert()
319319
GUILayout.BeginHorizontal();
320320
GUILayout.Space(10);
321321
GUILayout.BeginVertical();
322-
EditorGUILayout.HelpBox("Because you are not a member of this project this build will not access Unity services.", MessageType.Warning);
322+
EditorGUILayout.HelpBox(EditorGUIUtility.TextContent("Unable to access Unity services. Please log in, or request membership to this project to use these services.").text, MessageType.Warning);
323323
GUILayout.EndVertical();
324324
GUILayout.Space(5);
325325
GUILayout.EndHorizontal();
@@ -843,10 +843,6 @@ private static void GUIBuildButtons(IBuildWindowExtension buildWindowExtension,
843843
&& EditorUserBuildSettings.exportAsGoogleAndroidProject)
844844
buildButton = styles.export;
845845

846-
if (platform.targetGroup == BuildTargetGroup.iOS)
847-
if (Application.platform != RuntimePlatform.OSXEditor)
848-
enableBuildAndRunButton = false;
849-
850846
// Build Button
851847
GUI.enabled = enableBuildButton;
852848
if (GUILayout.Button(buildButton, GUILayout.Width(Styles.kButtonWidth)))

Editor/Mono/Collab/CollabToolbarWindow.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ internal static bool ShowCenteredAtPosition(Rect buttonRect)
8585
}
8686
if (s_CollabToolbarWindow == null)
8787
s_CollabToolbarWindow = CreateInstance<CollabToolbarWindow>() as CollabToolbarWindow;
88-
// Has to be done before calling Show / ShowWithMode
89-
buttonRect = GUIUtility.GUIToScreenRect(buttonRect);
9088
var windowSize = new Vector2(kWindowWidth, kWindowHeight);
9189
s_CollabToolbarWindow.initialOpenUrl = "file:///" + EditorApplication.userJavascriptPackagesPath + "unityeditor-collab-toolbar/dist/index.html";
9290
s_CollabToolbarWindow.Init();

0 commit comments

Comments
 (0)