Skip to content

Commit b1cf2a8

Browse files
author
Unity Technologies
committed
Unity 6000.2.0a6 C# reference source code
1 parent b42ec00 commit b1cf2a8

File tree

121 files changed

+2911
-989
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+2911
-989
lines changed

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
[assembly: InternalsVisibleTo("Unity.IntegrationTests.Misc")]
5151
[assembly: InternalsVisibleTo("Unity.IntegrationTests.PackageManager")]
5252
[assembly: InternalsVisibleTo("Unity.IntegrationTests.Profiler")]
53+
[assembly: InternalsVisibleTo("Unity.IntegrationTests.PS4")]
54+
[assembly: InternalsVisibleTo("Unity.IntegrationTests.PS5")]
5355
[assembly: InternalsVisibleTo("Unity.IntegrationTests.Rendering")]
5456
[assembly: InternalsVisibleTo("Unity.IntegrationTests.SceneVisibility")]
5557
[assembly: InternalsVisibleTo("Unity.IntegrationTests.ScriptCompilation")]

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -491,52 +491,9 @@ void OnGUI()
491491
{
492492
styles = new Styles();
493493
}
494-
495-
if (!UnityConnect.instance.canBuildWithUPID)
496-
{
497-
ShowAlert();
498-
}
499-
GUILayout.Space(5);
500-
GUILayout.BeginHorizontal();
501-
GUILayout.Space(10);
502-
GUILayout.BeginVertical();
503-
504-
string message = "";
505-
var buildSettingsLocked = !AssetDatabase.IsOpenForEdit(kEditorBuildSettingsPath, out message, StatusQueryOptions.UseCachedIfPossible);
506-
507-
using (new EditorGUI.DisabledScope(buildSettingsLocked))
508-
{
509-
ActiveScenesGUI();
510-
// Clear all and Add Current Scene
511-
GUILayout.BeginHorizontal();
512-
if (buildSettingsLocked)
513-
{
514-
GUI.enabled = true;
515-
if (GUILayout.Button(styles.checkOut))
516-
AssetDatabase.MakeEditable(kEditorBuildSettingsPath);
517-
GUILayout.Label(message);
518-
GUI.enabled = false;
519-
}
520-
GUILayout.FlexibleSpace();
521-
if (GUILayout.Button(styles.addOpenSource))
522-
AddOpenScenes();
523-
GUILayout.EndHorizontal();
524-
}
525-
526-
GUILayout.Space(10);
527-
528-
GUILayout.BeginHorizontal(GUILayout.Height(400));
529-
ActiveBuildTargetsGUI();
530-
GUILayout.Space(10);
531-
GUILayout.BeginVertical();
532-
ShowBuildTargetSettings();
533-
GUILayout.EndVertical();
534-
GUILayout.EndHorizontal();
535-
536-
GUILayout.Space(10);
537-
GUILayout.EndVertical();
538-
GUILayout.Space(10);
539-
GUILayout.EndHorizontal();
494+
// Override the 'old' build settings window in favor of the new build profile window.
495+
BuildPipeline.ShowBuildProfileWindow();
496+
Close();
540497
}
541498

542499
static bool IsAnyStandaloneModuleLoaded()

Editor/Mono/BuildProfile/BuildProfileAPI.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,41 @@ public static void SetActiveBuildProfile(BuildProfile buildProfile)
3333

3434
BuildProfileModuleUtil.SwitchLegacyActiveFromBuildProfile(buildProfile);
3535
}
36+
37+
/// <summary>
38+
/// Gets a component of type T associated with the build profile, its global fallback,
39+
/// or null if the component is not available.
40+
/// </summary>
41+
public T GetComponent<T>() where T : class
42+
{
43+
if (typeof(T) == typeof(PlayerSettings))
44+
{
45+
if (m_PlayerSettings != null)
46+
return m_PlayerSettings as T;
47+
return s_GlobalPlayerSettings as T;
48+
}
49+
50+
return null;
51+
}
52+
53+
/// <summary>
54+
/// Gets a component of type T associated with the currently active build profile,
55+
/// its global fallback, or null if the component is not available.
56+
/// </summary>
57+
public static T GetActiveComponent<T>() where T : class
58+
{
59+
var buildProfile = GetActiveBuildProfile();
60+
if (buildProfile == null)
61+
{
62+
if (typeof(T) == typeof(PlayerSettings))
63+
return s_GlobalPlayerSettings as T;
64+
}
65+
else
66+
{
67+
return buildProfile.GetComponent<T>();
68+
}
69+
70+
return null;
71+
}
3672
}
3773
}

Editor/Mono/BuildProfile/BuildProfileContext.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,5 +842,21 @@ static void Save() => InternalEditorUtility.SaveToSerializedFileAndForget(new[]
842842

843843
[VisibleToOtherModules]
844844
internal static bool IsSharedProfile(GUID platformGuid) => platformGuid.Empty();
845+
846+
internal static void UpdateScriptingDefineSymbolsInActivePlayerSettingsOverride(NamedBuildTarget buildTarget, string defines)
847+
{
848+
var profile = activeProfile;
849+
850+
if (profile == null)
851+
return;
852+
853+
if (profile.playerSettings == null)
854+
return;
855+
856+
PlayerSettings.SetScriptingDefineSymbols_Internal(profile.playerSettings, buildTarget.TargetName, defines);
857+
profile.SerializePlayerSettings();
858+
EditorUtility.SetDirty(profile);
859+
AssetDatabase.SaveAssetIfDirty(profile);
860+
}
845861
}
846862
}

Editor/Mono/BuildProfile/BuildProfileCreate.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using System;
6+
using System.IO;
67
using JetBrains.Annotations;
78
using UnityEditor.Modules;
89
using UnityEngine;
@@ -67,6 +68,7 @@ internal static void CreateInstance(GUID platformId, string assetPath)
6768
[VisibleToOtherModules("UnityEditor.BuildProfileModule")]
6869
internal static void CreateInstance(GUID platformId, string assetPath, int preconfiguredSettingsVariant, string[] packagesToAdd)
6970
{
71+
ValidateFileNameLength(assetPath);
7072
ValidatePlatform(platformId);
7173

7274
var (buildTarget, subtarget) = BuildProfileModuleUtil.GetBuildTargetAndSubtarget(platformId);
@@ -99,6 +101,18 @@ static void ValidatePlatform(GUID platformGuid)
99101
throw new ArgumentException("A build profile must be created for a valid platform.");
100102
}
101103

104+
/// <summary>
105+
/// Validates if the provided path name length is supported by the Asset database.
106+
/// Throws an ArgumentException if the platform is not valid.
107+
/// </summary>
108+
/// <param name="assetPath">The path to the build profile to be created.</param>
109+
static void ValidateFileNameLength(string assetPath)
110+
{
111+
// File name length is limited by the asset database
112+
if (Path.GetFileName(assetPath).Length > BuildProfileModuleUtil.k_MaxAssetFileNameLength)
113+
throw new ArgumentException($"Build profile name is too long ({Path.GetFileName(assetPath).Length}) - max supported is {BuildProfileModuleUtil.k_MaxAssetFileNameLength}");
114+
}
115+
102116
internal void NotifyBuildProfileExtensionOfCreation(int preconfiguredSettingsVariant)
103117
{
104118
var buildProfileExtension = BuildProfileModuleUtil.GetBuildProfileExtension(platformGuid);

Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ internal class BuildProfileModuleUtil
2525
const string k_BuyProUrl = "https://store.unity.com/products/unity-pro";
2626
const string k_ConsoleModuleUrl = "https://unity3d.com/platform-installation";
2727
const string k_LastRunnableBuildPathSeparator = "_";
28+
// The asset database supports file name length to max. 250 symbols
29+
// Leave 3 symbols for the GenerateUniqueAssetPath() that adds " 1"(2,3...) in case
30+
// an asset with such name already exists.
31+
public const int k_MaxAssetFileNameLength = 247;
32+
// For UI cases where the extension `.asset` is not taken into consideration
33+
public const int k_MaxAssetFileNameLengthWithoutExtension = k_MaxAssetFileNameLength - 6;
2834
static readonly string k_NoModuleLoaded = L10n.Tr("No {0} module loaded.");
2935
static readonly string k_DerivedPlatformInactive = L10n.Tr("{0} is currently disabled.");
3036
static readonly string k_EditorWillNeedToBeReloaded = L10n.Tr("Note: Editor will need to be restarted to load any newly installed modules");

Editor/Mono/BuildProfile/BuildProfileRenameOverlay.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal class BuildProfileRenameOverlay
1818
{
1919
static readonly string k_InvalidChars = BuildProfileModuleUtil.GetFilenameInvalidCharactersStr();
2020
static readonly string k_ErrorMessage = string.Format(L10n.Tr("A file name can't contain any of the following characters:\t{0}"), k_InvalidChars);
21+
static readonly string k_ErrorMessageLength = string.Format(L10n.Tr("Build profile name can't be longer than {0} symbols"), BuildProfileModuleUtil.k_MaxAssetFileNameLengthWithoutExtension);
2122

2223
TextField m_TextField;
2324
Rect? m_ErrorRect = null;
@@ -56,6 +57,16 @@ public void OnNameChanged(string previousValue, string newValue)
5657
m_TextField.cursorIndex = targetIndex;
5758
m_TextField.selectIndex = targetIndex;
5859
}
60+
else if (newValue.Length > BuildProfileModuleUtil.k_MaxAssetFileNameLengthWithoutExtension)
61+
{
62+
TooltipView.Show(k_ErrorMessageLength, errorRect);
63+
m_TextField.SetValueWithoutNotify(previousValue);
64+
65+
// The cursor should be kept in place when adding too much
66+
var targetIndex = Mathf.Max(m_TextField.cursorIndex - 1, 0);
67+
m_TextField.cursorIndex = targetIndex;
68+
m_TextField.selectIndex = targetIndex;
69+
}
5970
else
6071
{
6172
TooltipView.ForceClose();

Editor/Mono/ContextMenuUtility.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,16 @@ public static void AddGameObjectEntriesTo(DropdownMenu menu)
169169
internal static DropdownMenu CreateActionMenu()
170170
{
171171
var contextMenu = new DropdownMenu();
172+
173+
Menu.CreateActionMenuBegin();
174+
172175
EditorToolManager.activeToolContext.PopulateMenu(contextMenu);
173176
AddMenuItemsForType(contextMenu, ToolManager.activeContextType, EditorToolManager.activeToolContext.targets);
174177
EditorToolManager.activeTool.PopulateMenu(contextMenu);
175178
AddMenuItemsForType(contextMenu, ToolManager.activeToolType, EditorToolManager.activeTool.targets);
176179

180+
Menu.CreateActionMenuEnd();
181+
177182
return contextMenu;
178183
}
179184

Editor/Mono/EditorGUI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ public virtual void EndEditing()
581581
{
582582
if (activeEditor == this)
583583
{
584+
activeEditor.m_HasFocus = false;
584585
activeEditor = null;
585586
}
586587

@@ -7683,7 +7684,7 @@ internal static bool DefaultPropertyField(Rect position, SerializedProperty prop
76837684
bool toggled = DropdownButton(position, toggleLabelContent, FocusType.Keyboard, EditorStyles.layerMaskField);
76847685
if (toggled)
76857686
{
7686-
PopupWindowWithoutFocus.Show(position, new MaskFieldDropDown(property));
7687+
PopupWindow.Show(position, new MaskFieldDropDown(property));
76877688
GUIUtility.ExitGUI();
76887689
}
76897690
break;

Editor/Mono/EditorSettings.bindings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ internal static extern string Internal_ProjectGenerationUserExtensions
242242
[StaticAccessor("GetEditorSettings()", StaticAccessorType.Dot)]
243243
public static extern bool useLegacyProbeSampleCount { get; set; }
244244

245+
[StaticAccessor("GetEditorSettings()", StaticAccessorType.Dot)]
246+
public static extern bool shadowmaskStitching { get; set; }
247+
245248
[Obsolete("The disableCookiesInLightmapper setting is no longer supported. Cookies are always enabled in the Progressive Lightmapper.", true)]
246249
public static bool disableCookiesInLightmapper
247250
{

Editor/Mono/GUI/ColorMutator.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,21 @@ public float exposureValue
6868
return;
6969
m_ExposureValue = value;
7070
var newRgbFloat = m_HDRBaseColor * Mathf.Pow(2f, m_ExposureValue - m_BaseExposureValue);
71-
m_ColorHdr[(int)RgbaChannel.R] = newRgbFloat.r;
72-
m_ColorHdr[(int)RgbaChannel.G] = newRgbFloat.g;
73-
m_ColorHdr[(int)RgbaChannel.B] = newRgbFloat.b;
71+
m_ColorHdr[(int)RgbaChannel.R] = FloatClampSafe(newRgbFloat.r);
72+
m_ColorHdr[(int)RgbaChannel.G] = FloatClampSafe(newRgbFloat.g);
73+
m_ColorHdr[(int)RgbaChannel.B] = FloatClampSafe(newRgbFloat.b);
7474
}
7575
}
7676

77+
static float FloatClampSafe(float value)
78+
{
79+
if (float.IsPositiveInfinity(value) || float.IsNaN(value))
80+
return float.MaxValue;
81+
if (float.IsNegativeInfinity(value))
82+
return float.MinValue;
83+
return value;
84+
}
85+
7786
public byte GetColorChannel(RgbaChannel channel)
7887
{
7988
return m_Color[(int)channel];

Editor/Mono/GUI/MaskFieldGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ internal static int DoMaskField(Rect position, int controlID, int mask, string[]
162162
{
163163
MaskCallbackInfo.m_Instance = new MaskCallbackInfo(controlID);
164164
MaskCallbackInfo.m_Instance.m_DropDown = new MaskFieldDropDown(optionNames, flagValues, optionMaskValues, mask, MaskCallbackInfo.m_Instance.SetMaskValueDelegate, autoSelectEverything);
165-
PopupWindowWithoutFocus.Show(position, MaskCallbackInfo.m_Instance.m_DropDown);
165+
PopupWindow.Show(position, MaskCallbackInfo.m_Instance.m_DropDown);
166166
}
167167

168168
return mask;

Editor/Mono/Help.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ internal static string HelpFileNameForObject(Object obj)
336336
{
337337
Terrain => "script-Terrain",
338338
AudioMixerController or AudioMixerGroupController => "class-AudioMixer",
339+
AudioImporter => "class-AudioClip", // UUM-96832: We don't have an entry in the manual for the audio importer.
340+
VideoClipImporter => "class-VideoClip", // We don't have an entry in the manual for the video clip importer.
339341
EditorSettings => "class-EditorManager",
340342
SceneAsset => "CreatingScenes",
341343
LightingDataAsset => "LightmapSnapshot",

Editor/Mono/Inspector/Core/InspectorWindow.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public static void PopupPreviewWindow(InspectorWindow inspector)
5454
inspector.PopupPreviewWindow();
5555
}
5656

57+
public static void DockPreviewWindow(InspectorWindow inspector)
58+
{
59+
inspector.DockPreviewWindow();
60+
}
61+
5762
public static PreviewWindow GetPreviewWindow(InspectorWindow inspector)
5863
{
5964
return inspector.m_PreviewWindow;
@@ -330,6 +335,9 @@ protected override bool BeginDrawPreviewAndLabels()
330335
return m_PreviewWindow == null;
331336
}
332337

338+
/// <summary>
339+
/// Finalize IMGUI based inspectors.
340+
/// </summary>
333341
protected override void EndDrawPreviewAndLabels(Event evt, Rect rect, Rect dragRect)
334342
{
335343
if (m_HasPreview || m_PreviewWindow != null)
@@ -345,13 +353,11 @@ protected override void EndDrawPreviewAndLabels(Event evt, Rect rect, Rect dragR
345353
{
346354
if (m_PreviewWindow == null)
347355
{
348-
hasFloatingPreviewWindow = true;
349-
DetachPreview(false);
356+
PopupPreviewWindow(exitGUI: false);
350357
}
351358
else
352359
{
353-
m_PreviewWindow.Close();
354-
hasFloatingPreviewWindow = false;
360+
DockPreviewWindow();
355361
}
356362
});
357363
menu.AddItem(
@@ -370,9 +376,12 @@ protected override void EndDrawPreviewAndLabels(Event evt, Rect rect, Rect dragR
370376

371377
// Detach preview on right click in preview title bar
372378
if (evt.type == EventType.MouseUp && evt.button == 1 && rect.Contains(evt.mousePosition) && m_PreviewWindow == null)
373-
DetachPreview();
379+
PopupPreviewWindow(exitGUI: true);
374380
}
375381

382+
/// <summary>
383+
/// Creates the ellipsis menu for UITK based inspectors.
384+
/// </summary>
376385
protected override void CreatePreviewEllipsisMenu()
377386
{
378387
if (previewWindow == null)
@@ -395,14 +404,13 @@ protected override void CreatePreviewEllipsisMenu()
395404
}
396405
else
397406
{
398-
hasFloatingPreviewWindow = false;
399-
m_PreviewWindow.Close();
407+
DockPreviewWindow();
400408

401409
previewContainer.style.display = DisplayStyle.Flex;
402410
draglineAnchor.style.display = DisplayStyle.Flex;
403411
}
404412
},
405-
a => hasFloatingPreviewWindow ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal);
413+
a => DropdownMenuAction.Status.Normal);
406414

407415
previewWindow.AppendActionToEllipsisMenu(
408416
"Minimize in Inspector",
@@ -424,13 +432,17 @@ void OnDraglineChange(PointerUpEvent evt)
424432
PopupPreviewWindow();
425433
}
426434

427-
void PopupPreviewWindow()
435+
void PopupPreviewWindow(bool exitGUI = false)
428436
{
429-
DetachPreview(false);
430-
hasFloatingPreviewWindow = true;
437+
DetachPreview(exitGUI);
431438
previewWindow.parent?.Remove(previewWindow);
432439
}
433440

441+
void DockPreviewWindow()
442+
{
443+
m_PreviewWindow?.Close();
444+
}
445+
434446
private void DetachPreview(bool exitGUI = true)
435447
{
436448
if (Event.current != null)

Editor/Mono/Inspector/Core/PreviewWindow.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ protected override void OnDisable()
5757
base.OnDisable();
5858
if (m_ParentInspectorWindow != null && GetInspectors().Contains(m_ParentInspectorWindow))
5959
{
60-
m_ParentInspectorWindow.hasFloatingPreviewWindow = false;
6160
m_ParentInspectorWindow.RebuildContentsContainers();
6261
}
6362
}

0 commit comments

Comments
 (0)