Skip to content

Commit

Permalink
Unity 6000.0.20f1 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Sep 19, 2024
1 parent d487c13 commit 23bb6a2
Show file tree
Hide file tree
Showing 84 changed files with 1,754 additions and 755 deletions.
2 changes: 1 addition & 1 deletion Editor/Mono/BuildPipeline.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public static BuildReport BuildPlayer(BuildPlayerWithProfileOptions buildPlayerW
if (buildProfile == null)
throw new ArgumentException("Build profile is invalid.");

BuildProfileContext.instance.activeProfile = buildProfile;
BuildProfileContext.activeProfile = buildProfile;
var buildPlayerOptions = BuildProfileModuleUtil.GetBuildPlayerOptionsFromActiveProfile(
buildPlayerWithProfileOptions.locationPathName, buildPlayerWithProfileOptions.assetBundleManifestPath, buildPlayerWithProfileOptions.options);
return BuildPlayer(buildPlayerOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ protected virtual string GetCannotBuildPlayerInCurrentSetupError()
protected abstract RuntimePlatform GetHostPlatform();
protected abstract string GetHostPlatformName();

public override bool EnabledBuildAndRunButton()
{
return true;
}

public override bool ShouldDrawWaitForManagedDebugger()
{
return true;
Expand Down
15 changes: 7 additions & 8 deletions Editor/Mono/BuildProfile/BuildProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,14 @@ public EditorBuildSettingsScene[] scenes
m_Scenes = value;
CheckSceneListConsistency();

if (this == BuildProfileContext.instance.activeProfile)
if (this == BuildProfileContext.activeProfile)
EditorBuildSettings.SceneListChanged();
}
}

/// <summary>
/// Scripting Compilation Defines used during player and editor builds.
/// </summary>
/// <remarks>
/// <see cref="EditorUserBuildSettings.GetActiveProfileYamlScriptingDefines"/> fetches active profile
/// define be deserializing the YAML file and assumes defines will be found under "m_ScriptingDefines" node.
/// </remarks>
[SerializeField] private string[] m_ScriptingDefines = Array.Empty<string>();
public string[] scriptingDefines
{
Expand Down Expand Up @@ -144,10 +140,10 @@ internal PlayerSettings playerSettings
[VisibleToOtherModules]
internal bool IsActiveBuildProfileOrPlatform()
{
if (BuildProfileContext.instance.activeProfile == this)
if (BuildProfileContext.activeProfile == this)
return true;

if (BuildProfileContext.instance.activeProfile is not null
if (BuildProfileContext.activeProfile is not null
|| !BuildProfileContext.IsClassicPlatformProfile(this))
return false;

Expand Down Expand Up @@ -190,7 +186,7 @@ void OnEnable()
LoadPlayerSettings();

if (!EditorUserBuildSettings.isBuildProfileAvailable
|| BuildProfileContext.instance.activeProfile != this)
|| BuildProfileContext.activeProfile != this)
return;

// On disk changes invoke OnEnable,
Expand All @@ -206,6 +202,9 @@ void OnEnable()

void OnDisable()
{
if (IsActiveBuildProfileOrPlatform())
EditorUserBuildSettings.SetActiveProfileScriptingDefines(m_ScriptingDefines);

var playerSettingsDirty = EditorUtility.IsDirty(m_PlayerSettings);
if (playerSettingsDirty)
{
Expand Down
4 changes: 2 additions & 2 deletions Editor/Mono/BuildProfile/BuildProfileAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed partial class BuildProfile
/// </returns>
public static BuildProfile GetActiveBuildProfile()
{
return BuildProfileContext.instance.activeProfile;
return BuildProfileContext.activeProfile;
}

/// <summary>
Expand All @@ -26,7 +26,7 @@ public static BuildProfile GetActiveBuildProfile()
/// </param>
public static void SetActiveBuildProfile(BuildProfile buildProfile)
{
BuildProfileContext.instance.activeProfile = buildProfile;
BuildProfileContext.activeProfile = buildProfile;

if (buildProfile == null)
return;
Expand Down
27 changes: 0 additions & 27 deletions Editor/Mono/BuildProfile/BuildProfileCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@ namespace UnityEditor.Build.Profile
{
internal static class BuildProfileCLI
{
[RequiredByNativeCode]
internal static bool SetActiveBuildProfileFromPath(string buildProfilePath)
{
if (LoadFromPath(buildProfilePath, out BuildProfile buildProfile))
{
BuildProfileContext.instance.activeProfile = buildProfile;
return true;
}

return false;
}

static bool LoadFromPath(string buildProfilePath, out BuildProfile buildProfile)
{
if (AssetDatabase.AssetPathExists(buildProfilePath))
{
buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(buildProfilePath);
}
else
{
buildProfile = null;
Debug.LogError($"Couldn't find build profile asset for path {buildProfilePath}");
}

return buildProfile != null;
}

[RequiredByNativeCode]
static void BuildActiveProfileWithPath(string locationPathName)
{
Expand Down
89 changes: 49 additions & 40 deletions Editor/Mono/BuildProfile/BuildProfileContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ internal sealed class BuildProfileContext : ScriptableObject
const string k_SharedProfilePath = $"{k_BuildProfilePath}/SharedProfile.asset";
static BuildProfileContext s_Instance;

[SerializeField]
BuildProfile m_ActiveProfile;

[SerializeField]
string[] m_CachedEditorScriptingDefines = Array.Empty<string>();

Expand Down Expand Up @@ -64,54 +61,57 @@ internal string[] cachedEditorScriptingDefines
/// perspective Classic Platform and Build Profiles are different concepts.
/// </remarks>
[VisibleToOtherModules]
internal BuildProfile activeProfile
internal static BuildProfile activeProfile
{
get
{
// Active Build profile may be deleted from the project.
if (m_ActiveProfile != null && m_ActiveProfile.CanBuildLocally())
return m_ActiveProfile;
var activeProfile = EditorUserBuildSettings.activeBuildProfile;
if (activeProfile != null && activeProfile.CanBuildLocally())
return activeProfile;

m_ActiveProfile = null;
return null;
}

set
{
if (m_ActiveProfile == value)
return;
var prev = EditorUserBuildSettings.activeBuildProfile;

var prev = m_ActiveProfile;
if (value == null || value.platformBuildProfile == null)
{
m_ActiveProfile.UpdateGlobalManagerPlayerSettings(activeWillBeRemoved: true);
m_ActiveProfile = null;
Save();
EditorUserBuildSettings.SetBuildProfilePath(string.Empty);
activeProfileChanged?.Invoke(prev, m_ActiveProfile);
prev?.UpdateGlobalManagerPlayerSettings(activeWillBeRemoved: true);
EditorUserBuildSettings.activeBuildProfile = null;

activeProfileChanged?.Invoke(prev, null);
OnActiveProfileChangedForSettingExtension(prev, null);
BuildProfileModuleUtil.RequestScriptCompilation(null);
return;
}

if (m_PlatformIdToClassicPlatformProfile.TryGetValue(
// Only compare prev with value after the null check, as
// EditorUserBuildSettings.activeBuildProfile will return null
// if the build profile has been destroyed but on native side
// it's still pointing to a dead pptr.
if (ReferenceEquals(prev, value))
return;

if (s_Instance != null && s_Instance.m_PlatformIdToClassicPlatformProfile.TryGetValue(
value.platformId, out var entry) && entry == value)
{
Debug.LogWarning("[BuildProfile] Classic Platforms cannot be set as the active build profile.");
return;
}

m_ActiveProfile = value;
Save();
EditorUserBuildSettings.SetBuildProfilePath(AssetDatabase.GetAssetPath(m_ActiveProfile));
activeProfileChanged?.Invoke(prev, m_ActiveProfile);
OnActiveProfileChangedForSettingExtension(prev, m_ActiveProfile);
m_ActiveProfile.UpdateGlobalManagerPlayerSettings();
BuildProfileModuleUtil.RequestScriptCompilation(m_ActiveProfile);
EditorUserBuildSettings.activeBuildProfile = value;

activeProfileChanged?.Invoke(prev, value);
OnActiveProfileChangedForSettingExtension(prev, value);
value.UpdateGlobalManagerPlayerSettings();
BuildProfileModuleUtil.RequestScriptCompilation(value);
}
}

void OnActiveProfileChangedForSettingExtension(BuildProfile previous, BuildProfile newProfile)
static void OnActiveProfileChangedForSettingExtension(BuildProfile previous, BuildProfile newProfile)
{
BuildTargetDiscovery.TryGetBuildTarget(EditorUserBuildSettings.activeBuildTarget, out IBuildTarget iBuildTarget);
if (iBuildTarget == null)
Expand Down Expand Up @@ -216,7 +216,7 @@ internal static BuildProfile GetActiveOrClassicBuildProfile(
BuildTarget target, StandaloneBuildSubtarget subTarget = StandaloneBuildSubtarget.Default, string sharedSetting = null)
{
if (ShouldReturnActiveProfile(target, subTarget, sharedSetting))
return instance.activeProfile;
return activeProfile;

// For backwards compatibility, getter will look for
// the classic platform build profile for the target platform
Expand Down Expand Up @@ -331,8 +331,6 @@ void SyncActiveProfileToFallback()
void OnDisable()
{
Save();
EditorUserBuildSettings.SetBuildProfilePath((m_ActiveProfile != null) ?
AssetDatabase.GetAssetPath(m_ActiveProfile) : string.Empty);

// Platform profiles must be manually serialized for changes to persist.
foreach (var kvp in m_PlatformIdToClassicPlatformProfile)
Expand Down Expand Up @@ -405,13 +403,19 @@ void OnEnable()
sharedProfile = sharedProfileObj;
}

var buildProfile = activeProfile ?? GetForClassicPlatform(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.standaloneBuildSubtarget);
var buildProfile = activeProfile;

// profile can be null if we're in the middle of creating classic profiles
if (buildProfile == null)
return;
{
buildProfile = GetForClassicPlatform(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.standaloneBuildSubtarget);

EditorUserBuildSettings.CopyToBuildProfile(buildProfile);
// profile can be null if we're in the middle of creating classic profiles
if (buildProfile == null)
return;

// We only copy EditorUserBuildSettings into the build profile for classic platforms as we don't want to modify actual user assets
EditorUserBuildSettings.CopyToBuildProfile(buildProfile);
}

string module = BuildTargetDiscovery.GetModuleNameForBuildTarget(buildProfile.buildTarget);
var extension = ModuleManager.GetBuildProfileExtension(module);
Expand Down Expand Up @@ -587,13 +591,11 @@ static void CreateOrLoad()
System.Diagnostics.Debug.Assert(s_Instance != null);
s_Instance.CheckInstalledBuildPlatforms();

EditorUserBuildSettings.SetBuildProfilePath((s_Instance.m_ActiveProfile != null) ?
AssetDatabase.GetAssetPath(s_Instance.m_ActiveProfile) : string.Empty);
s_Instance.cachedEditorScriptingDefines = BuildDefines.GetBuildProfileScriptDefines();

BuildProfileModuleUtil.DeleteLastRunnableBuildKeyForDeletedProfiles();

s_Instance.OnActiveProfileChangedForSettingExtension(null, s_Instance.m_ActiveProfile);
OnActiveProfileChangedForSettingExtension(null, activeProfile);
}

[RequiredByNativeCode, UsedImplicitly]
Expand All @@ -620,6 +622,12 @@ static void SetActiveOrClassicProfileRawPlatformSetting(string settingName, stri
}
}

[RequiredByNativeCode, UsedImplicitly]
static void EnsureInitialized()
{
GC.KeepAlive(instance);
}

[RequiredByNativeCode, UsedImplicitly]
static string GetActiveOrClassicProfileRawPlatformSetting(string settingName, BuildTarget target, StandaloneBuildSubtarget subtarget)
{
Expand All @@ -643,16 +651,17 @@ static string GetActiveOrClassicProfileRawPlatformSetting(string settingName, Bu
[RequiredByNativeCode]
static string GetActiveBuildProfilePath()
{
if (instance.activeProfile)
return AssetDatabase.GetAssetPath(instance.activeProfile);
var activeProfile = BuildProfileContext.activeProfile;
if (activeProfile)
return AssetDatabase.GetAssetPath(activeProfile);

return string.Empty;
}

[RequiredByNativeCode]
static bool HasActiveProfileWithPlayerSettings(out int instanceID)
{
var activeProfile = instance.activeProfile;
var activeProfile = BuildProfileContext.activeProfile;
if (activeProfile?.playerSettings != null)
{
instanceID = activeProfile.GetInstanceID();
Expand All @@ -666,15 +675,15 @@ static bool HasActiveProfileWithPlayerSettings(out int instanceID)
[RequiredByNativeCode]
static void UpdateActiveProfilePlayerSettingsObjectFromYAML()
{
instance.activeProfile?.UpdatePlayerSettingsObjectFromYAML();
activeProfile?.UpdatePlayerSettingsObjectFromYAML();
}

static bool ShouldReturnActiveProfile(BuildTarget buildTarget, StandaloneBuildSubtarget subtarget, string sharedSetting = null)
{
if (!string.IsNullOrEmpty(sharedSetting))
return IsSharedSettingEnabledInActiveProfile(sharedSetting);

var activeProfile = instance.activeProfile;
var activeProfile = BuildProfileContext.activeProfile;
if (activeProfile == null || buildTarget == BuildTarget.NoTarget)
return false;

Expand All @@ -684,7 +693,7 @@ static bool ShouldReturnActiveProfile(BuildTarget buildTarget, StandaloneBuildSu

static bool IsSharedSettingEnabledInActiveProfile(string settingName)
{
var activeProfile = instance.activeProfile;
var activeProfile = BuildProfileContext.activeProfile;
if (activeProfile == null)
return false;

Expand Down
Loading

0 comments on commit 23bb6a2

Please sign in to comment.