Skip to content

Commit

Permalink
Unity 6000.0.18f1 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Sep 4, 2024
1 parent 6113073 commit 6500e74
Show file tree
Hide file tree
Showing 61 changed files with 783 additions and 336 deletions.
70 changes: 45 additions & 25 deletions Editor/Mono/Audio/AudioContainerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ namespace UnityEditor;

sealed class AudioContainerWindow : EditorWindow
{
enum Icons
{
Play = 0,
Stop = 1,
Skip = 2,
DiceOff = 3,
DiceOn = 4
}

/// <summary>
/// The cached instance of the window, if it is open.
/// </summary>
Expand All @@ -32,8 +41,8 @@ sealed class AudioContainerWindow : EditorWindow
/// Only used locally in these methods, but it's a global member to avoid GC.
/// </summary>
readonly List<AudioContainerElement> m_AddedElements = new();

readonly string k_EmptyGuidString = Guid.Empty.ToString("N");
readonly Texture2D[] k_IconTextureCache = new Texture2D[Enum.GetNames(typeof(Icons)).Length];

VisualElement m_ContainerRootVisualElement;
VisualElement m_Day0RootVisualElement;
Expand Down Expand Up @@ -91,15 +100,11 @@ sealed class AudioContainerWindow : EditorWindow
Label m_AutomaticTriggerModeLabel;
Label m_LoopLabel;

// Shared icon references
Texture2D m_DiceIconOff;
Texture2D m_DiceIconOn;

bool m_IsVisible;
bool m_IsSubscribedToGUICallbacksAndEvents;
bool m_IsInitializing;
bool m_Day0ElementsInitialized;
bool m_ContainerElementsInitialized;
bool m_IsSubscribedToGUICallbacksAndEvents;
bool m_ClipFieldProgressBarsAreCleared = true;

/// <summary>
Expand All @@ -114,6 +119,11 @@ internal static void CreateAudioRandomContainerWindow()
window.Show();
}

internal bool IsInitializedForTargetDisplay()
{
return m_ContainerElementsInitialized && m_IsSubscribedToGUICallbacksAndEvents;
}

static void OnCreateButtonClicked()
{
ProjectWindowUtil.CreateAudioRandomContainer();
Expand All @@ -126,8 +136,6 @@ void OnEnable()
Instance = this;
}

m_DiceIconOff = EditorGUIUtility.IconContent("AudioRandomContainer On Icon").image as Texture2D;
m_DiceIconOn = EditorGUIUtility.IconContent("AudioRandomContainer Icon").image as Texture2D;
SetTitle();
}

Expand Down Expand Up @@ -186,7 +194,7 @@ void SetTitle()

titleContent = new GUIContent(titleString)
{
image = m_DiceIconOff
image = GetIconTexture(Icons.DiceOff)
};
}

Expand Down Expand Up @@ -378,9 +386,7 @@ void InitializePreviewElements()
m_PlayStopButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "play-button-image");
m_SkipButton = UIToolkitUtilities.GetChildByName<Button>(m_ContainerRootVisualElement, "skip-button");
m_SkipButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "skip-button-image");

var skipIcon = UIToolkitUtilities.LoadIcon("Skip");
m_SkipButtonImage.style.backgroundImage = new StyleBackground(skipIcon);
m_SkipButtonImage.style.backgroundImage = GetIconTexture(Icons.Skip);
}

void SubscribeToPreviewCallbacksAndEvents()
Expand Down Expand Up @@ -429,13 +435,27 @@ void UpdateTransportButtonStates()

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

var image =
State.IsPlayingOrPaused()
? UIToolkitUtilities.LoadIcon("Stop")
: UIToolkitUtilities.LoadIcon("Play");
Texture2D GetIconTexture(Icons icon)
{
var cacheIndex = (int)icon;

var name = icon switch
{
Icons.Play or Icons.Stop or Icons.Skip => icon.ToString(),
Icons.DiceOff => "AudioRandomContainer On Icon",
Icons.DiceOn => "AudioRandomContainer Icon",
_ => throw new ArgumentOutOfRangeException(nameof(icon), icon, null)
};

if (k_IconTextureCache[cacheIndex] == null)
{
k_IconTextureCache[cacheIndex] = EditorGUIUtility.IconContent(name).image as Texture2D;
}

m_PlayStopButtonImage.style.backgroundImage = new StyleBackground(image);
return k_IconTextureCache[cacheIndex];
}

void OnTransportStateChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -535,14 +555,14 @@ void OnVolumeRandomizationEnabledChanged(SerializedProperty property)
{
if (property.boolValue)
{
m_VolumeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
m_VolumeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
m_VolumeRandomizationRangeSlider.SetEnabled(true);
m_VolumeRandomizationRangeField.SetEnabled(true);
m_VolumeRandomRangeTracker.SetEnabled(true);
}
else
{
m_VolumeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
m_VolumeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
m_VolumeRandomizationRangeSlider.SetEnabled(false);
m_VolumeRandomizationRangeField.SetEnabled(false);
m_VolumeRandomRangeTracker.SetEnabled(false);
Expand Down Expand Up @@ -642,14 +662,14 @@ void OnPitchRandomizationEnabledChanged(SerializedProperty property)
{
if (property.boolValue)
{
m_PitchRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
m_PitchRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
m_PitchRandomizationRangeSlider.SetEnabled(true);
m_PitchRandomizationRangeField.SetEnabled(true);
m_PitchRandomRangeTracker.SetEnabled(true);
}
else
{
m_PitchRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
m_PitchRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
m_PitchRandomizationRangeSlider.SetEnabled(false);
m_PitchRandomizationRangeField.SetEnabled(false);
m_PitchRandomRangeTracker.SetEnabled(false);
Expand Down Expand Up @@ -1227,14 +1247,14 @@ void OnTimeRandomizationEnabledChanged(SerializedProperty property)
if (property.boolValue
&& State.AudioContainer.triggerMode == AudioRandomContainerTriggerMode.Automatic)
{
m_TimeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
m_TimeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
m_TimeRandomizationRangeSlider.SetEnabled(true);
m_TimeRandomizationRangeField.SetEnabled(true);
m_TimeRandomRangeTracker.SetEnabled(true);
}
else
{
m_TimeRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
m_TimeRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
m_TimeRandomizationRangeSlider.SetEnabled(false);
m_TimeRandomizationRangeField.SetEnabled(false);
m_TimeRandomRangeTracker.SetEnabled(false);
Expand Down Expand Up @@ -1267,13 +1287,13 @@ void OnCountRandomizationEnabledChanged(SerializedProperty property)
&& State.AudioContainer.loopMode != AudioRandomContainerLoopMode.Infinite
&& State.AudioContainer.triggerMode == AudioRandomContainerTriggerMode.Automatic)
{
m_CountRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOn);
m_CountRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOn);
m_CountRandomizationRangeSlider.SetEnabled(true);
m_CountRandomizationRangeField.SetEnabled(true);
}
else
{
m_CountRandomizationButtonImage.style.backgroundImage = new StyleBackground(m_DiceIconOff);
m_CountRandomizationButtonImage.style.backgroundImage = GetIconTexture(Icons.DiceOff);
m_CountRandomizationRangeSlider.SetEnabled(false);
m_CountRandomizationRangeField.SetEnabled(false);
}
Expand Down
10 changes: 0 additions & 10 deletions Editor/Mono/Audio/UIToolkitUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License

using System;
using System.IO;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.UIElements;
Expand All @@ -26,14 +25,6 @@ internal static StyleSheet LoadStyleSheet(string filePath)
return asset;
}

internal static Texture2D LoadIcon(string filename)
{
var filePath = $"{Path.Combine("Icons", "Audio", filename)}@2x.png";
var asset = EditorGUIUtility.LoadIcon(filePath);
Assert.IsNotNull(asset, $"Could not load icon from editor default resources at path: {filePath}.");
return asset;
}

internal static T GetChildByName<T>(VisualElement parentElement, string childName) where T : VisualElement
{
var childElement = parentElement.Query<VisualElement>(childName).First();
Expand All @@ -52,7 +43,6 @@ internal static T GetChildByClassName<T>(VisualElement parentElement, string chi
return childElementCast;
}


internal static T GetChildAtIndex<T>(VisualElement parentElement, int index) where T : VisualElement
{
var childElement = parentElement.ElementAt(index);
Expand Down
11 changes: 11 additions & 0 deletions Editor/Mono/BuildProfile/BuildProfileCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public sealed partial class BuildProfile
[VisibleToOtherModules]
internal static void RemoveOnBuildProfileEnable(Action<BuildProfile> action) => onBuildProfileEnable -= action;

// This callback is of use when a build profile is created via AssetDatabase, and we need to notify the UI
// and select the newly created profile in the listview.
[UsedImplicitly]
internal static event Action<BuildProfile> onBuildProfileCreated;
[VisibleToOtherModules]
internal static void AddOnBuildProfileCreated(Action<BuildProfile> action) => onBuildProfileCreated += action;
[VisibleToOtherModules]
internal static void RemoveOnBuildProfileCreated(Action<BuildProfile> action) => onBuildProfileCreated -= action;

internal static BuildProfile CreateInstance(BuildTarget buildTarget, StandaloneBuildSubtarget subtarget)
{
string moduleName = ModuleManager.GetTargetStringFrom(buildTarget);
Expand Down Expand Up @@ -60,6 +69,8 @@ internal static void CreateInstance(string platformId, string assetPath)
buildProfile,
AssetDatabase.GenerateUniqueAssetPath(assetPath));
buildProfile.OnEnable();
// Notify the UI of creation so that the new build profile can be selected
onBuildProfileCreated?.Invoke(buildProfile);
}

void TryCreatePlatformSettings()
Expand Down
5 changes: 5 additions & 0 deletions Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ public static List<string> FindAllViewablePlatforms()
return result;
}

public static bool IsPlatformAvailableOnHostPlatform(GUID platformGuid, OperatingSystemFamily operatingSystemFamily)
{
return BuildTargetDiscovery.BuildPlatformIsAvailableOnHostPlatform(platformGuid, SystemInfo.operatingSystemFamily);
}

/// <summary>
/// Check if the user is able to build his VT-enabled Player for a target platform
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion Editor/Mono/EditorUtility.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using static UnityEditor.EditorGUI;
using UnityEditor.Inspector.GraphicsSettingsInspectors;

namespace UnityEditor
{
Expand Down Expand Up @@ -206,7 +207,11 @@ public static void UnloadUnusedAssetsIgnoreManagedReferences()
[RequiredByNativeCode]
internal static void DelayedForceRebuildInspectors()
{
EditorApplication.CallDelayed(ForceRebuildInspectors);
EditorApplication.CallDelayed(() =>
{
ForceRebuildInspectors();
GraphicsSettingsInspectorUtility.ReloadGraphicsSettingsEditorIfNeeded();
});
}

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
Expand Down
6 changes: 3 additions & 3 deletions Editor/Mono/Inspector/Core/InspectorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ private void OnProjectWasLoaded()

private void OnSelectionChanged()
{
if (isLocked)
return;

RebuildContentsContainers();
if (Selection.objects.Length == 0 && m_MultiEditLabel != null)
{
m_MultiEditLabel.RemoveFromHierarchy();
}

if (isLocked)
return;

UpdateSupportedDataModesList();
}

Expand Down
2 changes: 1 addition & 1 deletion Editor/Mono/Inspector/GraphicsSettingsInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static class GraphicsSettingsData
string m_CurrentText;

bool m_FinishedInitialization;
uint m_LastListsHash;
int m_LastListsHash;
int m_GeometryChangedEventCounter;

// As we use multiple IMGUI container while porting everything to UITK we will call serializedObject.Update in first separate IMGUI container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,24 @@ internal static void ReloadGraphicsSettingsEditorIfNeeded()
provider.Reload();
}

internal static uint ComputeRenderPipelineGlobalSettingsListHash(List<GlobalSettingsContainer> settingsContainers)
internal static int ComputeRenderPipelineGlobalSettingsListHash(List<GlobalSettingsContainer> settingsContainers)
{
bool haveSettings = settingsContainers is { Count: > 0 };
if (!haveSettings)
return 0u;
return 0;

uint currentHash = 2166136261u;
var currentHash = new HashCode();
currentHash.Add(GraphicsSettings.currentRenderPipelineAssetType?.ToString() ?? "");
foreach (var globalSettings in settingsContainers)
{
TryGetSettingsListFromRenderPipelineGlobalSettings(
globalSettings.serializedObject.targetObject as RenderPipelineGlobalSettings,
out SerializedObject _,
out SerializedProperty _,
out SerializedProperty settingsListInContainer);
currentHash *= 16777619u ^ settingsListInContainer.contentHash;
currentHash.Add(settingsListInContainer.contentHash);
}
return currentHash;
return currentHash.ToHashCode();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ public override void OnInspectorGUI()
}
}

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

ResolutionSectionGUI(platform, m_SettingsExtensions[selectedPlatformValue], sectionIndex++);
m_SplashScreenEditor.SplashSectionGUI(platform, m_SettingsExtensions[selectedPlatformValue], sectionIndex++);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ class SettingsContent

PlayerSettingsEditor m_Owner;

int m_SelectedPlatform = 0;

BuildPlatform[] m_ValidPlatforms;

// Serialized icons
SerializedProperty m_PlatformIcons;
SerializedProperty m_LegacyPlatformIcons;
Expand All @@ -54,8 +50,6 @@ public PlayerSettingsIconsEditor(PlayerSettingsEditor owner)

public void OnEnable()
{
m_ValidPlatforms = BuildPlatforms.instance.GetValidPlatforms(true).ToArray();

m_PlatformIcons = m_Owner.FindPropertyAssert("m_BuildTargetPlatformIcons");
m_LegacyPlatformIcons = m_Owner.FindPropertyAssert("m_BuildTargetIcons");
m_UIPrerenderedIcon = m_Owner.FindPropertyAssert("uIPrerenderedIcon");
Expand Down Expand Up @@ -379,9 +373,8 @@ public void SerializedObjectUpdated()
DeserializeLegacyIcons();
}

public void IconSectionGUI(NamedBuildTarget namedBuildTarget, ISettingEditorExtension settingsExtension, int platformID, int sectionIndex)
public void IconSectionGUI(BuildPlatform platform, ISettingEditorExtension settingsExtension, int platformID, int sectionIndex)
{
m_SelectedPlatform = platformID;
if (!m_Owner.BeginSettingsBox(sectionIndex, SettingsContent.iconTitle))
{
m_Owner.EndSettingsBox();
Expand All @@ -394,20 +387,18 @@ public void IconSectionGUI(NamedBuildTarget namedBuildTarget, ISettingEditorExte

if (platformUsesStandardIcons)
{
var selectedDefault = (m_SelectedPlatform < 0);
var selectedDefault = (platformID < 0);
// Set default platform variables
BuildPlatform platform = null;
var platformName = "";

// Override if a platform is selected
if (!selectedDefault)
{
platform = m_ValidPlatforms[m_SelectedPlatform];
platformName = platform.name;
}

var iconUISettings = IconSettings.StandardIcons;
if (BuildTargetDiscovery.TryGetBuildTarget(platform.defaultTarget, out IBuildTarget iBuildTarget))
if (BuildTargetDiscovery.TryGetBuildTarget(BuildPipeline.GetBuildTargetByName(platform.name), out IBuildTarget iBuildTarget))
iconUISettings = iBuildTarget.IconPlatformProperties?.IconUISettings ?? IconSettings.StandardIcons;

if (iconUISettings == IconSettings.None)
Expand Down
Loading

0 comments on commit 6500e74

Please sign in to comment.