Skip to content

Commit f2bb759

Browse files
author
Unity Technologies
committed
Unity 2018.1.8f1 C# reference source code
1 parent e5cfc6d commit f2bb759

10 files changed

Lines changed: 127 additions & 65 deletions

File tree

Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static public void LaunchOnTargets(BuildTargetGroup targetGroup, BuildTarget bui
189189
try
190190
{
191191
// Early out so as not to show/update progressbars unnecessarily
192-
if (buildReport == null || !DeploymentTargetManager.IsExtensionSupported(targetGroup, buildReport.summary.platform))
192+
if (buildReport == null)
193193
throw new System.NotSupportedException();
194194

195195
ProgressHandler progressHandler = new ProgressHandler("Deploying Player",
@@ -210,7 +210,9 @@ static public void LaunchOnTargets(BuildTargetGroup targetGroup, BuildTarget bui
210210
{
211211
try
212212
{
213-
DeploymentTargetManager.LaunchBuildOnTarget(targetGroup, buildReport, target, taskManager.SpawnProgressHandlerFromCurrentTask());
213+
var manager = DeploymentTargetManager.CreateInstance(targetGroup, buildReport.summary.platform);
214+
var buildProperties = BuildProperties.GetFromBuildReport(buildReport);
215+
manager.LaunchBuildOnTarget(buildProperties, target, taskManager.SpawnProgressHandlerFromCurrentTask());
214216
successfulLaunches++;
215217
}
216218
catch (DeploymentOperationFailedException e)

Editor/Mono/DeploymentTargets/DefaultDeploymentTargetsExtension.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
using System;
66
using System.Collections.Generic;
77
using UnityEditor.Modules;
8+
using UnityEditorInternal;
89

910
namespace UnityEditor.DeploymentTargets
1011
{
12+
internal class DefaultDeploymentTargetsMainThreadContext : IDeploymentTargetsMainThreadContext
13+
{
14+
}
15+
1116
internal class DefaultDeploymentTargetInfo : IDeploymentTargetInfo
1217
{
1318
public virtual FlagSet<DeploymentTargetSupportFlags> GetSupportFlags()
@@ -20,26 +25,43 @@ public virtual TargetCheckResult CheckTarget(DeploymentTargetRequirements target
2025
return new TargetCheckResult();
2126
}
2227

23-
public string GetDisplayName()
28+
public virtual string GetDisplayName()
2429
{
2530
return "";
2631
}
32+
33+
public virtual bool SupportsLaunchBuild(BuildProperties buildProperties)
34+
{
35+
return GetSupportFlags().HasFlags(DeploymentTargetSupportFlags.Launch) && CheckTarget(buildProperties.GetTargetRequirements()).Passed();
36+
}
2737
}
2838

2939
internal abstract class DefaultDeploymentTargetsExtension
3040
: IDeploymentTargetsExtension
3141
{
32-
public virtual List<DeploymentTargetIdAndStatus> GetKnownTargets(ProgressHandler progressHandler = null)
42+
public virtual IDeploymentTargetsMainThreadContext GetMainThreadContext(bool setup)
43+
{
44+
CheckGetMainThreadContextCalledOnMainThread();
45+
return new DefaultDeploymentTargetsMainThreadContext();
46+
}
47+
48+
protected void CheckGetMainThreadContextCalledOnMainThread()
49+
{
50+
if (!InternalEditorUtility.CurrentThreadIsMainThread())
51+
throw new NotSupportedException("Deployment targets main thread context can only be retrieved from the main thread.");
52+
}
53+
54+
public virtual List<DeploymentTargetIdAndStatus> GetKnownTargets(IDeploymentTargetsMainThreadContext context, ProgressHandler progressHandler = null)
3355
{
3456
return new List<DeploymentTargetIdAndStatus>();
3557
}
3658

37-
public virtual IDeploymentTargetInfo GetTargetInfo(DeploymentTargetId targetId, ProgressHandler progressHandler = null)
59+
public virtual IDeploymentTargetInfo GetTargetInfo(IDeploymentTargetsMainThreadContext context, DeploymentTargetId targetId, ProgressHandler progressHandler = null)
3860
{
3961
return new DefaultDeploymentTargetInfo();
4062
}
4163

42-
public virtual void LaunchBuildOnTarget(BuildProperties buildProperties, DeploymentTargetId targetId, ProgressHandler progressHandler = null)
64+
public virtual void LaunchBuildOnTarget(IDeploymentTargetsMainThreadContext context, BuildProperties buildProperties, DeploymentTargetId targetId, ProgressHandler progressHandler = null)
4365
{
4466
throw new NotSupportedException();
4567
}

Editor/Mono/DeploymentTargets/DeploymentTargetManager.cs

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,71 @@
44

55
using System;
66
using System.Collections.Generic;
7-
using System.Linq;
87
using UnityEditor.Modules;
98
using UnityEditor.Build.Reporting;
10-
using UnityEngine;
119

1210
namespace UnityEditor.DeploymentTargets
1311
{
14-
internal class DeploymentTargetManager
12+
class DeploymentTargetManager
1513
{
16-
const string kExtensionErrorMessage = "Platform does not implement DeploymentTargetsExtension";
14+
const string k_ExtensionErrorMessage = "Platform does not implement DeploymentTargetsExtension";
1715

18-
private static IDeploymentTargetsExtension GetExtension(BuildTargetGroup targetGroup, BuildTarget buildTarget)
19-
{
20-
IDeploymentTargetsExtension extension = ModuleManager.GetDeploymentTargetsExtension(targetGroup, buildTarget);
21-
if (extension == null)
22-
throw new NotSupportedException(kExtensionErrorMessage);
23-
return extension;
24-
}
16+
readonly IDeploymentTargetsExtension m_Extension;
17+
readonly IDeploymentTargetsMainThreadContext m_Context;
2518

26-
public static bool IsExtensionSupported(BuildTargetGroup targetGroup, BuildTarget buildTarget)
27-
{
28-
return ModuleManager.GetDeploymentTargetsExtension(targetGroup, buildTarget) != null;
29-
}
19+
public IDeploymentTargetsMainThreadContext Context { get { return m_Context; }}
3020

31-
public static IDeploymentTargetInfo GetTargetInfo(BuildTargetGroup targetGroup, BuildTarget buildTarget, DeploymentTargetId targetId)
21+
public static DeploymentTargetManager CreateInstance(BuildTargetGroup targetGroup, BuildTarget buildTarget, bool setup = true)
3222
{
33-
IDeploymentTargetsExtension extension = GetExtension(targetGroup, buildTarget);
34-
return extension.GetTargetInfo(targetId);
23+
var extension = GetExtension(targetGroup, buildTarget);
24+
var context = extension.GetMainThreadContext(setup);
25+
return context != null ? new DeploymentTargetManager(extension, context) : null;
3526
}
3627

37-
public static bool SupportsLaunchBuild(IDeploymentTargetInfo info, BuildProperties buildProperties)
28+
DeploymentTargetManager(IDeploymentTargetsExtension extension, IDeploymentTargetsMainThreadContext context)
3829
{
39-
return info.GetSupportFlags().HasFlags(DeploymentTargetSupportFlags.Launch) &&
40-
info.CheckTarget(buildProperties.GetTargetRequirements()).Passed();
30+
m_Extension = extension;
31+
m_Context = context;
4132
}
4233

43-
public static bool SupportsLaunchBuild(IDeploymentTargetInfo info, BuildReport buildReport)
34+
static IDeploymentTargetsExtension GetExtension(BuildTargetGroup targetGroup, BuildTarget buildTarget)
4435
{
45-
return SupportsLaunchBuild(info, BuildProperties.GetFromBuildReport(buildReport));
36+
var extension = ModuleManager.GetDeploymentTargetsExtension(targetGroup, buildTarget);
37+
if (extension == null)
38+
throw new NotSupportedException(k_ExtensionErrorMessage);
39+
return extension;
4640
}
4741

48-
public static void LaunchBuildOnTarget(BuildTargetGroup targetGroup, BuildTarget buildTarget, BuildProperties buildProperties, DeploymentTargetId targetId, ProgressHandler progressHandler = null)
42+
public IDeploymentTargetInfo GetTargetInfo(DeploymentTargetId targetId)
4943
{
50-
IDeploymentTargetsExtension extension = GetExtension(targetGroup, buildTarget);
51-
extension.LaunchBuildOnTarget(buildProperties, targetId, progressHandler);
44+
return m_Extension.GetTargetInfo(m_Context, targetId);
5245
}
5346

54-
public static void LaunchBuildOnTarget(BuildTargetGroup targetGroup, BuildReport buildReport, DeploymentTargetId targetId, ProgressHandler progressHandler = null)
47+
public void LaunchBuildOnTarget(BuildProperties buildProperties, DeploymentTargetId targetId, ProgressHandler progressHandler = null)
5548
{
56-
LaunchBuildOnTarget(targetGroup, buildReport.summary.platform, BuildProperties.GetFromBuildReport(buildReport), targetId, progressHandler);
49+
m_Extension.LaunchBuildOnTarget(m_Context, buildProperties, targetId, progressHandler);
5750
}
5851

59-
public static List<DeploymentTargetIdAndStatus> GetKnownTargets(BuildTargetGroup targetGroup, BuildTarget buildTarget)
52+
public List<DeploymentTargetIdAndStatus> GetKnownTargets()
6053
{
61-
IDeploymentTargetsExtension extension = GetExtension(targetGroup, buildTarget);
62-
return extension.GetKnownTargets();
54+
return m_Extension.GetKnownTargets(m_Context);
6355
}
6456

6557
// Launch a build on any target on a platform
66-
public static List<DeploymentTargetId> FindValidTargetsForLaunchBuild(BuildTargetGroup targetGroup, BuildTarget buildTarget, BuildProperties buildProperties)
58+
public List<DeploymentTargetId> FindValidTargetsForLaunchBuild(BuildProperties buildProperties)
6759
{
68-
IDeploymentTargetsExtension extension = GetExtension(targetGroup, buildTarget);
69-
List<DeploymentTargetId> validTargetIds = new List<DeploymentTargetId>();
70-
List<DeploymentTargetIdAndStatus> knownTargets = extension.GetKnownTargets();
60+
var validTargetIds = new List<DeploymentTargetId>();
61+
var knownTargets = m_Extension.GetKnownTargets(m_Context);
7162
foreach (var target in knownTargets)
7263
{
7364
if (target.status == DeploymentTargetStatus.Ready)
7465
{
75-
if (SupportsLaunchBuild(extension.GetTargetInfo(target.id), buildProperties))
66+
var targetInfo = m_Extension.GetTargetInfo(m_Context, target.id);
67+
if (targetInfo.SupportsLaunchBuild(buildProperties))
7668
validTargetIds.Add(target.id);
7769
}
7870
}
7971
return validTargetIds;
8072
}
81-
82-
public static List<DeploymentTargetId> FindValidTargetsForLaunchBuild(BuildTargetGroup targetGroup, BuildReport buildReport)
83-
{
84-
return FindValidTargetsForLaunchBuild(targetGroup, buildReport.summary.platform, BuildProperties.GetFromBuildReport(buildReport));
85-
}
8673
}
8774
}

Editor/Mono/DeploymentTargets/IDeploymentTargetsExtension.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ internal interface IDeploymentTargetInfo
102102
TargetCheckResult CheckTarget(DeploymentTargetRequirements targetRequirements);
103103

104104
string GetDisplayName();
105+
106+
bool SupportsLaunchBuild(BuildProperties buildProperties);
107+
}
108+
109+
internal interface IDeploymentTargetsMainThreadContext
110+
{
105111
}
106112

107113
internal class DeploymentOperationAbortedException : Exception {}
@@ -122,20 +128,27 @@ public CorruptBuildException(string message = "Corrupt build.", Exception inner
122128

123129
internal interface IDeploymentTargetsExtension
124130
{
131+
// Returns context object populated with data that other methods can access from any thread.
132+
// setup - Pass true to setup platform if it hasn't been already setup (e.g. display dialog box to select SDK path). Throws exception if user cancels setup process.
133+
// Pass false to return null if platform hasn't been already setup. This is useful when this method is called from UI draw event.
134+
// Displaying dialog boxes at that point breaks UI. Let the user know what's going on by displaying informational label or something like that.
135+
// Can NOT be called from a background thread
136+
IDeploymentTargetsMainThreadContext GetMainThreadContext(bool setup = true);
137+
125138
// Returns a list of all known targets and their status
126139
// Can be called from a background thread
127-
List<DeploymentTargetIdAndStatus> GetKnownTargets(ProgressHandler progressHandler = null);
140+
List<DeploymentTargetIdAndStatus> GetKnownTargets(IDeploymentTargetsMainThreadContext context, ProgressHandler progressHandler = null);
128141

129142
// Returns info for a target
130143
// Throws DeploymentOperationFailedException (or one of its subclasses) is something goes wrong.
131144
// Throws DeploymentOperationAbortedException if process is cancelled by the user.
132145
// Can be called from a background thread
133-
IDeploymentTargetInfo GetTargetInfo(DeploymentTargetId targetId, ProgressHandler progressHandler = null);
146+
IDeploymentTargetInfo GetTargetInfo(IDeploymentTargetsMainThreadContext context, DeploymentTargetId targetId, ProgressHandler progressHandler = null);
134147

135148
// Launches a build on a target
136149
// Throws DeploymentOperationFailedException (or one of its subclasses) is something goes wrong.
137150
// Throws DeploymentOperationAbortedException if process is cancelled by the user.
138151
// Can be called from a background thread
139-
void LaunchBuildOnTarget(BuildProperties buildProperties, DeploymentTargetId targetId, ProgressHandler progressHandler = null);
152+
void LaunchBuildOnTarget(IDeploymentTargetsMainThreadContext context, BuildProperties buildProperties, DeploymentTargetId targetId, ProgressHandler progressHandler = null);
140153
}
141154
}

Editor/Mono/EditorApplication.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
86
using System.Text;
9-
using UnityEngine.SceneManagement;
10-
using UnityEditor.SceneManagement;
117
using UnityEngine;
128
using UnityEngine.Events;
139
using UnityEngine.Scripting;
1410
using UnityEditorInternal;
11+
using UnityEditor.Scripting.ScriptCompilation;
1512

1613
namespace UnityEditor
1714
{
@@ -312,5 +309,13 @@ static void Internal_CallGlobalEventHandler()
312309

313310
Event.current = null;
314311
}
312+
313+
public static bool isCompiling
314+
{
315+
get
316+
{
317+
return EditorCompilationInterface.IsCompiling();
318+
}
319+
}
315320
}
316321
}

Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,19 @@ public bool DoesProjectFolderHaveAnyScripts()
875875
return allScripts != null && allScripts.Count > 0;
876876
}
877877

878+
public bool DoesProjectHaveAnyCustomScriptAssemblies()
879+
{
880+
foreach (var script in allScripts)
881+
{
882+
var targetAssembly = EditorBuildRules.GetTargetAssembly(script, projectDirectory, customTargetAssemblies);
883+
884+
if (targetAssembly.Type == EditorBuildRules.TargetAssemblyType.Custom)
885+
return true;
886+
}
887+
888+
return false;
889+
}
890+
878891
ScriptAssemblySettings CreateScriptAssemblySettings(BuildTargetGroup buildTargetGroup, BuildTarget buildTarget, EditorScriptCompilationOptions options)
879892
{
880893
var defines = InternalEditorUtility.GetCompilationDefines(options, buildTargetGroup, buildTarget);

Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ public static bool DoesProjectFolderHaveAnyScripts()
240240
return Instance.DoesProjectFolderHaveAnyScripts();
241241
}
242242

243+
[RequiredByNativeCode]
244+
public static bool DoesProjectHaveAnyCustomScriptAssemblies()
245+
{
246+
return Instance.DoesProjectHaveAnyCustomScriptAssemblies();
247+
}
248+
243249
[RequiredByNativeCode]
244250
public static EditorCompilation.AssemblyCompilerMessages[] GetCompileMessages()
245251
{

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Unity 2018.1.7f1 C# reference source code
1+
## Unity 2018.1.8f1 C# reference source code
22

33
The C# part of the Unity engine and editor source code.
44
May be used for reference purposes only.

Runtime/Export/SystemInfo.bindings.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,30 @@ public static int supportsStencil
328328
get { return 1; }
329329
}
330330

331+
// The enums are only marked as obsolete in the editor.
332+
static bool IsObsolete(Enum value)
333+
{
334+
var fieldInfo = value.GetType().GetField(value.ToString());
335+
var attributes = (ObsoleteAttribute[])fieldInfo.GetCustomAttributes(typeof(ObsoleteAttribute), false);
336+
return (attributes != null && attributes.Length > 0);
337+
}
338+
339+
340+
static bool IsValidEnumValue(Enum value)
341+
{
342+
if (!Enum.IsDefined(value.GetType(), value))
343+
return false;
344+
345+
if (IsObsolete(value))
346+
return false;
347+
348+
return true;
349+
}
350+
331351
// Is render texture format supported?
332352
public static bool SupportsRenderTextureFormat(RenderTextureFormat format)
333353
{
334-
if (!Enum.IsDefined(typeof(RenderTextureFormat), format))
354+
if (!IsValidEnumValue(format))
335355
throw new ArgumentException("Failed SupportsRenderTextureFormat; format is not a valid RenderTextureFormat");
336356

337357
return HasRenderTextureNative(format);
@@ -340,15 +360,15 @@ public static bool SupportsRenderTextureFormat(RenderTextureFormat format)
340360
// Is render texture format supports blending?
341361
public static bool SupportsBlendingOnRenderTextureFormat(RenderTextureFormat format)
342362
{
343-
if (!Enum.IsDefined(typeof(RenderTextureFormat), format))
363+
if (!IsValidEnumValue(format))
344364
throw new ArgumentException("Failed SupportsBlendingOnRenderTextureFormat; format is not a valid RenderTextureFormat");
345365

346366
return SupportsBlendingOnRenderTextureFormatNative(format);
347367
}
348368

349369
public static bool SupportsTextureFormat(TextureFormat format)
350370
{
351-
if (!Enum.IsDefined(typeof(TextureFormat), format))
371+
if (!IsValidEnumValue(format))
352372
throw new ArgumentException("Failed SupportsTextureFormat; format is not a valid TextureFormat");
353373

354374
return SupportsTextureFormatNative(format);

artifacts/generated/bindings_old/common/Editor/EditorApplicationBindings.gen.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using UsedByNativeCodeAttribute=UnityEngine.Scripting.UsedByNativeCodeAttribute;
99

1010
using System;
11+
using UnityEditor.Scripting.ScriptCompilation;
1112
using UnityEngine;
1213
using Object = UnityEngine.Object;
1314

@@ -79,13 +80,6 @@ public extern static bool isPaused
7980
set;
8081
}
8182

82-
public extern static bool isCompiling
83-
{
84-
[UnityEngine.Scripting.GeneratedByOldBindingsGeneratorAttribute] // Temporarily necessary for bindings migration
85-
[System.Runtime.CompilerServices.MethodImplAttribute((System.Runtime.CompilerServices.MethodImplOptions)0x1000)]
86-
get;
87-
}
88-
8983
public extern static bool isUpdating
9084
{
9185
[UnityEngine.Scripting.GeneratedByOldBindingsGeneratorAttribute] // Temporarily necessary for bindings migration

0 commit comments

Comments
 (0)