Skip to content

Commit

Permalink
Unity 6000.1.0a3 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Oct 31, 2024
1 parent 59e16ee commit ac359b9
Show file tree
Hide file tree
Showing 47 changed files with 1,201 additions and 563 deletions.
5 changes: 5 additions & 0 deletions Editor/Mono/Audio/AudioContainerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,11 @@ void OnAudioClipListChanged(SerializedProperty property)
// Force a list rebuild when the list has changed or it will not always render correctly
m_ClipsListView.Rebuild();

// This function is the first entry-point in `AudioContainerWindow` after an undo-event that alters the
// audio clip list has been triggered. And, whenever the list is altered, we need to make sure the state is stopped.
State.Stop();
ClearClipFieldProgressBars();

UpdateTransportButtonStates();
SetTitle();
}
Expand Down
18 changes: 18 additions & 0 deletions Editor/Mono/BuildPipeline.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,24 @@ private static BuildReport BuildPlayer(string[] scenes, string locationPathName,
scenes[i] = scenes[i].Replace('\\', '/').Replace("//", "/");
}

if ((options & BuildOptions.Development) == 0)
{
if ((options & BuildOptions.AllowDebugging) != 0)
{
throw new ArgumentException("Non-development build cannot allow debugging. Either add the Development build option, or remove the AllowDebugging build option.");
}

if ((options & BuildOptions.EnableDeepProfilingSupport) != 0)
{
throw new ArgumentException("Non-development build cannot allow deep profiling support. Either add the Development build option, or remove the EnableDeepProfilingSupport build option.");
}

if ((options & BuildOptions.ConnectWithProfiler) != 0)
{
throw new ArgumentException("Non-development build cannot allow auto-connecting the profiler. Either add the Development build option, or remove the ConnectWithProfiler build option.");
}
}

try
{
return BuildPlayerInternal(scenes, locationPathName, assetBundleManifestPath, buildTargetGroup, target, subtarget, options, extraScriptingDefines);
Expand Down
30 changes: 28 additions & 2 deletions Editor/Mono/BuildProfile/BuildProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,23 @@ internal PlayerSettings playerSettings
[VisibleToOtherModules]
internal Action OnPlayerSettingsUpdatedFromYAML;

/// <summary>
/// Cross-pipeline graphics settings overrides in build profile
/// </summary>
[VisibleToOtherModules]
internal BuildProfileGraphicsSettings graphicsSettings;

[VisibleToOtherModules]
internal Action OnGraphicsSettingsSubAssetRemoved;

/// <summary>
/// Cross-pipeline graphics settings overrides in build profile
/// Quality settings overrides in build profile
/// </summary>
[VisibleToOtherModules]
internal BuildProfileGraphicsSettings graphicsSettings;
internal BuildProfileQualitySettings qualitySettings;

[VisibleToOtherModules]
internal Action OnQualitySettingsSubAssetRemoved;

// TODO: Return server IBuildTargets for server build profiles. (https://jira.unity3d.com/browse/PLAT-6612)
/// <summary>
Expand Down Expand Up @@ -235,6 +244,7 @@ void OnEnable()
LoadPlayerSettings();

TryLoadGraphicsSettings();
TryLoadQualitySettings();

if (!EditorUserBuildSettings.isBuildProfileAvailable
|| BuildProfileContext.activeProfile != this)
Expand Down Expand Up @@ -266,6 +276,21 @@ void TryLoadGraphicsSettings()
graphicsSettings = data;
}

void TryLoadQualitySettings()
{
if (qualitySettings != null)
return;

var path = AssetDatabase.GetAssetPath(this);
var objects = AssetDatabase.LoadAllAssetsAtPath(path);

var data = Array.Find(objects, obj => obj is BuildProfileQualitySettings) as BuildProfileQualitySettings;
if (data == null)
return;

qualitySettings = data;
}

void OnDisable()
{
if (BuildProfileContext.activeProfile == this)
Expand Down Expand Up @@ -297,6 +322,7 @@ static void ContextMenuReset(MenuCommand menuCommand)
targetBuildProfile.scriptingDefines = Array.Empty<string>();

BuildProfileModuleUtil.RemovePlayerSettings(targetBuildProfile);
targetBuildProfile.RemoveQualitySettings();
targetBuildProfile.RemoveGraphicsSettings();

AssetDatabase.SaveAssetIfDirty(targetBuildProfile);
Expand Down
29 changes: 29 additions & 0 deletions Editor/Mono/BuildProfile/BuildProfileContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ internal static bool ActiveProfileHasGraphicsSettings()
return activeProfile.graphicsSettings != null;
}

/// <summary>
/// Check if the active build profile has quality settings
/// </summary>
internal static bool ActiveProfileHasQualitySettings()
{
if (activeProfile == null)
return false;

return activeProfile.qualitySettings != null;
}

/// <summary>
/// Sync the active build profile to EditorUserBuildSettings to ensure they are in a consistent state.
/// </summary>
Expand Down Expand Up @@ -734,6 +745,24 @@ static bool SetActiveShaderVariantCollections(ShaderVariantCollection[] collecti
return true;
}

[RequiredByNativeCode, UsedImplicitly]
static string[] GetActiveProfileQualityLevels()
{
if (!ActiveProfileHasQualitySettings())
return Array.Empty<string>();

return activeProfile.qualitySettings.qualityLevels;
}

[RequiredByNativeCode, UsedImplicitly]
static string GetActiveProfileDefaultQualityLevel()
{
if (!ActiveProfileHasQualitySettings())
return string.Empty;

return activeProfile.qualitySettings.defaultQualityLevel;
}

[RequiredByNativeCode]
static string GetActiveBuildProfilePath()
{
Expand Down
15 changes: 15 additions & 0 deletions Editor/Mono/BuildProfile/BuildProfileCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,20 @@ internal void RemoveGraphicsSettings()

OnGraphicsSettingsSubAssetRemoved?.Invoke();
}

/// <summary>
/// Remove the Quality Settings overrides from the build profile.
/// </summary>
internal void RemoveQualitySettings()
{
if (qualitySettings == null)
return;

AssetDatabase.RemoveObjectFromAsset(qualitySettings);
qualitySettings = null;
EditorUtility.SetDirty(this);

OnQualitySettingsSubAssetRemoved?.Invoke();
}
}
}
74 changes: 73 additions & 1 deletion Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,81 @@ public static void OnActiveProfileGraphicsSettingsChanged(bool hasGraphicsSettin
GraphicsSettingsInspector.OnActiveProfileGraphicsSettingsChanged?.Invoke();
}

internal static void RemoveQualityLevelFromAllProfiles(string qualityLevelName)
{
var profiles = GetAllBuildProfiles();
foreach (var profile in profiles)
{
if (profile.qualitySettings == null)
continue;

profile.qualitySettings.RemoveQualityLevel(qualityLevelName);
}
}

internal static void RenameQualityLevelInAllProfiles(string oldName, string newName)
{
var profiles = GetAllBuildProfiles();
foreach (var profile in profiles)
{
if (profile.qualitySettings == null)
continue;

profile.qualitySettings.RenameQualityLevel(oldName, newName);
}
}

/// <summary>
/// Get all custom build profiles in the project.
/// </summary>
public static List<BuildProfile> GetAllBuildProfiles()
{
var alreadyLoadedBuildProfiles = Resources.FindObjectsOfTypeAll<BuildProfile>();

const string buildProfileAssetSearchString = $"t:{nameof(BuildProfile)}";
var assetsGuids = AssetDatabase.FindAssets(buildProfileAssetSearchString);
var result = new List<BuildProfile>(assetsGuids.Length);

// Suppress missing type warning thrown by serialization. This could happen
// when the build profile window is opened, then entering play mode and the
// module for that profile is not installed.
BuildProfileModuleUtil.SuppressMissingTypeWarning();

foreach (var guid in assetsGuids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
BuildProfile profile = AssetDatabase.LoadAssetAtPath<BuildProfile>(path);
if (profile == null)
{
Debug.LogWarning($"[BuildProfile] Failed to load asset at path: {path}");
continue;
}

result.Add(profile);
}

foreach (var buildProfile in alreadyLoadedBuildProfiles)
{
// Asset database will not give us any build profiles that get created in memory
// and we need to include them in this list as we use it to detect that build profiles
// have been destroyed and destroy their resources like PlayerSettings afterwards.
// Skipping the in-memory build profiles will result in us deleting their associated
// player settings object while it's being used and will lead to a crash (UUM-77423)
if (buildProfile &&
!BuildProfileContext.IsClassicPlatformProfile(buildProfile) &&
!BuildProfileContext.IsSharedProfile(buildProfile.buildTarget) &&
!EditorUtility.IsPersistent(buildProfile))
{
result.Add(buildProfile);
}
}

return result;
}

public static string[] GetSettingsRequiringRestart(PlayerSettings previousProfileSettings, PlayerSettings newProfileSettings, BuildTarget oldBuildTarget, BuildTarget newBuildTarget)
{
return PlayerSettings.GetSettingsRequiringRestart(previousProfileSettings, newProfileSettings, oldBuildTarget, newBuildTarget);
return PlayerSettings.GetSettingsRequiringRestart(previousProfileSettings, newProfileSettings, oldBuildTarget, newBuildTarget);
}

public static PlayerSettings GetGlobalPlayerSettings()
Expand Down
66 changes: 66 additions & 0 deletions Editor/Mono/BuildProfile/BuildProfileQualitySettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License

using System;
using UnityEngine;
using UnityEngine.Bindings;

namespace UnityEditor.Build.Profile
{
[VisibleToOtherModules("UnityEditor.BuildProfileModule")]
sealed class BuildProfileQualitySettings : ScriptableObject
{
[SerializeField] string m_DefaultQualityLevel = string.Empty;
[SerializeField] string[] m_QualityLevels = Array.Empty<string>();

public string defaultQualityLevel
{
get => m_DefaultQualityLevel;
set => m_DefaultQualityLevel = value;
}

public string[] qualityLevels
{
get => m_QualityLevels;
set => m_QualityLevels = value;
}

public void Instantiate()
{
name = "Quality Settings";
hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
}

public void RemoveQualityLevel(string qualityLevel)
{
var index = Array.IndexOf(qualityLevels, qualityLevel);
if (index == -1)
return;

var newQualityLevels = new string[qualityLevels.Length - 1];
Array.Copy(qualityLevels, 0, newQualityLevels, 0, index);
Array.Copy(qualityLevels, index + 1, newQualityLevels, index, qualityLevels.Length - index - 1);
qualityLevels = newQualityLevels;

if (defaultQualityLevel == qualityLevel)
defaultQualityLevel = qualityLevels.Length > 0 ? qualityLevels[0] : string.Empty;

EditorUtility.SetDirty(this);
}

public void RenameQualityLevel(string oldName, string newName)
{
var index = Array.IndexOf(qualityLevels, oldName);
if (index == -1)
return;

qualityLevels[index] = newName;

if (defaultQualityLevel == oldName)
defaultQualityLevel = newName;

EditorUtility.SetDirty(this);
}
}
}
Loading

0 comments on commit ac359b9

Please sign in to comment.