Skip to content

Commit 6500e74

Browse files
author
Unity Technologies
committed
Unity 6000.0.18f1 C# reference source code
1 parent 6113073 commit 6500e74

File tree

61 files changed

+783
-336
lines changed

Some content is hidden

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

61 files changed

+783
-336
lines changed

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ namespace UnityEditor;
2020

2121
sealed class AudioContainerWindow : EditorWindow
2222
{
23+
enum Icons
24+
{
25+
Play = 0,
26+
Stop = 1,
27+
Skip = 2,
28+
DiceOff = 3,
29+
DiceOn = 4
30+
}
31+
2332
/// <summary>
2433
/// The cached instance of the window, if it is open.
2534
/// </summary>
@@ -32,8 +41,8 @@ sealed class AudioContainerWindow : EditorWindow
3241
/// Only used locally in these methods, but it's a global member to avoid GC.
3342
/// </summary>
3443
readonly List<AudioContainerElement> m_AddedElements = new();
35-
3644
readonly string k_EmptyGuidString = Guid.Empty.ToString("N");
45+
readonly Texture2D[] k_IconTextureCache = new Texture2D[Enum.GetNames(typeof(Icons)).Length];
3746

3847
VisualElement m_ContainerRootVisualElement;
3948
VisualElement m_Day0RootVisualElement;
@@ -91,15 +100,11 @@ sealed class AudioContainerWindow : EditorWindow
91100
Label m_AutomaticTriggerModeLabel;
92101
Label m_LoopLabel;
93102

94-
// Shared icon references
95-
Texture2D m_DiceIconOff;
96-
Texture2D m_DiceIconOn;
97-
98103
bool m_IsVisible;
99-
bool m_IsSubscribedToGUICallbacksAndEvents;
100104
bool m_IsInitializing;
101105
bool m_Day0ElementsInitialized;
102106
bool m_ContainerElementsInitialized;
107+
bool m_IsSubscribedToGUICallbacksAndEvents;
103108
bool m_ClipFieldProgressBarsAreCleared = true;
104109

105110
/// <summary>
@@ -114,6 +119,11 @@ internal static void CreateAudioRandomContainerWindow()
114119
window.Show();
115120
}
116121

122+
internal bool IsInitializedForTargetDisplay()
123+
{
124+
return m_ContainerElementsInitialized && m_IsSubscribedToGUICallbacksAndEvents;
125+
}
126+
117127
static void OnCreateButtonClicked()
118128
{
119129
ProjectWindowUtil.CreateAudioRandomContainer();
@@ -126,8 +136,6 @@ void OnEnable()
126136
Instance = this;
127137
}
128138

129-
m_DiceIconOff = EditorGUIUtility.IconContent("AudioRandomContainer On Icon").image as Texture2D;
130-
m_DiceIconOn = EditorGUIUtility.IconContent("AudioRandomContainer Icon").image as Texture2D;
131139
SetTitle();
132140
}
133141

@@ -186,7 +194,7 @@ void SetTitle()
186194

187195
titleContent = new GUIContent(titleString)
188196
{
189-
image = m_DiceIconOff
197+
image = GetIconTexture(Icons.DiceOff)
190198
};
191199
}
192200

@@ -378,9 +386,7 @@ void InitializePreviewElements()
378386
m_PlayStopButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "play-button-image");
379387
m_SkipButton = UIToolkitUtilities.GetChildByName<Button>(m_ContainerRootVisualElement, "skip-button");
380388
m_SkipButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "skip-button-image");
381-
382-
var skipIcon = UIToolkitUtilities.LoadIcon("Skip");
383-
m_SkipButtonImage.style.backgroundImage = new StyleBackground(skipIcon);
389+
m_SkipButtonImage.style.backgroundImage = GetIconTexture(Icons.Skip);
384390
}
385391

386392
void SubscribeToPreviewCallbacksAndEvents()
@@ -429,13 +435,27 @@ void UpdateTransportButtonStates()
429435

430436
m_PlayStopButton?.SetEnabled(State.IsReadyToPlay() && !editorIsPaused && !EditorUtility.audioMasterMute);
431437
m_SkipButton?.SetEnabled(State.IsPlayingOrPaused() && State.AudioContainer.triggerMode == AudioRandomContainerTriggerMode.Automatic && !editorIsPaused && !EditorUtility.audioMasterMute);
438+
m_PlayStopButtonImage.style.backgroundImage = State.IsPlayingOrPaused() ? GetIconTexture(Icons.Stop) : GetIconTexture(Icons.Play);
439+
}
432440

433-
var image =
434-
State.IsPlayingOrPaused()
435-
? UIToolkitUtilities.LoadIcon("Stop")
436-
: UIToolkitUtilities.LoadIcon("Play");
441+
Texture2D GetIconTexture(Icons icon)
442+
{
443+
var cacheIndex = (int)icon;
444+
445+
var name = icon switch
446+
{
447+
Icons.Play or Icons.Stop or Icons.Skip => icon.ToString(),
448+
Icons.DiceOff => "AudioRandomContainer On Icon",
449+
Icons.DiceOn => "AudioRandomContainer Icon",
450+
_ => throw new ArgumentOutOfRangeException(nameof(icon), icon, null)
451+
};
452+
453+
if (k_IconTextureCache[cacheIndex] == null)
454+
{
455+
k_IconTextureCache[cacheIndex] = EditorGUIUtility.IconContent(name).image as Texture2D;
456+
}
437457

438-
m_PlayStopButtonImage.style.backgroundImage = new StyleBackground(image);
458+
return k_IconTextureCache[cacheIndex];
439459
}
440460

441461
void OnTransportStateChanged(object sender, EventArgs e)
@@ -535,14 +555,14 @@ void OnVolumeRandomizationEnabledChanged(SerializedProperty property)
535555
{
536556
if (property.boolValue)
537557
{
538-
m_VolumeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
558+
m_VolumeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
539559
m_VolumeRandomizationRangeSlider.SetEnabled(true);
540560
m_VolumeRandomizationRangeField.SetEnabled(true);
541561
m_VolumeRandomRangeTracker.SetEnabled(true);
542562
}
543563
else
544564
{
545-
m_VolumeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
565+
m_VolumeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
546566
m_VolumeRandomizationRangeSlider.SetEnabled(false);
547567
m_VolumeRandomizationRangeField.SetEnabled(false);
548568
m_VolumeRandomRangeTracker.SetEnabled(false);
@@ -642,14 +662,14 @@ void OnPitchRandomizationEnabledChanged(SerializedProperty property)
642662
{
643663
if (property.boolValue)
644664
{
645-
m_PitchRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
665+
m_PitchRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
646666
m_PitchRandomizationRangeSlider.SetEnabled(true);
647667
m_PitchRandomizationRangeField.SetEnabled(true);
648668
m_PitchRandomRangeTracker.SetEnabled(true);
649669
}
650670
else
651671
{
652-
m_PitchRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
672+
m_PitchRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
653673
m_PitchRandomizationRangeSlider.SetEnabled(false);
654674
m_PitchRandomizationRangeField.SetEnabled(false);
655675
m_PitchRandomRangeTracker.SetEnabled(false);
@@ -1227,14 +1247,14 @@ void OnTimeRandomizationEnabledChanged(SerializedProperty property)
12271247
if (property.boolValue
12281248
&& State.AudioContainer.triggerMode == AudioRandomContainerTriggerMode.Automatic)
12291249
{
1230-
m_TimeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
1250+
m_TimeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
12311251
m_TimeRandomizationRangeSlider.SetEnabled(true);
12321252
m_TimeRandomizationRangeField.SetEnabled(true);
12331253
m_TimeRandomRangeTracker.SetEnabled(true);
12341254
}
12351255
else
12361256
{
1237-
m_TimeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
1257+
m_TimeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
12381258
m_TimeRandomizationRangeSlider.SetEnabled(false);
12391259
m_TimeRandomizationRangeField.SetEnabled(false);
12401260
m_TimeRandomRangeTracker.SetEnabled(false);
@@ -1267,13 +1287,13 @@ void OnCountRandomizationEnabledChanged(SerializedProperty property)
12671287
&& State.AudioContainer.loopMode != AudioRandomContainerLoopMode.Infinite
12681288
&& State.AudioContainer.triggerMode == AudioRandomContainerTriggerMode.Automatic)
12691289
{
1270-
m_CountRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
1290+
m_CountRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
12711291
m_CountRandomizationRangeSlider.SetEnabled(true);
12721292
m_CountRandomizationRangeField.SetEnabled(true);
12731293
}
12741294
else
12751295
{
1276-
m_CountRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
1296+
m_CountRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
12771297
m_CountRandomizationRangeSlider.SetEnabled(false);
12781298
m_CountRandomizationRangeField.SetEnabled(false);
12791299
}

Editor/Mono/Audio/UIToolkitUtilities.cs

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

55
using System;
6-
using System.IO;
76
using UnityEngine;
87
using UnityEngine.Assertions;
98
using UnityEngine.UIElements;
@@ -26,14 +25,6 @@ internal static StyleSheet LoadStyleSheet(string filePath)
2625
return asset;
2726
}
2827

29-
internal static Texture2D LoadIcon(string filename)
30-
{
31-
var filePath = $"{Path.Combine("Icons", "Audio", filename)}@2x.png";
32-
var asset = EditorGUIUtility.LoadIcon(filePath);
33-
Assert.IsNotNull(asset, $"Could not load icon from editor default resources at path: {filePath}.");
34-
return asset;
35-
}
36-
3728
internal static T GetChildByName<T>(VisualElement parentElement, string childName) where T : VisualElement
3829
{
3930
var childElement = parentElement.Query<VisualElement>(childName).First();
@@ -52,7 +43,6 @@ internal static T GetChildByClassName<T>(VisualElement parentElement, string chi
5243
return childElementCast;
5344
}
5445

55-
5646
internal static T GetChildAtIndex<T>(VisualElement parentElement, int index) where T : VisualElement
5747
{
5848
var childElement = parentElement.ElementAt(index);

Editor/Mono/BuildProfile/BuildProfileCreate.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public sealed partial class BuildProfile
1919
[VisibleToOtherModules]
2020
internal static void RemoveOnBuildProfileEnable(Action<BuildProfile> action) => onBuildProfileEnable -= action;
2121

22+
// This callback is of use when a build profile is created via AssetDatabase, and we need to notify the UI
23+
// and select the newly created profile in the listview.
24+
[UsedImplicitly]
25+
internal static event Action<BuildProfile> onBuildProfileCreated;
26+
[VisibleToOtherModules]
27+
internal static void AddOnBuildProfileCreated(Action<BuildProfile> action) => onBuildProfileCreated += action;
28+
[VisibleToOtherModules]
29+
internal static void RemoveOnBuildProfileCreated(Action<BuildProfile> action) => onBuildProfileCreated -= action;
30+
2231
internal static BuildProfile CreateInstance(BuildTarget buildTarget, StandaloneBuildSubtarget subtarget)
2332
{
2433
string moduleName = ModuleManager.GetTargetStringFrom(buildTarget);
@@ -60,6 +69,8 @@ internal static void CreateInstance(string platformId, string assetPath)
6069
buildProfile,
6170
AssetDatabase.GenerateUniqueAssetPath(assetPath));
6271
buildProfile.OnEnable();
72+
// Notify the UI of creation so that the new build profile can be selected
73+
onBuildProfileCreated?.Invoke(buildProfile);
6374
}
6475

6576
void TryCreatePlatformSettings()

Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ public static List<string> FindAllViewablePlatforms()
321321
return result;
322322
}
323323

324+
public static bool IsPlatformAvailableOnHostPlatform(GUID platformGuid, OperatingSystemFamily operatingSystemFamily)
325+
{
326+
return BuildTargetDiscovery.BuildPlatformIsAvailableOnHostPlatform(platformGuid, SystemInfo.operatingSystemFamily);
327+
}
328+
324329
/// <summary>
325330
/// Check if the user is able to build his VT-enabled Player for a target platform
326331
/// </summary>

Editor/Mono/EditorUtility.bindings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections.Generic;
1212
using System.Linq;
1313
using static UnityEditor.EditorGUI;
14+
using UnityEditor.Inspector.GraphicsSettingsInspectors;
1415

1516
namespace UnityEditor
1617
{
@@ -206,7 +207,11 @@ public static void UnloadUnusedAssetsIgnoreManagedReferences()
206207
[RequiredByNativeCode]
207208
internal static void DelayedForceRebuildInspectors()
208209
{
209-
EditorApplication.CallDelayed(ForceRebuildInspectors);
210+
EditorApplication.CallDelayed(() =>
211+
{
212+
ForceRebuildInspectors();
213+
GraphicsSettingsInspectorUtility.ReloadGraphicsSettingsEditorIfNeeded();
214+
});
210215
}
211216

212217
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]

Editor/Mono/Inspector/Core/InspectorWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ private void OnProjectWasLoaded()
161161

162162
private void OnSelectionChanged()
163163
{
164+
if (isLocked)
165+
return;
166+
164167
RebuildContentsContainers();
165168
if (Selection.objects.Length == 0 && m_MultiEditLabel != null)
166169
{
167170
m_MultiEditLabel.RemoveFromHierarchy();
168171
}
169172

170-
if (isLocked)
171-
return;
172-
173173
UpdateSupportedDataModesList();
174174
}
175175

Editor/Mono/Inspector/GraphicsSettingsInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal static class GraphicsSettingsData
4444
string m_CurrentText;
4545

4646
bool m_FinishedInitialization;
47-
uint m_LastListsHash;
47+
int m_LastListsHash;
4848
int m_GeometryChangedEventCounter;
4949

5050
// As we use multiple IMGUI container while porting everything to UITK we will call serializedObject.Update in first separate IMGUI container.

Editor/Mono/Inspector/GraphicsSettingsInspectors/GraphicsSettingsInspectorUtility.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,23 +309,24 @@ internal static void ReloadGraphicsSettingsEditorIfNeeded()
309309
provider.Reload();
310310
}
311311

312-
internal static uint ComputeRenderPipelineGlobalSettingsListHash(List<GlobalSettingsContainer> settingsContainers)
312+
internal static int ComputeRenderPipelineGlobalSettingsListHash(List<GlobalSettingsContainer> settingsContainers)
313313
{
314314
bool haveSettings = settingsContainers is { Count: > 0 };
315315
if (!haveSettings)
316-
return 0u;
316+
return 0;
317317

318-
uint currentHash = 2166136261u;
318+
var currentHash = new HashCode();
319+
currentHash.Add(GraphicsSettings.currentRenderPipelineAssetType?.ToString() ?? "");
319320
foreach (var globalSettings in settingsContainers)
320321
{
321322
TryGetSettingsListFromRenderPipelineGlobalSettings(
322323
globalSettings.serializedObject.targetObject as RenderPipelineGlobalSettings,
323324
out SerializedObject _,
324325
out SerializedProperty _,
325326
out SerializedProperty settingsListInContainer);
326-
currentHash *= 16777619u ^ settingsListInContainer.contentHash;
327+
currentHash.Add(settingsListInContainer.contentHash);
327328
}
328-
return currentHash;
329+
return currentHash.ToHashCode();
329330
}
330331

331332
#endregion

Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ public override void OnInspectorGUI()
10201020
}
10211021
}
10221022

1023-
m_IconsEditor.IconSectionGUI(platform.namedBuildTarget, m_SettingsExtensions[selectedPlatformValue], selectedPlatformValue, sectionIndex++);
1023+
m_IconsEditor.IconSectionGUI(platform, m_SettingsExtensions[selectedPlatformValue], selectedPlatformValue, sectionIndex++);
10241024

10251025
ResolutionSectionGUI(platform, m_SettingsExtensions[selectedPlatformValue], sectionIndex++);
10261026
m_SplashScreenEditor.SplashSectionGUI(platform, m_SettingsExtensions[selectedPlatformValue], sectionIndex++);

Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsIconsEditor.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class SettingsContent
2929

3030
PlayerSettingsEditor m_Owner;
3131

32-
int m_SelectedPlatform = 0;
33-
34-
BuildPlatform[] m_ValidPlatforms;
35-
3632
// Serialized icons
3733
SerializedProperty m_PlatformIcons;
3834
SerializedProperty m_LegacyPlatformIcons;
@@ -54,8 +50,6 @@ public PlayerSettingsIconsEditor(PlayerSettingsEditor owner)
5450

5551
public void OnEnable()
5652
{
57-
m_ValidPlatforms = BuildPlatforms.instance.GetValidPlatforms(true).ToArray();
58-
5953
m_PlatformIcons = m_Owner.FindPropertyAssert("m_BuildTargetPlatformIcons");
6054
m_LegacyPlatformIcons = m_Owner.FindPropertyAssert("m_BuildTargetIcons");
6155
m_UIPrerenderedIcon = m_Owner.FindPropertyAssert("uIPrerenderedIcon");
@@ -379,9 +373,8 @@ public void SerializedObjectUpdated()
379373
DeserializeLegacyIcons();
380374
}
381375

382-
public void IconSectionGUI(NamedBuildTarget namedBuildTarget, ISettingEditorExtension settingsExtension, int platformID, int sectionIndex)
376+
public void IconSectionGUI(BuildPlatform platform, ISettingEditorExtension settingsExtension, int platformID, int sectionIndex)
383377
{
384-
m_SelectedPlatform = platformID;
385378
if (!m_Owner.BeginSettingsBox(sectionIndex, SettingsContent.iconTitle))
386379
{
387380
m_Owner.EndSettingsBox();
@@ -394,20 +387,18 @@ public void IconSectionGUI(NamedBuildTarget namedBuildTarget, ISettingEditorExte
394387

395388
if (platformUsesStandardIcons)
396389
{
397-
var selectedDefault = (m_SelectedPlatform < 0);
390+
var selectedDefault = (platformID < 0);
398391
// Set default platform variables
399-
BuildPlatform platform = null;
400392
var platformName = "";
401393

402394
// Override if a platform is selected
403395
if (!selectedDefault)
404396
{
405-
platform = m_ValidPlatforms[m_SelectedPlatform];
406397
platformName = platform.name;
407398
}
408399

409400
var iconUISettings = IconSettings.StandardIcons;
410-
if (BuildTargetDiscovery.TryGetBuildTarget(platform.defaultTarget, out IBuildTarget iBuildTarget))
401+
if (BuildTargetDiscovery.TryGetBuildTarget(BuildPipeline.GetBuildTargetByName(platform.name), out IBuildTarget iBuildTarget))
411402
iconUISettings = iBuildTarget.IconPlatformProperties?.IconUISettings ?? IconSettings.StandardIcons;
412403

413404
if (iconUISettings == IconSettings.None)

0 commit comments

Comments
 (0)