Skip to content

Commit 4dfc797

Browse files
author
Unity Technologies
committed
Unity 2022.2.0a12 C# reference source code
1 parent 79d86f8 commit 4dfc797

142 files changed

Lines changed: 3440 additions & 1206 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/IncrementalBuildPipeline/PlayerBuildProgramLibrary.Data/Data.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class PlayerBuildConfig
3333
public string ApplicationIdentifier;
3434
public string Architecture;
3535
public bool UseIl2Cpp;
36+
public bool UseCoreCLR;
3637
public bool InstallIntoBuildsFolder;
3738
public bool GenerateIdeProject;
3839
public bool Development;

Editor/Mono/AssemblyHelper.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ static private bool CouldBelongToDotNetOrWindowsRuntime(string assemblyPath)
7979
assemblyPath.IndexOf("platform.dll") != -1;
8080
}
8181

82-
static private bool IgnoreAssembly(string assemblyPath, BuildTarget target)
82+
static private bool IgnoreAssembly(string assemblyPath, BuildTarget target, ScriptingImplementation scriptingImplementation)
8383
{
84-
if (target == BuildTarget.WSAPlayer)
84+
#pragma warning disable 618
85+
if (target == BuildTarget.WSAPlayer || scriptingImplementation == ScriptingImplementation.CoreCLR)
8586
{
8687
if (CouldBelongToDotNetOrWindowsRuntime(assemblyPath))
8788
return true;
@@ -99,9 +100,9 @@ static private bool IgnoreAssembly(string assemblyPath, BuildTarget target)
99100
return IsInternalAssembly(assemblyPath);
100101
}
101102

102-
static private void AddReferencedAssembliesRecurse(string assemblyPath, List<string> alreadyFoundAssemblies, string[] allAssemblyPaths, string[] foldersToSearch, Dictionary<string, AssemblyDefinition> cache, BuildTarget target)
103+
static private void AddReferencedAssembliesRecurse(string assemblyPath, List<string> alreadyFoundAssemblies, string[] allAssemblyPaths, string[] foldersToSearch, Dictionary<string, AssemblyDefinition> cache, BuildTarget target, ScriptingImplementation scriptingImplementation)
103104
{
104-
if (IgnoreAssembly(assemblyPath, target))
105+
if (IgnoreAssembly(assemblyPath, target, scriptingImplementation))
105106
return;
106107

107108
if (!File.Exists(assemblyPath))
@@ -130,7 +131,7 @@ static private void AddReferencedAssembliesRecurse(string assemblyPath, List<str
130131
if (referencedAssembly.Name == "BridgeInterface") continue;
131132
if (referencedAssembly.Name == "WinRTBridge") continue;
132133
if (referencedAssembly.Name == "UnityEngineProxy") continue;
133-
if (IgnoreAssembly(referencedAssembly.Name + ".dll", target)) continue;
134+
if (IgnoreAssembly(referencedAssembly.Name + ".dll", target, scriptingImplementation)) continue;
134135

135136
string foundPath = FindAssemblyName(referencedAssembly.FullName, referencedAssembly.Name, allAssemblyPaths, foldersToSearch, cache);
136137

@@ -154,7 +155,7 @@ static private void AddReferencedAssembliesRecurse(string assemblyPath, List<str
154155
assemblyPath));
155156
}
156157

157-
AddReferencedAssembliesRecurse(foundPath, alreadyFoundAssemblies, allAssemblyPaths, foldersToSearch, cache, target);
158+
AddReferencedAssembliesRecurse(foundPath, alreadyFoundAssemblies, allAssemblyPaths, foldersToSearch, cache, target, scriptingImplementation);
158159
}
159160
}
160161

@@ -182,14 +183,14 @@ static string FindAssemblyName(string fullName, string name, string[] allAssembl
182183
}
183184

184185
[RequiredByNativeCode]
185-
static public string[] FindAssembliesReferencedBy(string[] paths, string[] foldersToSearch, BuildTarget target)
186+
static public string[] FindAssembliesReferencedBy(string[] paths, string[] foldersToSearch, BuildTarget target, ScriptingImplementation scriptingImplementation)
186187
{
187188
List<string> unique = new List<string>();
188189
string[] allAssemblyPaths = paths;
189190

190191
var cache = new Dictionary<string, AssemblyDefinition>();
191192
for (int i = 0; i < paths.Length; i++)
192-
AddReferencedAssembliesRecurse(paths[i], unique, allAssemblyPaths, foldersToSearch, cache, target);
193+
AddReferencedAssembliesRecurse(paths[i], unique, allAssemblyPaths, foldersToSearch, cache, target, scriptingImplementation);
193194

194195
for (int i = 0; i < paths.Length; i++)
195196
unique.Remove(paths[i]);

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
[assembly: InternalsVisibleTo("com.unity.purchasing.udp.Editor")]
134134
[assembly: InternalsVisibleTo("com.unity.search.extensions.editor")]
135135

136+
[assembly: InternalsVisibleTo("UnityEditor.Android.Extensions")]
137+
136138
[assembly: InternalsVisibleTo("Unity.Scenes")]
137139

138140
[assembly: AssemblyIsEditorAssembly]

Editor/Mono/BuildPipeline/DesktopStandaloneBuildWindowExtension.cs

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ internal abstract class DesktopStandaloneBuildWindowExtension : DefaultBuildWind
2222
protected bool m_HasServerPlayers;
2323
protected bool m_IsRunningOnHostPlatform;
2424

25+
public static void SetArchitectureForPlatform(BuildTarget buildTarget, OSArchitecture architecture)
26+
{
27+
EditorUserBuildSettings.SetPlatformSettings(BuildPipeline.GetBuildTargetName(buildTarget), EditorUserBuildSettings.kSettingArchitecture, architecture.ToString().ToLower());
28+
}
29+
2530
public DesktopStandaloneBuildWindowExtension(bool hasMonoPlayers, bool hasIl2CppPlayers, bool hasCoreCLRPlayers, bool hasServerPlayers)
2631
{
2732
SetupStandaloneSubtargets();
@@ -73,16 +78,30 @@ internal static BuildTarget GetBestStandaloneTarget(BuildTarget selectedTarget)
7378
return BuildTarget.StandaloneWindows64;
7479
}
7580

76-
private static Dictionary<GUIContent, BuildTarget> GetArchitecturesForPlatform(BuildTarget target)
81+
struct BuildTargetInfo
82+
{
83+
public BuildTarget buildTarget;
84+
public OSArchitecture architecture;
85+
}
86+
87+
private static Dictionary<GUIContent, BuildTargetInfo> GetArchitecturesForPlatform(BuildTarget target)
7788
{
7889
switch (target)
7990
{
8091
case BuildTarget.StandaloneWindows:
8192
case BuildTarget.StandaloneWindows64:
82-
return new Dictionary<GUIContent, BuildTarget>
93+
return new Dictionary<GUIContent, BuildTargetInfo>
8394
{
84-
{ EditorGUIUtility.TrTextContent("Intel 64-bit"), BuildTarget.StandaloneWindows64 },
85-
{ EditorGUIUtility.TrTextContent("Intel 32-bit"), BuildTarget.StandaloneWindows },
95+
{ EditorGUIUtility.TrTextContent("Intel 64-bit"), new BuildTargetInfo
96+
{
97+
buildTarget = BuildTarget.StandaloneWindows64,
98+
architecture = OSArchitecture.x64
99+
}},
100+
{ EditorGUIUtility.TrTextContent("Intel 32-bit"), new BuildTargetInfo
101+
{
102+
buildTarget = BuildTarget.StandaloneWindows,
103+
architecture = OSArchitecture.x86
104+
}},
86105
};
87106
default:
88107
return null;
@@ -115,29 +134,45 @@ private static BuildTarget DefaultTargetForPlatform(BuildTarget target)
115134
}
116135
}
117136

118-
private static BuildTarget DefaultArchitectureForTarget(BuildTarget target)
137+
private static BuildTargetInfo DefaultArchitectureForTarget(BuildTarget target)
119138
{
120139
switch (target)
121140
{
122141
case BuildTarget.StandaloneWindows:
123142
case BuildTarget.StandaloneWindows64:
124-
return BuildTarget.StandaloneWindows64;
143+
return new BuildTargetInfo
144+
{
145+
buildTarget = BuildTarget.StandaloneWindows64,
146+
architecture = OSArchitecture.x64
147+
};
125148
// Deprecated
126149
#pragma warning disable 612, 618
127150
case BuildTarget.StandaloneLinux:
128151
case BuildTarget.StandaloneLinuxUniversal:
129152
#pragma warning restore 612, 618
130153
case BuildTarget.StandaloneLinux64:
131-
return BuildTarget.StandaloneLinux64;
154+
return new BuildTargetInfo
155+
{
156+
buildTarget = BuildTarget.StandaloneLinux64,
157+
architecture = OSArchitecture.x64
158+
};
132159
case BuildTarget.StandaloneOSX:
133160
// Deprecated
134161
#pragma warning disable 612, 618
135162
case BuildTarget.StandaloneOSXIntel:
136163
case BuildTarget.StandaloneOSXIntel64:
137164
#pragma warning restore 612, 618
138-
return BuildTarget.StandaloneOSX;
165+
return new BuildTargetInfo
166+
{
167+
buildTarget = BuildTarget.StandaloneOSX,
168+
architecture = OSArchitecture.x64
169+
};
139170
default:
140-
return target;
171+
return new BuildTargetInfo
172+
{
173+
buildTarget = target,
174+
architecture = OSArchitecture.x64
175+
};
141176
}
142177
}
143178

@@ -146,14 +181,14 @@ protected virtual void ShowArchitectureSpecificOptions() {}
146181
public override void ShowPlatformBuildOptions()
147182
{
148183
BuildTarget selectedTarget = GetBestStandaloneTarget(EditorUserBuildSettings.selectedStandaloneTarget);
149-
BuildTarget newTarget = EditorUserBuildSettings.selectedStandaloneTarget;
184+
BuildTargetInfo newTarget = new BuildTargetInfo {buildTarget = EditorUserBuildSettings.selectedStandaloneTarget};
150185

151186
int selectedIndex = Math.Max(0, Array.IndexOf(m_StandaloneSubtargets, DefaultTargetForPlatform(selectedTarget)));
152187
int newIndex = EditorGUILayout.Popup(m_StandaloneTarget, selectedIndex, m_StandaloneSubtargetStrings);
153188

154189
if (newIndex == selectedIndex)
155190
{
156-
Dictionary<GUIContent, BuildTarget> architectures = GetArchitecturesForPlatform(selectedTarget);
191+
Dictionary<GUIContent, BuildTargetInfo> architectures = GetArchitecturesForPlatform(selectedTarget);
157192
if (null != architectures)
158193
{
159194
// Display architectures for the current target platform
@@ -163,7 +198,7 @@ public override void ShowPlatformBuildOptions()
163198
// Grab m_Architecture index for currently selected target
164199
foreach (var architecture in architectures)
165200
{
166-
if (architecture.Value == selectedTarget)
201+
if (architecture.Value.buildTarget == selectedTarget)
167202
{
168203
selectedArchitecture = System.Math.Max(0, System.Array.IndexOf(architectureNames, architecture.Key));
169204
break;
@@ -179,10 +214,11 @@ public override void ShowPlatformBuildOptions()
179214
newTarget = DefaultArchitectureForTarget(m_StandaloneSubtargets[newIndex]);
180215
}
181216

182-
if (newTarget != EditorUserBuildSettings.selectedStandaloneTarget)
217+
if (newTarget.buildTarget != EditorUserBuildSettings.selectedStandaloneTarget)
183218
{
184219
// setting selectedStandaloneTarget has side-effect: stops playmode
185-
EditorUserBuildSettings.selectedStandaloneTarget = newTarget;
220+
EditorUserBuildSettings.selectedStandaloneTarget = newTarget.buildTarget;
221+
SetArchitectureForPlatform(newTarget.buildTarget, newTarget.architecture);
186222
GUIUtility.ExitGUI();
187223
}
188224

@@ -208,19 +244,20 @@ public override bool EnabledBuildButton()
208244
protected virtual string GetCannotBuildPlayerInCurrentSetupError()
209245
{
210246
var namedBuildTarget = EditorUserBuildSettingsUtils.CalculateSelectedNamedBuildTarget();
247+
var scriptingBackend = PlayerSettings.GetScriptingBackend(namedBuildTarget);
211248

212249
if (namedBuildTarget == NamedBuildTarget.Server)
213250
{
214251
if(!m_HasServerPlayers)
215252
return $"Dedicated Server support for {GetHostPlatformName()} is not installed.";
216253

217-
if (PlayerSettings.GetScriptingBackend(namedBuildTarget) == ScriptingImplementation.IL2CPP && !m_IsRunningOnHostPlatform)
254+
if (scriptingBackend == ScriptingImplementation.IL2CPP && !m_IsRunningOnHostPlatform)
218255
return string.Format("{0} IL2CPP player can only be built on {0}.", GetHostPlatformName());
219256

220257
return null;
221258
}
222259

223-
switch(PlayerSettings.GetScriptingBackend(namedBuildTarget))
260+
switch(scriptingBackend)
224261
{
225262
case ScriptingImplementation.Mono2x:
226263
{
@@ -232,7 +269,7 @@ protected virtual string GetCannotBuildPlayerInCurrentSetupError()
232269
case ScriptingImplementation.CoreCLR:
233270
{
234271
if (!m_HasCoreCLRPlayers)
235-
return $"Currently selected scripting backend (CoreCLR) is not {(Unsupported.IsSourceBuild() ? "installed" : "supported")}.";
272+
return $"Currently selected scripting backend (CoreCLR) is not {(Unsupported.IsSourceBuild() ? "installed" : "supported")}."; // CORECLR_FIXME remove sourcebuild
236273
break;
237274
}
238275
case ScriptingImplementation.IL2CPP:
@@ -245,7 +282,7 @@ protected virtual string GetCannotBuildPlayerInCurrentSetupError()
245282
}
246283
default:
247284
{
248-
return $"Unknown scripting backend: {PlayerSettings.GetScriptingBackend(namedBuildTarget)}";
285+
return $"Unknown scripting backend: {scriptingBackend}";
249286
}
250287
}
251288

Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected virtual string GetVariationName(BuildPostProcessArgs args)
2323
GetPlatformString(args),
2424
GetServer(args) ? "server" : "player",
2525
GetDevelopment(args) ? "development" : "nondevelopment",
26-
GetUseIl2Cpp(args) ? "il2cpp" : "mono");
26+
GetUseIl2Cpp(args) ? "il2cpp" : (GetUseCoreCLR(args) ? "coreclr" : "mono"));
2727
}
2828

2929
protected bool GetServer(BuildPostProcessArgs args) =>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
namespace UnityEditor.Build
6+
{
7+
internal enum OSArchitecture
8+
{
9+
x64,
10+
ARM64,
11+
x64ARM64,
12+
x86,
13+
}
14+
}

0 commit comments

Comments
 (0)