Skip to content

Commit

Permalink
Unity 6000.0.0b16 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Apr 19, 2024
1 parent 750cd77 commit 22a9cc4
Show file tree
Hide file tree
Showing 89 changed files with 2,087 additions and 824 deletions.
8 changes: 8 additions & 0 deletions Editor/Mono/Audio/AudioContainerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ void OnDisable()
m_AddedElements.Clear();
}

private void OnFocus()
{
if (State.AudioContainer != null)
{
UpdateTransportButtonStates();
}
}

void Update()
{
if (!m_IsVisible)
Expand Down
31 changes: 31 additions & 0 deletions Editor/Mono/BuildPipeline.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using UnityEditor.Scripting.ScriptCompilation;
using System.Runtime.InteropServices;
using UnityEditor.Build;
using UnityEditor.Build.Profile;
using UnityEngine.Scripting;

namespace UnityEditor
Expand Down Expand Up @@ -223,6 +224,14 @@ public struct BuildPlayerOptions
public string[] extraScriptingDefines { get; set; }
}

public struct BuildPlayerWithProfileOptions
{
public BuildProfile buildProfile { get; set; }
public string locationPathName { get; set; }
public string assetBundleManifestPath { get; set; }
public BuildOptions options { get; set; }
}

internal struct BuildPlayerDataOptions
{
public string[] scenes { get; set; }
Expand Down Expand Up @@ -276,6 +285,10 @@ public class BuildPipeline
[FreeFunction(IsThreadSafe = true)]
internal static extern string GetEditorTargetName();

[NativeHeader("Editor/Src/BuildPipeline/BuildPlayerHelpers.h")]
[FreeFunction]
internal static extern void ShowBuildProfileWindow();

[Obsolete("PushAssetDependencies has been made obsolete. Please use the new AssetBundle build system introduced in 5.0 and check BuildAssetBundles documentation for details.", true)]
[FreeFunction]
public static extern void PushAssetDependencies();
Expand All @@ -302,6 +315,24 @@ internal static BuildPlayerContext PreparePlayerBuild(BuildPlayerOptions buildPl
return buildPlayerContext;
}

/// <summary>
/// Builds a player.
/// </summary>
/// <param name="buildPlayerWithProfileOptions">The BuildPlayerWithProfileOptions to be built with.</param>
/// <returns>A BuildReport giving build process information.</returns>
/// <exception cref="ArgumentException">Throws if build profile is null.</exception>
public static BuildReport BuildPlayer(BuildPlayerWithProfileOptions buildPlayerWithProfileOptions)
{
var buildProfile = buildPlayerWithProfileOptions.buildProfile;
if (buildProfile == null)
throw new ArgumentException("Build profile is invalid.");

BuildProfileContext.instance.activeProfile = buildProfile;
var buildPlayerOptions = BuildProfileModuleUtil.GetBuildPlayerOptionsFromActiveProfile(
buildPlayerWithProfileOptions.locationPathName, buildPlayerWithProfileOptions.assetBundleManifestPath, buildPlayerWithProfileOptions.options);
return BuildPlayer(buildPlayerOptions);
}

public static BuildReport BuildPlayer(EditorBuildSettingsScene[] levels, string locationPathName, BuildTarget target, BuildOptions options)
{
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
Expand Down
16 changes: 14 additions & 2 deletions Editor/Mono/BuildPipeline/BuildPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License

using UnityEngine;
using System;
using System.Collections.Generic;
using DiscoveredTargetInfo = UnityEditor.BuildTargetDiscovery.DiscoveredTargetInfo;
using TargetAttributes = UnityEditor.BuildTargetDiscovery.TargetAttributes;

namespace UnityEditor.Build
{
// All settings for a build platform.
internal class BuildPlatform
internal class BuildPlatform : ICloneable
{
// short name used for texture settings, etc.
public string name;
Expand Down Expand Up @@ -38,13 +39,24 @@ public BuildPlatform(string locTitle, string tooltip, string iconId, NamedBuildT
{
this.namedBuildTarget = namedBuildTarget;
name = namedBuildTarget.TargetName;
m_Title = new ScalableGUIContent(locTitle, null, iconId);

// Workaround for some platforms which have | in their name which is also used as separator for tooltips
if (locTitle.Contains("|"))
m_Title = new ScalableGUIContent(locTitle.Replace("|", " "), null, iconId);
else
m_Title = new ScalableGUIContent(locTitle, null, iconId);

m_SmallTitle = new ScalableGUIContent(null, null, iconId + ".Small");
this.tooltip = tooltip;
this.hideInUi = hideInUi;
this.defaultTarget = defaultTarget;
this.installed = installed;
}

public object Clone()
{
return MemberwiseClone();
}
}

internal class BuildPlatformWithSubtarget : BuildPlatform
Expand Down
20 changes: 20 additions & 0 deletions Editor/Mono/BuildPipeline/NamedBuildTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ internal static NamedBuildTarget FromActiveSettings(BuildTarget target)
return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
}

internal static NamedBuildTarget FromTargetAndSubtarget(BuildTarget target, int subtarget)
{
var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);
if (buildTargetGroup == BuildTargetGroup.Standalone)
{
var standaloneSubtarget = (StandaloneBuildSubtarget)subtarget;
switch (standaloneSubtarget)
{
case StandaloneBuildSubtarget.Player:
return NamedBuildTarget.Standalone;
case StandaloneBuildSubtarget.Server:
return NamedBuildTarget.Server;
default:
throw new ArgumentException($"'{standaloneSubtarget}' is not a valid subtarget for the Standalone build target");
}
}

return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
}

public static bool operator==(NamedBuildTarget lhs, NamedBuildTarget rhs)
{
return lhs.Equals(rhs);
Expand Down
47 changes: 5 additions & 42 deletions Editor/Mono/BuildPlayerWindowBuildMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using UnityEditor.Connect;
using UnityEditor.Profiling;
using UnityEditor.Utils;
using UnityEditor.Build.Profile;

namespace UnityEditor
{
Expand Down Expand Up @@ -230,53 +231,15 @@ internal static BuildPlayerOptions GetBuildPlayerOptionsInternal(bool askForBuil
BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
int subtarget = EditorUserBuildSettings.GetSelectedSubtargetFor(buildTarget);

// Pick location for the build
string newLocation = "";
options.options = BuildProfileModuleUtil.GetBuildOptions(buildTarget, buildTargetGroup, string.Empty, options.options);

//Check if Lz4 is supported for the current buildtargetgroup and enable it if need be
if (PostprocessBuildPlayer.SupportsLz4Compression(buildTarget))
{
var compression = EditorUserBuildSettings.GetCompressionType(buildTargetGroup);
if (compression < 0)
compression = PostprocessBuildPlayer.GetDefaultCompression(buildTarget);
if (compression == Compression.Lz4)
options.options |= BuildOptions.CompressWithLz4;
else if (compression == Compression.Lz4HC)
options.options |= BuildOptions.CompressWithLz4HC;
}

bool developmentBuild = EditorUserBuildSettings.development;
if (developmentBuild)
options.options |= BuildOptions.Development;
if (EditorUserBuildSettings.allowDebugging && developmentBuild)
options.options |= BuildOptions.AllowDebugging;
if (EditorUserBuildSettings.symlinkSources)
options.options |= BuildOptions.SymlinkSources;

if(BuildTargetDiscovery.TryGetBuildTarget(buildTarget, out IBuildTarget iBuildTarget))
{
if (EditorUserBuildSettings.connectProfiler && (developmentBuild || (iBuildTarget.PlayerConnectionPlatformProperties?.ForceAllowProfilerConnection ?? false)) )
options.options |= BuildOptions.ConnectWithProfiler;
}

if (EditorUserBuildSettings.buildWithDeepProfilingSupport && developmentBuild)
options.options |= BuildOptions.EnableDeepProfilingSupport;
if (EditorUserBuildSettings.buildScriptsOnly)
options.options |= BuildOptions.BuildScriptsOnly;
if (!string.IsNullOrEmpty(ProfilerUserSettings.customConnectionID) && developmentBuild)
options.options |= BuildOptions.CustomConnectionID;


if (IsInstallInBuildFolderOption())
{
options.options |= BuildOptions.InstallInBuildFolder;
}
else if ((options.options & BuildOptions.PatchPackage) == 0)
if ((options.options & BuildOptions.InstallInBuildFolder) == 0 &&
(options.options & BuildOptions.PatchPackage) == 0)
{
if (askForBuildLocation && !PickBuildLocation(buildTargetGroup, buildTarget, subtarget, options.options, out updateExistingBuild))
throw new BuildMethodException();

newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);
var newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);

if (newLocation.Length == 0)
{
Expand Down
76 changes: 66 additions & 10 deletions Editor/Mono/BuildProfile/BuildProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UnityEngine;
using UnityEngine.Bindings;
using UnityEngine.Scripting;
using UnityEditor.Modules;

namespace UnityEditor.Build.Profile
{
Expand Down Expand Up @@ -45,14 +46,26 @@ internal StandaloneBuildSubtarget subtarget
/// <summary>
/// Module name used to fetch build profiles.
/// </summary>
[SerializeField] string m_ModuleName;
string m_ModuleName;
[VisibleToOtherModules]
internal string moduleName
{
get => m_ModuleName;
set => m_ModuleName = value;
}

/// <summary>
/// Platform ID of the build profile.
/// Correspond to platform GUID in <see cref="BuildTargetDiscovery"/>
/// </summary>
[SerializeField] string m_PlatformId;
[VisibleToOtherModules]
internal string platformId
{
get => m_PlatformId;
set => m_PlatformId = value;
}

/// <summary>
/// Platform module specific build settings; e.g. AndroidBuildSettings.
/// </summary>
Expand Down Expand Up @@ -96,7 +109,7 @@ public EditorBuildSettingsScene[] scenes
/// 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>();
[VisibleToOtherModules] internal string[] scriptingDefines
public string[] scriptingDefines
{
get => m_ScriptingDefines;
set => m_ScriptingDefines = value;
Expand All @@ -114,6 +127,12 @@ internal PlayerSettings playerSettings
set { m_PlayerSettings = value; }
}

// TODO: Return server IBuildTargets for server build profiles. (https://jira.unity3d.com/browse/PLAT-6612)
/// <summary>
/// Get the IBuildTarget of the build profile.
/// </summary>
internal IBuildTarget GetIBuildTarget() => ModuleManager.GetIBuildTarget(buildTarget);

/// <summary>
/// Returns true if the given <see cref="BuildProfile"/> is the active profile or a classic
/// profile for the EditorUserBuildSettings active build target.
Expand All @@ -128,30 +147,43 @@ internal bool IsActiveBuildProfileOrPlatform()
|| !BuildProfileContext.IsClassicPlatformProfile(this))
return false;

if (!BuildProfileModuleUtil.IsStandalonePlatform(buildTarget))
return buildTarget == EditorUserBuildSettings.activeBuildTarget;

var profileModuleName = BuildProfileModuleUtil.GetModuleName(buildTarget);
var activeModuleName = BuildProfileModuleUtil.GetModuleName(EditorUserBuildSettings.activeBuildTarget);
return profileModuleName == activeModuleName && subtarget == EditorUserBuildSettings.standaloneBuildSubtarget;
var activePlatformId = BuildProfileModuleUtil.GetPlatformId(
EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.standaloneBuildSubtarget);
return platformId == activePlatformId;
}

[VisibleToOtherModules]
internal bool CanBuildLocally()
{
// Note: A platform build profile may have a non-null value even if its module is not installed.
// This scenario is true for server platform profiles, which are the same type as the standalone one.
return platformBuildProfile != null && BuildProfileModuleUtil.IsModuleInstalled(moduleName, subtarget);
return platformBuildProfile != null && BuildProfileModuleUtil.IsModuleInstalled(platformId);
}

internal string GetLastRunnableBuildPathKey()
{
if (platformBuildProfile == null)
return string.Empty;

var key = platformBuildProfile.GetLastRunnableBuildPathKey();
if (string.IsNullOrEmpty(key) || BuildProfileContext.IsClassicPlatformProfile(this))
return key;

string assetPath = AssetDatabase.GetAssetPath(this);
return BuildProfileModuleUtil.GetLastRunnableBuildKeyFromAssetPath(assetPath, key);
}

void OnEnable()
{
ValidateDataConsistency();

moduleName = BuildProfileModuleUtil.GetModuleName(platformId);

// Check if the platform support module has been installed,
// and try to set an uninitialized platform settings.
if (platformBuildProfile == null)
TryCreatePlatformSettings();

CheckSceneListConsistency();
onBuildProfileEnable?.Invoke(this);
LoadPlayerSettings();

Expand Down Expand Up @@ -182,6 +214,30 @@ void OnDisable()
AssetDatabase.SaveAssetIfDirty(this);
}

void ValidateDataConsistency()
{
// TODO: Remove migration code (https://jira.unity3d.com/browse/PLAT-8909)
// Set platform ID for build profiles created before it is introduced.
if (string.IsNullOrEmpty(platformId))
{
platformId = BuildProfileContext.IsSharedProfile(buildTarget) ?
new GUID(string.Empty).ToString() : BuildProfileModuleUtil.GetPlatformId(buildTarget, subtarget);
EditorUtility.SetDirty(this);
}
else
{
var (curBuildTarget, curSubtarget) = BuildProfileModuleUtil.GetBuildTargetAndSubtarget(platformId);
if (buildTarget != curBuildTarget || subtarget != curSubtarget)
{
buildTarget = curBuildTarget;
subtarget = curSubtarget;
EditorUtility.SetDirty(this);
}
}

CheckSceneListConsistency();
}

/// <summary>
/// EditorBuildSettingsScene stores both path and GUID. Path can become
/// invalid when scenes are moved or renamed and must be recalculated.
Expand Down
18 changes: 17 additions & 1 deletion Editor/Mono/BuildProfile/BuildProfileCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ namespace UnityEditor.Build.Profile
internal static class BuildProfileCLI
{
[RequiredByNativeCode]
internal static void SetActiveBuildProfileFromPath(string buildProfilePath)
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)
Expand All @@ -32,5 +35,18 @@ static bool LoadFromPath(string buildProfilePath, out BuildProfile buildProfile)

return buildProfile != null;
}

[RequiredByNativeCode]
static void BuildActiveProfileWithPath(string locationPathName)
{
var options = new BuildPlayerWithProfileOptions()
{
buildProfile = BuildProfile.GetActiveBuildProfile(),
locationPathName = locationPathName,
options = BuildOptions.None
};

BuildPipeline.BuildPlayer(options);
}
}
}
Loading

0 comments on commit 22a9cc4

Please sign in to comment.