From f45f297f342239326ea865a57a1bb8ddf93e38c6 Mon Sep 17 00:00:00 2001 From: Unity Technologies Date: Wed, 16 Oct 2024 23:50:12 +0000 Subject: [PATCH 1/2] Unity 6000.0.23f1 C# reference source code --- .../SpeedTree/SpeedTree9Importer.cs | 19 +- .../SpeedTree9ImporterModelEditor.cs | 18 +- .../BuildProfile/BuildProfileModuleUtil.cs | 9 + Editor/Mono/EditorGUI.cs | 6 +- Editor/Mono/EditorGUIUtility.cs | 6 + Editor/Mono/GUI/RenameOverlay.cs | 2 + .../PlayerSettingsEditor.cs | 209 +++++++++++------- Editor/Mono/MaterialProperty.cs | 14 +- .../Modules/DefaultBuildProfileExtension.cs | 15 +- .../DefaultPlayerSettingsEditorExtension.cs | 10 +- Editor/Mono/Modules/PlatformSupportModule.cs | 10 - Editor/Mono/PlayerSettings.bindings.cs | 96 +++++++- .../Mono/ProjectBrowser/ProjectWindowUtil.cs | 14 +- .../Handlers/BuildProfileContextMenu.cs | 10 +- .../Handlers/BuildProfileDataSource.cs | 7 +- .../Editor/Services/Common/Package.cs | 15 +- .../Editor/Services/Interfaces/IPackage.cs | 2 - .../Editor/Services/Packages/PackageState.cs | 4 +- .../Editor/Services/Pages/SimplePage.cs | 3 +- .../Editor/Services/Upm/UpmPackageFactory.cs | 4 +- .../Editor/UI/PackageDetails.cs | 10 + .../PackageManagerUI/Editor/UI/PackageItem.cs | 87 +++++--- .../Editor/UI/PackageManagerWindow.cs | 20 +- .../Editor/UI/ToolBar/PackageToolBar.cs | 10 +- .../ParticleSystemModules/ShapeModuleUI.cs | 7 +- .../ShortcutHelperBar.cs | 21 +- .../FontAsset/FontAssetAtlasPopulation.cs | 2 +- .../NativeTextGenerationSettings.bindings.cs | 9 + .../Builder/Inspector/BuilderInspector.cs | 12 +- .../Core/Renderer/UIRVEShaderInfoAllocator.cs | 65 ++++-- .../Renderer/UIRenderer/UIRenderDevice.cs | 39 ---- Modules/UIElements/Core/Text/ATGTextHandle.cs | 5 +- Modules/UIElements/Core/Text/TextUtilities.cs | 9 + .../UIElements/Core/Text/UITKTextHandle.cs | 12 +- .../Core/UXML/VisualElementFactoryRegistry.cs | 7 +- Modules/UIElements/Core/VisualElement.cs | 8 +- .../Core/VisualElementDataBinding.cs | 8 + .../UIElements/Core/VisualElementTypeData.cs | 10 - .../Debugger/Events/EventTypeSearchField.cs | 2 +- .../Events/UIElementsEventDebugger.cs | 8 +- README.md | 2 +- .../ScriptBindings/SpriteRenderer.bindings.cs | 11 + Runtime/Export/UnityEvent/UnityEvent.cs | 5 + .../BeeDriver2/Bee.BeeDriver2.dll | Bin 119296 -> 119296 bytes 44 files changed, 537 insertions(+), 305 deletions(-) diff --git a/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs b/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs index 9c9285ffea..a38271eb6b 100644 --- a/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs +++ b/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs @@ -21,11 +21,9 @@ namespace UnityEditor.SpeedTree.Importer { - // [2024-08-07] version: 2 - // Fixed mesh's UV2 & UV3 data usage strategy to 'always allocate' from 'conditionally allocate' - // to fix unwanted application of leaf-facing effect to geometries without leaf-facing data. - - [ScriptedImporter(version: 2, ext: "st9", AllowCaching = true)] + // [2024-09-27] version: 3 + // Fixed code that would lead to m_LODCount vs m_PerLODSettings.arraySize mismatching in GUI + [ScriptedImporter(version: 3, ext: "st9", AllowCaching = true)] public class SpeedTree9Importer : ScriptedImporter { const int SPEEDTREE_9_WIND_VERSION = 1; @@ -233,6 +231,16 @@ private void CacheTreeImporterValues(string assetPath) { // Variables used a lot are cached, since accessing any Reader array has a non-negligeable cost. m_LODCount = (uint)m_Tree.Lod.Length; + if(m_LODCount > LODGroupGUI.kLODColors.Length) + { + Debug.LogWarningFormat("Number of LOD meshes in asset ({0}) is larger than the maximum number supported by Unity GUI ({1})." + + "\nImporting only the first {1} LOD meshes." + , m_LODCount, LODGroupGUI.kLODColors.Length); + + // LODGroup GUI won't draw if we're above this limit, so we prevent future assertions here. + m_LODCount = (uint)LODGroupGUI.kLODColors.Length; + } + m_HasFacingData = TreeHasFacingData(); m_HasBranch2Data = m_Tree.Wind.DoBranch2; m_LastLodIsBillboard = m_Tree.BillboardInfo.LastLodIsBillboard; @@ -532,6 +540,7 @@ private void CalculateBillboardAndPerLODSettings() } else if (m_PerLODSettings.Count < m_LODCount) { + m_PerLODSettings.Clear(); for (int i = 0; i < m_LODCount; ++i) { bool isBillboardLOD = m_LastLodIsBillboard && i == m_LODCount - 1; diff --git a/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9ImporterModelEditor.cs b/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9ImporterModelEditor.cs index 49eb05fb0e..29ff3dbadf 100644 --- a/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9ImporterModelEditor.cs +++ b/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9ImporterModelEditor.cs @@ -493,7 +493,12 @@ private void DrawLODGroupFoldouts(List lods) private string GetLODSubmeshAndTriCountLabel(int numLODs, int lodGroupIndex, SpeedTree9Importer im, LODGroup lodGroup) { LOD[] lods = lodGroup.GetLODs(); - Debug.Assert(lods.Length == numLODs); + + if(lods.Length != numLODs) + { + Debug.LogWarningFormat("Number of LODs mismatch between serialized object & LODGroup: {0}\nPlease re-import the asset and kindly report a bug if this warning keeps coming back.", im.assetPath); + numLODs = lods.Length; + } int[][] primitiveCounts = new int[numLODs][]; int[] submeshCounts = new int[numLODs]; @@ -547,6 +552,11 @@ private string GetLODSubmeshAndTriCountLabel(int numLODs, int lodGroupIndex, Spe return $"{totalTriCount} {LODGroupGUI.GUIStyles.m_TriangleCountLabel.text} {triangleChangeLabel} {submeshCountLabel}"; } + private Color GetLODGroupColor(int lodIndex) + { + return LODGroupGUI.kLODColors[lodIndex % LODGroupGUI.kLODColors.Length]; + } + private void DrawLODGroupFoldout(Camera camera, int lodGroupIndex, ref SavedBool foldoutState, List lodInfoList) { GameObject[] ObjectArrayToGameObjectArray(UnityEngine.Object[] objects) @@ -598,7 +608,7 @@ GameObject[] ObjectArrayToGameObjectArray(UnityEngine.Object[] objects) , foldoutState.value , LODFoldoutHeaderLabel , m_LODColorTextures[lodGroupIndex] - , LODGroupGUI.kLODColors[lodGroupIndex] * 0.6f // 0.5f magic number is copied from LODGroupsGUI.cs + , GetLODGroupColor(lodGroupIndex) * 0.6f // 0.5f magic number is copied from LODGroupsGUI.cs , LODFoldoutHeaderGroupAdditionalText ); @@ -727,13 +737,13 @@ void InitAndSetFoldoutLabelTextures() for (int i = 0; i < m_LODColorTextures.Length; i++) { m_LODColorTextures[i] = new Texture2D(1, 1); - m_LODColorTextures[i].SetPixel(0, 0, LODGroupGUI.kLODColors[i]); + m_LODColorTextures[i].SetPixel(0, 0, GetLODGroupColor(i)); } } void ResetFoldoutLists() { - int lodArraySize = m_PerLODSettings.arraySize; + int lodArraySize = Mathf.Min(m_PerLODSettings.arraySize, LODGroupGUI.kLODColors.Length); m_LODGroupFoldoutHeaderValues = new SavedBool[lodArraySize]; for (int i = 0; i < lodArraySize; i++) { diff --git a/Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs b/Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs index cd79284662..7c6ec74d6b 100644 --- a/Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs +++ b/Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs @@ -625,5 +625,14 @@ static bool ShowRestartEditorDialog(string[] settingsRequiringRestart) return EditorUtility.DisplayDialog(L10n.Tr("Unity editor restart required"), editorPromptText.ToString(), L10n.Tr("Apply"), L10n.Tr("Cancel")); } + + internal static PlayerSettings GetBuildProfileOrGlobalPlayerSettings(BuildProfile buildProfile) + { + if (buildProfile == null || buildProfile.playerSettings == null) + { + return BuildProfile.GetGlobalPlayerSettings(); + } + return buildProfile.playerSettings; + } } } diff --git a/Editor/Mono/EditorGUI.cs b/Editor/Mono/EditorGUI.cs index 86da134efc..77122c6cab 100644 --- a/Editor/Mono/EditorGUI.cs +++ b/Editor/Mono/EditorGUI.cs @@ -508,6 +508,7 @@ void IDisposable.Dispose() internal class RecycledTextEditor : TextEditor { internal static bool s_ActuallyEditing = false; // internal so we can save this state. + internal static bool s_EditingWasCompleted = false; // internal so we can save this state. internal static bool s_AllowContextCutOrPaste = true; // e.g. selectable labels only allow for copying private long[] s_OriginalLongValues; private double[] s_OriginalDoubleValues; @@ -585,6 +586,7 @@ public virtual void EndEditing() controlID = 0; s_ActuallyEditing = false; + s_EditingWasCompleted = false; s_AllowContextCutOrPaste = true; UnityEditor.Undo.IncrementCurrentGroup(); @@ -1022,8 +1024,8 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit } } - // Inform editor that someone removed focus from us. - if (editor.controlID == id && GUIUtility.keyboardControl != id || (evt.type == EventType.ValidateCommand && evt.commandName == EventCommandNames.UndoRedoPerformed)) + // Inform editor that someone removed focus from us or a rename operation was completed. + if (editor.controlID == id && GUIUtility.keyboardControl != id || EditorGUIUtility.renameWasCompleted || (evt.type == EventType.ValidateCommand && evt.commandName == EventCommandNames.UndoRedoPerformed)) { editor.EndEditing(); } diff --git a/Editor/Mono/EditorGUIUtility.cs b/Editor/Mono/EditorGUIUtility.cs index d85478ca2f..2fbfd5a7b2 100644 --- a/Editor/Mono/EditorGUIUtility.cs +++ b/Editor/Mono/EditorGUIUtility.cs @@ -1328,6 +1328,12 @@ public static bool editingTextField set { EditorGUI.RecycledTextEditor.s_ActuallyEditing = value; } } + internal static bool renameWasCompleted + { + get { return EditorGUI.RecycledTextEditor.s_EditingWasCompleted; } + set { EditorGUI.RecycledTextEditor.s_EditingWasCompleted = value; } + } + public static bool textFieldHasSelection { get { return EditorGUI.s_RecycledEditor.hasSelection; } diff --git a/Editor/Mono/GUI/RenameOverlay.cs b/Editor/Mono/GUI/RenameOverlay.cs index 67f8a7bfec..dff6fae5a0 100644 --- a/Editor/Mono/GUI/RenameOverlay.cs +++ b/Editor/Mono/GUI/RenameOverlay.cs @@ -112,6 +112,8 @@ public void EndRename(bool acceptChanges) if (!m_IsRenaming) return; + EditorGUIUtility.renameWasCompleted = true; + Undo.undoRedoEvent -= UndoRedoWasPerformed; EditorApplication.update -= BeginRenameInternalCallback; diff --git a/Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs b/Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs index cadf250947..424e49d567 100644 --- a/Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs +++ b/Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs @@ -25,6 +25,7 @@ using UnityEngine.Scripting; using UnityEngine.Bindings; using UnityEditor.Build.Profile; +using UnityEditor.UIElements; // ************************************* READ BEFORE EDITING ************************************** // @@ -308,6 +309,12 @@ PlayerSettingsIconsEditor iconsEditor private static MeshDeformation[] m_MeshDeformations = { MeshDeformation.CPU, MeshDeformation.GPU, MeshDeformation.GPUBatched }; + internal static void SyncEditors(BuildTarget target) + { + foreach(var editor in s_activeEditors) + editor.OnSyncEditor(target); + } + // Section and tab selection state SavedInt m_SelectedSection = new SavedInt("PlayerSettings.ShownSection", -1); @@ -483,22 +490,8 @@ PlayerSettingsIconsEditor iconsEditor string m_LocalizedTargetName; // reorderable lists of graphics devices, per platform - static Dictionary s_GraphicsDeviceLists = new Dictionary(); - - public static void SyncPlatformAPIsList(BuildTarget target) - { - if (!s_GraphicsDeviceLists.ContainsKey(target)) - return; - s_GraphicsDeviceLists[target].list = PlayerSettings.GetGraphicsAPIs(target).ToList(); - } - - static ReorderableList s_ScriptingDefineSymbolsList; - static ReorderableList s_ColorGamutList; - - public static void SyncColorGamuts() - { - s_ColorGamutList.list = PlayerSettings.GetColorGamuts().ToList(); - } + Dictionary m_GraphicsDeviceLists = new Dictionary(); + ReorderableList m_ColorGamutList; int scriptingDefinesControlID = 0; @@ -550,6 +543,18 @@ internal enum PlayerSettingsType internal bool IsBuildProfileEditor() => playerSettingsType == PlayerSettingsType.ActiveBuildProfile || playerSettingsType == PlayerSettingsType.NonActiveBuildProfile; internal bool IsActivePlayerSettingsEditor() => (playerSettingsType == PlayerSettingsType.Global && !BuildProfileContext.ProjectHasActiveProfileWithPlayerSettings()) || playerSettingsType == PlayerSettingsType.ActiveBuildProfile; + internal void OnTargetObjectChangedDirectly() => m_OnTrackSerializedObjectValueChanged?.Invoke(serializedObject); + + internal void OnSyncEditor(BuildTarget target) + { + SyncColorGamuts(); + + if (target == BuildTarget.NoTarget) + return; + + SyncPlatformAPIsList(target); + } + const string kSelectedPlatform = "PlayerSettings.SelectedPlatform"; /// @@ -736,7 +741,7 @@ void OnEnable() // we clear it just to be on the safe side: // we access this cache both from player settings editor and script side when changing api - s_GraphicsDeviceLists.Clear(); + m_GraphicsDeviceLists.Clear(); var selectedPlatform = SessionState.GetInt(kSelectedPlatform, currentPlatform); if (selectedPlatform < 0) @@ -834,6 +839,8 @@ internal static void HandlePlayerSettingsChanged( != next.GetLightmapStreamingEnabledForPlatformGroup_Internal(nextBuildTargetGroup)) || (current.GetLightmapStreamingPriorityForPlatformGroup_Internal(currentBuildTargetGroup) != next.GetLightmapStreamingPriorityForPlatformGroup_Internal(nextBuildTargetGroup)); + bool isShaderPrecisionChanged = PlayerSettings.ShouldSyncShaderPrecisionModel(current, next); + EditorApplication.delayCall += () => { if (isHDRCubemapEncodingChanged) @@ -850,6 +857,11 @@ internal static void HandlePlayerSettingsChanged( { Lightmapping.OnUpdateLightmapStreaming(nextBuildTargetGroup); } + + if (isShaderPrecisionChanged) + { + PlayerSettings.SyncShaderPrecisionModel(); + } }; } @@ -1404,12 +1416,13 @@ static private GraphicsDeviceType GraphicsDeviceTypeFromString(string graphicsDe private void AddGraphicsDeviceMenuSelected(object userData, string[] options, int selected) { var target = (BuildTarget)userData; - var apis = PlayerSettings.GetGraphicsAPIs(target); + var apis = m_CurrentTarget.GetGraphicsAPIs_Internal(target); if (apis == null) return; var apiToAdd = GraphicsDeviceTypeFromString(options[selected]); apis = apis.Append(apiToAdd).ToArray(); - PlayerSettings.SetGraphicsAPIs(target, apis); + m_CurrentTarget.SetGraphicsAPIs_Internal(target, apis, true); + OnTargetObjectChangedDirectly(); } private void AddGraphicsDeviceElement(BuildTarget target, Rect rect, ReorderableList list) @@ -1454,7 +1467,7 @@ private bool CanRemoveGraphicsDeviceElement(ReorderableList list) private void RemoveGraphicsDeviceElement(BuildTarget target, ReorderableList list) { - var apis = PlayerSettings.GetGraphicsAPIs(target); + var apis = m_CurrentTarget.GetGraphicsAPIs_Internal(target); if (apis == null) return; // don't allow removing the last API @@ -1473,7 +1486,7 @@ private void RemoveGraphicsDeviceElement(BuildTarget target, ReorderableList lis private void ReorderGraphicsDeviceElement(BuildTarget target, ReorderableList list) { - var previousAPIs = PlayerSettings.GetGraphicsAPIs(target); + var previousAPIs = m_CurrentTarget.GetGraphicsAPIs_Internal(target); var apiList = (List)list.list; var apis = apiList.ToArray(); @@ -1551,9 +1564,12 @@ private ChangeGraphicsApiAction CheckApplyGraphicsAPIList(BuildTarget target, bo private void ApplyChangeGraphicsApiAction(BuildTarget target, GraphicsDeviceType[] apis, ChangeGraphicsApiAction action) { if (action.changeList) - PlayerSettings.SetGraphicsAPIs(target, apis); + { + m_CurrentTarget.SetGraphicsAPIs_Internal(target, apis, true); + OnTargetObjectChangedDirectly(); + } else - s_GraphicsDeviceLists.Remove(target); // we cancelled the list change, so remove the cached one + m_GraphicsDeviceLists.Remove(target); // we cancelled the list change, so remove the cached one if (action.reloadGfx) { @@ -1570,7 +1586,7 @@ private void ApplyChangedGraphicsAPIList(BuildTarget target, GraphicsDeviceType[ private void DrawGraphicsDeviceElement(BuildTarget target, Rect rect, int index, bool selected, bool focused) { - var name = GraphicsDeviceTypeToString(target, (GraphicsDeviceType)s_GraphicsDeviceLists[target].list[index]); + var name = GraphicsDeviceTypeToString(target, (GraphicsDeviceType)m_GraphicsDeviceLists[target].list[index]); GUI.Label(rect, name, EditorStyles.label); } @@ -1645,7 +1661,7 @@ void OpenGLES31OptionsGUI(BuildTargetGroup targetGroup, BuildTarget targetPlatfo if (!hasES31Options) return; - var apis = PlayerSettings.GetGraphicsAPIs(targetPlatform); + var apis = m_CurrentTarget.GetGraphicsAPIs_Internal(targetPlatform); // only available if we include ES3 var hasMinES3 = apis.Contains(GraphicsDeviceType.OpenGLES3); if (!hasMinES3) @@ -1659,7 +1675,7 @@ void OpenGLES31OptionsGUI(BuildTargetGroup targetGroup, BuildTarget targetPlatfo void ExclusiveGraphicsAPIsGUI(BuildTarget targetPlatform, string displayTitle) { EditorGUI.BeginChangeCheck(); - GraphicsDeviceType[] currentDevices = PlayerSettings.GetGraphicsAPIs(targetPlatform); + GraphicsDeviceType[] currentDevices = m_CurrentTarget.GetGraphicsAPIs_Internal(targetPlatform); GraphicsDeviceType[] availableDevices = PlayerSettings.GetSupportedGraphicsAPIs(targetPlatform); GUIContent[] names = new GUIContent[availableDevices.Length]; @@ -1672,7 +1688,8 @@ void ExclusiveGraphicsAPIsGUI(BuildTarget targetPlatform, string displayTitle) if (EditorGUI.EndChangeCheck() && selected != currentDevices[0]) { Undo.RecordObject(target, SettingsContent.undoChangedGraphicsAPIString); - PlayerSettings.SetGraphicsAPIs(targetPlatform, new GraphicsDeviceType[] { selected }); + m_CurrentTarget.SetGraphicsAPIs_Internal(targetPlatform, new GraphicsDeviceType[] { selected }, true); + OnTargetObjectChangedDirectly(); } } @@ -1689,12 +1706,13 @@ void GraphicsAPIsGUIOnePlatform(BuildTargetGroup targetGroup, BuildTarget target // toggle for automatic API selection EditorGUI.BeginChangeCheck(); - var automatic = PlayerSettings.GetUseDefaultGraphicsAPIs(targetPlatform); + var automatic = m_CurrentTarget.GetUseDefaultGraphicsAPIs_Internal(targetPlatform); automatic = EditorGUILayout.Toggle(string.Format(L10n.Tr("Auto Graphics API {0}"), (platformTitle ?? string.Empty)), automatic); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, SettingsContent.undoChangedGraphicsAPIString); - PlayerSettings.SetUseDefaultGraphicsAPIs(targetPlatform, automatic); + m_CurrentTarget.SetUseDefaultGraphicsAPIs_Internal(targetPlatform, automatic); + OnTargetObjectChangedDirectly(); } // graphics API list if not automatic @@ -1717,9 +1735,9 @@ void GraphicsAPIsGUIOnePlatform(BuildTargetGroup targetGroup, BuildTarget target } // create reorderable list for this target if needed - if (!s_GraphicsDeviceLists.ContainsKey(targetPlatform)) + if (!m_GraphicsDeviceLists.ContainsKey(targetPlatform)) { - GraphicsDeviceType[] devices = PlayerSettings.GetGraphicsAPIs(targetPlatform); + GraphicsDeviceType[] devices = m_CurrentTarget.GetGraphicsAPIs_Internal(targetPlatform); var devicesList = (devices != null) ? devices.ToList() : new List(); var rlist = new ReorderableList(devicesList, typeof(GraphicsDeviceType), true, true, true, true); rlist.onAddDropdownCallback = (rect, list) => AddGraphicsDeviceElement(targetPlatform, rect, list); @@ -1730,15 +1748,15 @@ void GraphicsAPIsGUIOnePlatform(BuildTargetGroup targetGroup, BuildTarget target rlist.drawHeaderCallback = (rect) => GUI.Label(rect, displayTitle, EditorStyles.label); rlist.elementHeight = 16; - s_GraphicsDeviceLists.Add(targetPlatform, rlist); + m_GraphicsDeviceLists.Add(targetPlatform, rlist); } - if (targetPlatform == BuildTarget.StandaloneOSX && s_GraphicsDeviceLists[BuildTarget.StandaloneOSX].list.Contains(GraphicsDeviceType.OpenGLCore)) + if (targetPlatform == BuildTarget.StandaloneOSX && m_GraphicsDeviceLists[BuildTarget.StandaloneOSX].list.Contains(GraphicsDeviceType.OpenGLCore)) { EditorGUILayout.HelpBox(SettingsContent.appleSiliconOpenGLWarning.text, MessageType.Warning, true); } - s_GraphicsDeviceLists[targetPlatform].DoLayoutList(); + m_GraphicsDeviceLists[targetPlatform].DoLayoutList(); //@TODO: undo } @@ -1823,9 +1841,11 @@ private void AddColorGamutElement(BuildTargetGroup targetGroup, Rect rect, Reord private void AddColorGamutMenuSelected(object userData, string[] options, int selected) { var colorGamuts = (ColorGamut[])userData; - var colorGamutList = PlayerSettings.GetColorGamuts().ToList(); + var colorGamutList = m_CurrentTarget.GetColorGamuts_Internal().ToList(); colorGamutList.Add(colorGamuts[selected]); - PlayerSettings.SetColorGamuts(colorGamutList.ToArray()); + m_CurrentTarget.SetColorGamuts_Internal(colorGamutList.ToArray()); + OnTargetObjectChangedDirectly(); + SyncColorGamuts(); } private bool CanRemoveColorGamutElement(ReorderableList list) @@ -1837,7 +1857,7 @@ private bool CanRemoveColorGamutElement(ReorderableList list) private void RemoveColorGamutElement(ReorderableList list) { - var colorGamutList = PlayerSettings.GetColorGamuts().ToList(); + var colorGamutList = m_CurrentTarget.GetColorGamuts_Internal().ToList(); // don't allow removing the last ColorGamut if (colorGamutList.Count < 2) { @@ -1845,18 +1865,22 @@ private void RemoveColorGamutElement(ReorderableList list) return; } colorGamutList.RemoveAt(list.index); - PlayerSettings.SetColorGamuts(colorGamutList.ToArray()); + m_CurrentTarget.SetColorGamuts_Internal(colorGamutList.ToArray()); + OnTargetObjectChangedDirectly(); + SyncColorGamuts(); } private void ReorderColorGamutElement(ReorderableList list) { var colorGamutList = (List)list.list; - PlayerSettings.SetColorGamuts(colorGamutList.ToArray()); + m_CurrentTarget.SetColorGamuts_Internal(colorGamutList.ToArray()); + OnTargetObjectChangedDirectly(); + SyncColorGamuts(); } private void DrawColorGamutElement(BuildTargetGroup targetGroup, Rect rect, int index, bool selected, bool focused) { - var colorGamut = s_ColorGamutList.list[index]; + var colorGamut = m_ColorGamutList.list[index]; GUI.Label(rect, GetColorGamutDisplayString(targetGroup, (ColorGamut)colorGamut), EditorStyles.label); } @@ -1874,9 +1898,9 @@ void ColorGamutGUI(BuildPlatform platform) (properties?.SupportsColorGamut ?? false))) return; - if (s_ColorGamutList == null) + if (m_ColorGamutList == null) { - ColorGamut[] colorGamuts = PlayerSettings.GetColorGamuts(); + ColorGamut[] colorGamuts = m_CurrentTarget.GetColorGamuts_Internal(); var colorGamutsList = (colorGamuts != null) ? colorGamuts.ToList() : new List(); var rlist = new ReorderableList(colorGamutsList, typeof(ColorGamut), true, true, true, true); rlist.onCanRemoveCallback = CanRemoveColorGamutElement; @@ -1884,23 +1908,23 @@ void ColorGamutGUI(BuildPlatform platform) rlist.onReorderCallback = ReorderColorGamutElement; rlist.elementHeight = 16; - s_ColorGamutList = rlist; + m_ColorGamutList = rlist; } // On standalone inspector mention that the setting applies only to Mac // (Temporarily until other standalones support this setting) GUIContent header = targetGroup == BuildTargetGroup.Standalone ? SettingsContent.colorGamutForMac : SettingsContent.colorGamut; - s_ColorGamutList.drawHeaderCallback = (rect) => + m_ColorGamutList.drawHeaderCallback = (rect) => GUI.Label(rect, header, EditorStyles.label); // we want to change the displayed text per platform, to indicate unsupported gamuts - s_ColorGamutList.onAddDropdownCallback = (rect, list) => + m_ColorGamutList.onAddDropdownCallback = (rect, list) => AddColorGamutElement(targetGroup, rect, list); - s_ColorGamutList.drawElementCallback = (rect, index, selected, focused) => + m_ColorGamutList.drawElementCallback = (rect, index, selected, focused) => DrawColorGamutElement(targetGroup, rect, index, selected, focused); - s_ColorGamutList.DoLayoutList(); + m_ColorGamutList.DoLayoutList(); } public void DebugAndCrashReportingGUI(BuildPlatform platform, @@ -2051,13 +2075,17 @@ private void OtherSectionShaderSettingsGUI(BuildPlatform platform) using (new EditorGUI.DisabledScope(EditorApplication.isPlaying || EditorApplication.isCompiling)) { EditorGUI.BeginChangeCheck(); - - ShaderPrecisionModel currShaderPrecisionModel = PlayerSettings.GetShaderPrecisionModel(); + ShaderPrecisionModel currShaderPrecisionModel = (ShaderPrecisionModel) m_ShaderPrecisionModel.intValue; ShaderPrecisionModel[] shaderPrecisionModelValues = { ShaderPrecisionModel.PlatformDefault, ShaderPrecisionModel.Unified }; - ShaderPrecisionModel newShaderPrecisionModel = BuildEnumPopup(SettingsContent.shaderPrecisionModel, currShaderPrecisionModel, shaderPrecisionModelValues, SettingsContent.shaderPrecisionModelOptions); + ShaderPrecisionModel newShaderPrecisionModel = BuildEnumPopup( + SettingsContent.shaderPrecisionModel, currShaderPrecisionModel, shaderPrecisionModelValues, + SettingsContent.shaderPrecisionModelOptions); if (EditorGUI.EndChangeCheck() && currShaderPrecisionModel != newShaderPrecisionModel) { - PlayerSettings.SetShaderPrecisionModel(newShaderPrecisionModel); + m_ShaderPrecisionModel.intValue = (int) newShaderPrecisionModel; + serializedObject.ApplyModifiedProperties(); + if (IsActivePlayerSettingsEditor()) + PlayerSettings.SyncShaderPrecisionModel(); } } @@ -2257,7 +2285,7 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte { if (platform.namedBuildTarget.ToBuildTargetGroup() == BuildTargetGroup.Standalone) { - GraphicsDeviceType[] gfxAPIs = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget); + GraphicsDeviceType[] gfxAPIs = m_CurrentTarget.GetGraphicsAPIs_Internal(platform.defaultTarget); hdrDisplaySupported = gfxAPIs[0] == GraphicsDeviceType.Direct3D11 || gfxAPIs[0] == GraphicsDeviceType.Direct3D12 || gfxAPIs[0] == GraphicsDeviceType.Vulkan || gfxAPIs[0] == GraphicsDeviceType.Metal; } @@ -2265,12 +2293,12 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte if (platform.namedBuildTarget.ToBuildTargetGroup() == BuildTargetGroup.Standalone) { - GraphicsDeviceType[] gfxAPIs = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget); + GraphicsDeviceType[] gfxAPIs = m_CurrentTarget.GetGraphicsAPIs_Internal(platform.defaultTarget); gfxJobModesSupported = (gfxAPIs[0] == GraphicsDeviceType.Direct3D12) || (gfxAPIs[0] == GraphicsDeviceType.Vulkan); } else if (platform.namedBuildTarget.ToBuildTargetGroup() == BuildTargetGroup.Android) { - GraphicsDeviceType[] gfxAPIs = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget); + GraphicsDeviceType[] gfxAPIs = m_CurrentTarget.GetGraphicsAPIs_Internal(platform.defaultTarget); gfxJobModesSupported = (gfxAPIs[0] == GraphicsDeviceType.Vulkan); } @@ -2279,7 +2307,7 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte { bool platformSupportsBatching = false; - GraphicsDeviceType[] gfxAPIs = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget); + GraphicsDeviceType[] gfxAPIs = m_CurrentTarget.GetGraphicsAPIs_Internal(platform.defaultTarget); foreach (GraphicsDeviceType api in gfxAPIs) { if (api == GraphicsDeviceType.Switch || @@ -2339,7 +2367,7 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte } bool graphicsJobsOptionEnabled = true; - bool graphicsJobs = PlayerSettings.GetGraphicsJobsForPlatform(platform.defaultTarget); + bool graphicsJobs = PlayerSettings.GetGraphicsJobsForPlatform_Internal(m_CurrentTarget, platform.defaultTarget); bool newGraphicsJobs = graphicsJobs; if (platform.namedBuildTarget == NamedBuildTarget.XboxOne) @@ -2347,31 +2375,33 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte // on XBoxOne, we only have kGfxJobModeNative active for DX12 API and kGfxJobModeLegacy for the DX11 API // no need for a drop down popup for XBoxOne // also if XboxOneD3D12 is selected as GraphicsAPI, then we want to set graphics jobs and disable the user option - GraphicsDeviceType[] gfxAPIs = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget); + GraphicsDeviceType[] gfxAPIs = m_CurrentTarget.GetGraphicsAPIs_Internal(platform.defaultTarget); GraphicsJobMode newGfxJobMode = GraphicsJobMode.Legacy; if (gfxAPIs[0] == GraphicsDeviceType.XboxOneD3D12) { newGfxJobMode = GraphicsJobMode.Split; if (graphicsJobs == false) { - PlayerSettings.SetGraphicsJobsForPlatform(platform.defaultTarget, true); + PlayerSettings.SetGraphicsJobsForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, true); graphicsJobs = true; newGraphicsJobs = true; } } - PlayerSettings.SetGraphicsJobModeForPlatform(platform.defaultTarget, newGfxJobMode); - PlayerSettings.SetGraphicsThreadingModeForPlatform(platform.defaultTarget, GfxThreadingMode.SplitJobs); + PlayerSettings.SetGraphicsJobModeForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, newGfxJobMode); + PlayerSettings.SetGraphicsThreadingModeForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, GfxThreadingMode.SplitJobs); + OnTargetObjectChangedDirectly(); } else if (platform.namedBuildTarget == NamedBuildTarget.PS5) { // On PS5NGGC, we always have graphics jobs enabled so we disable the option in that case - GraphicsDeviceType[] gfxAPIs = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget); + GraphicsDeviceType[] gfxAPIs = m_CurrentTarget.GetGraphicsAPIs_Internal(platform.defaultTarget); if (gfxAPIs[0] == GraphicsDeviceType.PlayStation5NGGC) { graphicsJobsOptionEnabled = false; if (graphicsJobs == false) { - PlayerSettings.SetGraphicsJobsForPlatform(platform.defaultTarget, true); + PlayerSettings.SetGraphicsJobsForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, true); + OnTargetObjectChangedDirectly(); graphicsJobs = true; newGraphicsJobs = true; } @@ -2400,10 +2430,10 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte if (EditorGUI.EndChangeCheck() && (newGraphicsJobs != graphicsJobs)) { Undo.RecordObject(target, SettingsContent.undoChangedGraphicsJobsString); - PlayerSettings.SetGraphicsJobsForPlatform(platform.defaultTarget, newGraphicsJobs); + PlayerSettings.SetGraphicsJobsForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, newGraphicsJobs); + OnTargetObjectChangedDirectly(); - bool restartEditor = CheckApplyGraphicsJobsModeChange(platform.defaultTarget); - if (restartEditor) + if (IsActivePlayerSettingsEditor() && CheckApplyGraphicsJobsModeChange(platform.defaultTarget)) { EditorApplication.RequestCloseAndRelaunchWithCurrentArguments(); GUIUtility.ExitGUI(); @@ -2416,7 +2446,7 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte var checkGfxJobModeSupport = (Enum value) => { return settingsExtension != null ? settingsExtension.AdjustGfxJobMode((GraphicsJobMode)value) == (GraphicsJobMode)value : true; }; EditorGUI.BeginChangeCheck(); - GraphicsJobMode currGfxJobMode = PlayerSettings.GetGraphicsJobModeForPlatform(platform.defaultTarget); + GraphicsJobMode currGfxJobMode = PlayerSettings.GetGraphicsJobModeForPlatform_Internal(m_CurrentTarget, platform.defaultTarget); GraphicsJobMode newGfxJobMode = (GraphicsJobMode)EditorGUILayout.EnumPopup(SettingsContent.graphicsJobsMode, currGfxJobMode, checkGfxJobModeSupport, false); if (EditorGUI.EndChangeCheck() && (newGfxJobMode != currGfxJobMode)) @@ -2434,17 +2464,17 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte // Finally we apply the change of gfx job mode if (newGfxJobMode != currGfxJobMode) { - PlayerSettings.SetGraphicsJobModeForPlatform(platform.defaultTarget, newGfxJobMode); + PlayerSettings.SetGraphicsJobModeForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, newGfxJobMode); if(newGfxJobMode == GraphicsJobMode.Native) - PlayerSettings.SetGraphicsThreadingModeForPlatform(platform.defaultTarget, GfxThreadingMode.ClientWorkerNativeJobs); + PlayerSettings.SetGraphicsThreadingModeForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, GfxThreadingMode.ClientWorkerNativeJobs); else if (newGfxJobMode == GraphicsJobMode.Legacy) - PlayerSettings.SetGraphicsThreadingModeForPlatform(platform.defaultTarget, GfxThreadingMode.ClientWorkerJobs); + PlayerSettings.SetGraphicsThreadingModeForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, GfxThreadingMode.ClientWorkerJobs); else if (newGfxJobMode == GraphicsJobMode.Split) - PlayerSettings.SetGraphicsThreadingModeForPlatform(platform.defaultTarget, GfxThreadingMode.SplitJobs); + PlayerSettings.SetGraphicsThreadingModeForPlatform_Internal(m_CurrentTarget, platform.defaultTarget, GfxThreadingMode.SplitJobs); - bool restartEditor = CheckApplyGraphicsJobsModeChange(platform.defaultTarget); - if (restartEditor) + OnTargetObjectChangedDirectly(); + if (IsActivePlayerSettingsEditor() && CheckApplyGraphicsJobsModeChange(platform.defaultTarget)) { EditorApplication.RequestCloseAndRelaunchWithCurrentArguments(); GUIUtility.ExitGUI(); @@ -2688,8 +2718,8 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte using (new EditorGUI.DisabledScope(EditorApplication.isPlaying || EditorApplication.isCompiling)) { var target = platform.namedBuildTarget.ToBuildTargetGroup(); - bool debugModeEnabled = PlayerSettings.GetLoadStoreDebugModeEnabledForPlatformGroup(target); - bool debugModeEditorOnly = PlayerSettings.GetLoadStoreDebugModeEditorOnlyForPlatformGroup(target); + bool debugModeEnabled = m_CurrentTarget.GetLoadStoreDebugModeEnabledForPlatformGroup_Internal(target); + bool debugModeEditorOnly = m_CurrentTarget.GetLoadStoreDebugModeEditorOnlyForPlatformGroup_Internal(target); EditorGUI.BeginChangeCheck(); debugModeEnabled = EditorGUILayout.Toggle(SettingsContent.loadStoreDebugModeCheckbox, debugModeEnabled); @@ -2701,8 +2731,9 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte } if (EditorGUI.EndChangeCheck()) { - PlayerSettings.SetLoadStoreDebugModeEnabledForPlatformGroup(target, debugModeEnabled); - PlayerSettings.SetLoadStoreDebugModeEditorOnlyForPlatformGroup(target, debugModeEditorOnly); + m_CurrentTarget.SetLoadStoreDebugModeEnabledForPlatformGroup_Internal(target, debugModeEnabled); + m_CurrentTarget.SetLoadStoreDebugModeEditorOnlyForPlatformGroup_Internal(target, debugModeEditorOnly); + OnTargetObjectChangedDirectly(); GUIUtility.ExitGUI(); } @@ -2713,7 +2744,7 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte private bool VirtualTexturingInvalidGfxAPI(BuildTarget target, bool checkEditor) { - GraphicsDeviceType[] gfxTypes = PlayerSettings.GetGraphicsAPIs(target); + GraphicsDeviceType[] gfxTypes = m_CurrentTarget.GetGraphicsAPIs_Internal(target); bool supportedAPI = true; foreach (GraphicsDeviceType api in gfxTypes) @@ -2754,7 +2785,7 @@ private bool CheckIfWebGPUInGfxAPIList() { foreach (var target in k_WebGPUSupportedBuildTargets) { - if (PlayerSettings.GetGraphicsAPIs(target).Contains(GraphicsDeviceType.WebGPU)) + if (m_CurrentTarget.GetGraphicsAPIs_Internal(target).Contains(GraphicsDeviceType.WebGPU)) { return true; } @@ -2993,6 +3024,11 @@ private EditorAssembliesCompatibilityLevel GetEditorAssembliesCompatibilityLevel return (EditorAssembliesCompatibilityLevel)m_EditorAssembliesCompatibilityLevel.intValue; } + bool HasAnyNetFXCompatibilityLevel() + { + return m_CurrentTarget?.HasAnyNetFXCompatibilityLevel() ?? false; + } + private void SetEditorAssembliesCompatibilityLevel(EditorAssembliesCompatibilityLevel editorAssembliesCompatibilityLevel) { // We won't allow switching back to the "Default" value. @@ -3082,7 +3118,7 @@ private void OtherSectionConfigurationGUI(BuildPlatform platform, ISettingEditor } // Editor Assemblies Compatibility level - using (new EditorGUI.DisabledScope(m_SerializedObject.isEditingMultipleObjects)) + using (new EditorGUI.DisabledScope(m_SerializedObject.isEditingMultipleObjects || HasAnyNetFXCompatibilityLevel())) { using (var horizontal = new EditorGUILayout.HorizontalScope()) { @@ -4173,5 +4209,20 @@ bool CanShowPlatformSettingsForHostPlatform(BuildTarget settingsBuildTarget, Bui return BuildTargetDiscovery.BuildPlatformIsAvailableOnHostPlatform(settingsBuildTarget, SystemInfo.operatingSystemFamily); } + + void SyncColorGamuts() + { + if (m_ColorGamutList == null) + return; + + m_ColorGamutList.list = m_CurrentTarget.GetColorGamuts_Internal().ToList(); + } + + void SyncPlatformAPIsList(BuildTarget target) + { + if (!m_GraphicsDeviceLists.ContainsKey(target)) + return; + m_GraphicsDeviceLists[target].list = m_CurrentTarget.GetGraphicsAPIs_Internal(target).ToList(); + } } } diff --git a/Editor/Mono/MaterialProperty.cs b/Editor/Mono/MaterialProperty.cs index 7276b20782..5fd739eac7 100644 --- a/Editor/Mono/MaterialProperty.cs +++ b/Editor/Mono/MaterialProperty.cs @@ -477,7 +477,7 @@ static void HandleApplyRevert(GenericMenu menu, bool singleEditing, Object[] tar static void HandleCopyPaste(GenericMenu menu) { - GetCopyPasteAction(capturedProperties[0], out var copyAction, out var pasteAction); + GetCopyPasteAction(s_CopyPasteCache, out var copyAction, out var pasteAction); if (menu.GetItemCount() != 0) menu.AddSeparator(""); @@ -520,9 +520,11 @@ static void DoRegularMenu(GenericMenu menu, bool isOverriden, Object[] targets) if (isOverriden) HandleApplyRevert(menu, singleEditing, targets); - if (singleEditing && capturedProperties.Count == 1) + if (singleEditing && s_CopyPasteCache != null) + { HandleCopyPaste(menu); - + s_CopyPasteCache = null; + } DisplayMode displayMode = GetDisplayMode(targets); if (displayMode == DisplayMode.Material) { @@ -537,7 +539,7 @@ static void DoRegularMenu(GenericMenu menu, bool isOverriden, Object[] targets) static void GetCopyPasteAction(MaterialProperty prop, out GenericMenu.MenuFunction copyAction, out GenericMenu.MenuFunction pasteAction) { - bool canCopy = !capturedProperties[0].hasMixedValue; + bool canCopy = !s_CopyPasteCache.hasMixedValue; bool canPaste = GUI.enabled; copyAction = null; @@ -652,6 +654,7 @@ static void GotoLockOriginAction(Object[] targets) } } static List s_PropertyStack = new List(); + static MaterialProperty s_CopyPasteCache = null; internal static void ClearStack() => s_PropertyStack.Clear(); internal static void BeginProperty(MaterialProperty prop, Object[] targets) @@ -672,6 +675,9 @@ internal static void BeginProperty(MaterialSerializedProperty prop, Object[] tar internal static void BeginProperty(Rect totalRect, MaterialProperty prop, MaterialSerializedProperty serializedProp, Object[] targets, float startY = -1) { + if (Event.current.rawType == EventType.ContextClick && (totalRect.Contains(Event.current.mousePosition))) + s_CopyPasteCache = prop; + if (targets == null || IsRegistered(prop, serializedProp)) { s_PropertyStack.Add(new PropertyData() { targets = null }); diff --git a/Editor/Mono/Modules/DefaultBuildProfileExtension.cs b/Editor/Mono/Modules/DefaultBuildProfileExtension.cs index 92563038ad..12c7004b03 100644 --- a/Editor/Mono/Modules/DefaultBuildProfileExtension.cs +++ b/Editor/Mono/Modules/DefaultBuildProfileExtension.cs @@ -58,6 +58,7 @@ internal abstract class DefaultBuildProfileExtension : IBuildProfileExtension NamedBuildTarget m_NamedBuildTarget; protected bool m_IsClassicProfile = false; protected SharedPlatformSettings m_SharedSettings; + BuildProfile m_BuildProfile; // The properties can be unresponsive on multiple clicks due to the // complex layout calculations which can slow down GUI rendering. @@ -146,13 +147,13 @@ public VisualElement CreateCommonSettingsGUI(SerializedObject serializedObject, m_CompressionType = FindPlatformSettingsPropertyAssert(rootProperty, "m_CompressionType"); m_InstallInBuildFolder = FindPlatformSettingsPropertyAssert(rootProperty, "m_InstallInBuildFolder"); - var profile = serializedObject.targetObject as BuildProfile; - Debug.Assert(profile != null); - m_BuildTarget = profile.buildTarget; - var subtarget = profile.subtarget; + m_BuildProfile = serializedObject.targetObject as BuildProfile; + Debug.Assert(m_BuildProfile != null, "Build profile cannot be null"); + m_BuildTarget = m_BuildProfile.buildTarget; + var subtarget = m_BuildProfile.subtarget; m_BuildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_BuildTarget); m_NamedBuildTarget = (subtarget == StandaloneBuildSubtarget.Server) ? NamedBuildTarget.Server : NamedBuildTarget.FromBuildTargetGroup(m_BuildTargetGroup); - m_IsClassicProfile = BuildProfileContext.IsClassicPlatformProfile(profile); + m_IsClassicProfile = BuildProfileContext.IsClassicPlatformProfile(m_BuildProfile); m_SharedSettings = BuildProfileContext.instance.sharedProfile.platformBuildProfile as SharedPlatformSettings; return new IMGUIContainer( @@ -321,8 +322,8 @@ public virtual void ShowProfilerCheckbox() public virtual void ShowScriptDebuggingCheckbox() { ShowManagedDebuggerCheckboxes(); - - if (m_AllowDebugging.boolValue && PlayerSettings.GetScriptingBackend(m_NamedBuildTarget) == ScriptingImplementation.IL2CPP) + var currentPlayerSettings = BuildProfileModuleUtil.GetBuildProfileOrGlobalPlayerSettings(m_BuildProfile); + if (m_AllowDebugging.boolValue && PlayerSettings.GetScriptingBackend_Internal(currentPlayerSettings, m_NamedBuildTarget.TargetName) == ScriptingImplementation.IL2CPP) { var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(m_NamedBuildTarget); bool isDebuggerUsable = apiCompatibilityLevel == ApiCompatibilityLevel.NET_4_6 || apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard_2_0 || diff --git a/Editor/Mono/Modules/DefaultPlayerSettingsEditorExtension.cs b/Editor/Mono/Modules/DefaultPlayerSettingsEditorExtension.cs index de8a6c4de3..aaff79da12 100644 --- a/Editor/Mono/Modules/DefaultPlayerSettingsEditorExtension.cs +++ b/Editor/Mono/Modules/DefaultPlayerSettingsEditorExtension.cs @@ -143,10 +143,16 @@ public virtual void MultithreadedRenderingGUI(NamedBuildTarget namedBuildTarget) // For other platforms the "Multithreaded Rendering" feature is controlled by PlayerSettings::m_MTRendering. Default value is true (set during PlayerSettings::Reset) if (BuildTargetDiscovery.PlatformGroupHasFlag(namedBuildTarget.ToBuildTargetGroup(), TargetAttributes.IsMTRenderingDisabledByDefault)) { - bool oldValue = PlayerSettings.GetMobileMTRendering(namedBuildTarget); + var playerSettings = playerSettingsEditor.m_SerializedObject.targetObject as PlayerSettings; + Debug.Assert(playerSettings != null); + + bool oldValue = playerSettings.GetMobileMTRenderingInternal_Instance(namedBuildTarget.TargetName); bool newValue = EditorGUILayout.Toggle(MultithreadedRenderingGUITooltip(), oldValue); if (oldValue != newValue) - PlayerSettings.SetMobileMTRendering(namedBuildTarget, newValue); + { + playerSettings.SetMobileMTRenderingInternal_Instance(namedBuildTarget.TargetName, newValue); + playerSettingsEditor.OnTargetObjectChangedDirectly(); + } } else EditorGUILayout.PropertyField(m_MTRendering, m_MTRenderingTooltip); } diff --git a/Editor/Mono/Modules/PlatformSupportModule.cs b/Editor/Mono/Modules/PlatformSupportModule.cs index a509aeaca6..9f28fdda01 100644 --- a/Editor/Mono/Modules/PlatformSupportModule.cs +++ b/Editor/Mono/Modules/PlatformSupportModule.cs @@ -191,16 +191,6 @@ internal class DefaultScriptingImplementations : IScriptingImplementations { public virtual ScriptingImplementation[] Supported() { - if (Unsupported.IsSourceBuild()) // CORECLR_FIXME remove sourcebuild - { - return new[] - { - ScriptingImplementation.Mono2x, - ScriptingImplementation.IL2CPP, - #pragma warning disable 618 - ScriptingImplementation.CoreCLR - }; - } return new[] { ScriptingImplementation.Mono2x, diff --git a/Editor/Mono/PlayerSettings.bindings.cs b/Editor/Mono/PlayerSettings.bindings.cs index a2a1f68f43..8f069d12ee 100644 --- a/Editor/Mono/PlayerSettings.bindings.cs +++ b/Editor/Mono/PlayerSettings.bindings.cs @@ -840,7 +840,7 @@ public static void SetGraphicsAPIs(BuildTarget platform, UnityEngine.Rendering.G { SetGraphicsAPIsImpl(platform, apis); // we do cache api list in player settings editor, so if we update from script we should forcibly update cache - PlayerSettingsEditor.SyncPlatformAPIsList(platform); + PlayerSettingsEditor.SyncEditors(platform); } [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] @@ -853,7 +853,7 @@ public static void SetUseDefaultGraphicsAPIs(BuildTarget platform, bool automati { SetUseDefaultGraphicsAPIsImpl(platform, automatic); // we do cache api list in player settings editor, so if we update from script we should forcibly update cache - PlayerSettingsEditor.SyncPlatformAPIsList(platform); + PlayerSettingsEditor.SyncEditors(platform); } [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] @@ -867,7 +867,7 @@ internal static void SetColorGamuts(ColorGamut[] colorSpaces) { SetColorGamutsImpl(colorSpaces); // Color space data is cached in player settings editor - PlayerSettingsEditor.SyncColorGamuts(); + PlayerSettingsEditor.SyncEditors(BuildTarget.NoTarget); } [NativeMethod("SetColorGamuts")] @@ -1234,6 +1234,14 @@ internal static ApiCompatibilityLevel EditorAssemblyCompatibilityToApiCompatibil private static extern EditorAssembliesCompatibilityLevel GetEditorAssembliesCompatibilityLevelInternal(); public static EditorAssembliesCompatibilityLevel GetEditorAssembliesCompatibilityLevel() => GetEditorAssembliesCompatibilityLevelInternal(); + [NativeMethod("GetEditorOnly().HasAnyNetFXCompatibilityLevel")] + private extern bool HasAnyNetFXCompatibilityLevelInternal(); + + internal bool HasAnyNetFXCompatibilityLevel() + { + return HasAnyNetFXCompatibilityLevelInternal(); + } + [NativeThrows] [StaticAccessor("GetPlayerSettings().GetEditorOnlyForUpdate()")] [NativeMethod("SetEditorAssembliesCompatibilityLevel")] @@ -1730,7 +1738,6 @@ public static WindowsGamepadBackendHint windowsGamepadBackendHint [StaticAccessor("GetPlayerSettings().GetEditorOnlyForUpdate()")] public static extern void SetShaderPrecisionModel(ShaderPrecisionModel model); - [StaticAccessor("GetPlayerSettings().GetEditorOnly()")] internal static extern TextureCompressionFormat GetDefaultTextureCompressionFormat(BuildTarget platform); @@ -1822,6 +1829,22 @@ internal static extern bool iosCopyPluginsCodeInsteadOfSymlink [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] internal static extern int GetShaderChunkCountForPlatform_Internal(PlayerSettings instance, BuildTarget buildTarget); + // --- Graphics Job + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern bool GetGraphicsJobsForPlatform_Internal(PlayerSettings instance, BuildTarget platform); + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern void SetGraphicsJobsForPlatform_Internal(PlayerSettings instance, BuildTarget platform, bool graphicsJobs); + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern GraphicsJobMode GetGraphicsJobModeForPlatform_Internal(PlayerSettings instance, BuildTarget platform); + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern void SetGraphicsJobModeForPlatform_Internal(PlayerSettings instance, BuildTarget platform, GraphicsJobMode gfxJobMode); + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern void SetGraphicsThreadingModeForPlatform_Internal(PlayerSettings instance, BuildTarget platform, GfxThreadingMode gfxJobMode); + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] internal static extern void SetShaderChunkCountForPlatform_Internal(PlayerSettings instance, BuildTarget buildTarget, int chunkCount); @@ -1831,6 +1854,15 @@ internal static extern bool iosCopyPluginsCodeInsteadOfSymlink [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] internal static extern void SetNormalMapEncoding_Internal(PlayerSettings instance, string platform, NormalMapEncoding encoding); + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern ScriptingImplementation GetScriptingBackend_Internal(PlayerSettings playerSettings, string buildTargetGroupName); + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern bool ShouldSyncShaderPrecisionModel(PlayerSettings prev, PlayerSettings next); + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + internal static extern void SyncShaderPrecisionModel(); + /* * Internal non-static getter/setters referenced when reading/writing to non-active player settings object. */ @@ -1861,5 +1893,61 @@ internal static extern bool iosCopyPluginsCodeInsteadOfSymlink [StaticAccessor("PlayerSettings", StaticAccessorType.DoubleColon)] internal static extern string[] GetSettingsRequiringRestart(PlayerSettings prevSettings, PlayerSettings newSettings, BuildTarget prevBuildTarget, BuildTarget newBuildTarget); + + // Load / Store + [NativeMethod("GetLoadStoreDebugModeEnabled")] + internal extern bool GetLoadStoreDebugModeEnabledForPlatformGroup_Internal(BuildTargetGroup platformGroup); + + [NativeMethod("SetLoadStoreDebugModeEnabled")] + internal extern void SetLoadStoreDebugModeEnabledForPlatformGroup_Internal(BuildTargetGroup platformGroup, bool loadStoreDebugModeEnabled); + + [NativeMethod("GetLoadStoreDebugModeEditorOnly")] + internal extern bool GetLoadStoreDebugModeEditorOnlyForPlatformGroup_Internal(BuildTargetGroup platformGroup); + + [NativeMethod("SetLoadStoreDebugModeEditorOnly")] + internal extern void SetLoadStoreDebugModeEditorOnlyForPlatformGroup_Internal(BuildTargetGroup platformGroup, bool loadStoreDebugModeEnabled); + + // Mobile Rendering + [NativeThrows] + [NativeMethod("SetMobileMTRendering")] + internal extern void SetMobileMTRenderingInternal_Instance(string buildTargetName, bool enable); + + [NativeThrows] + [NativeMethod("GetMobileMTRendering")] + internal extern bool GetMobileMTRenderingInternal_Instance(string buildTargetName); + + // Graphics APIs + [NativeMethod("GetPlatformAutomaticGraphicsAPIs")] + internal extern bool GetUseDefaultGraphicsAPIs_Internal(BuildTarget platform); + + internal void SetUseDefaultGraphicsAPIs_Internal(BuildTarget platform, bool automatic) + { + SetUseDefaultGraphicsAPIsImpl_Internal(this, platform, automatic); + // we do cache api list in player settings editor, so if we update from script we should forcibly update cache + PlayerSettingsEditor.SyncEditors(platform); + } + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + private static extern void SetUseDefaultGraphicsAPIsImpl_Internal(PlayerSettings instance, BuildTarget platform, bool automatic); + + [NativeMethod("GetPlatformGraphicsAPIs")] + internal extern UnityEngine.Rendering.GraphicsDeviceType[] GetGraphicsAPIs_Internal(BuildTarget platform); + + [StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)] + private static extern void SetGraphicsAPIsImpl_Internal(PlayerSettings instance, BuildTarget platform, UnityEngine.Rendering.GraphicsDeviceType[] apis); + + internal void SetGraphicsAPIs_Internal(BuildTarget platform, UnityEngine.Rendering.GraphicsDeviceType[] apis, bool shouldSync) + { + SetGraphicsAPIsImpl_Internal(this, platform, apis); + // we do cache api list in player settings editor, so if we update from script we should forcibly update cache + if (shouldSync) + PlayerSettingsEditor.SyncEditors(platform); + } + + [NativeMethod("GetColorGamuts")] + internal extern ColorGamut[] GetColorGamuts_Internal(); + + [NativeMethod("SetColorGamuts")] + internal extern void SetColorGamuts_Internal(ColorGamut[] colorSpaces); } } diff --git a/Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs b/Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs index 590f59a1d3..4451152d23 100644 --- a/Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs +++ b/Editor/Mono/ProjectBrowser/ProjectWindowUtil.cs @@ -867,13 +867,13 @@ internal static void GetAncestors(int instanceID, HashSet ancestors) if (instanceID == ProjectBrowser.kPackagesFolderInstanceId) return; - // Ensure we add the main asset as ancestor if input is a subasset + // Ensure we add the main asset as ancestor if input is a sub-asset int mainAssetInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(AssetDatabase.GetAssetPath(instanceID)); bool isSubAsset = mainAssetInstanceID != instanceID; if (isSubAsset) ancestors.Add(mainAssetInstanceID); - // Find ancestors of main aset + // Find ancestors of main asset string currentFolderPath = GetContainingFolder(AssetDatabase.GetAssetPath(mainAssetInstanceID)); while (!string.IsNullOrEmpty(currentFolderPath)) { @@ -1102,11 +1102,13 @@ internal static bool DeleteAssets(List instanceIDs, bool askIfSure) { infotext.AppendLine(); string name = (paths.Length == 1) ? "This Material" : "One or more of these Material(s)"; - infotext.AppendLine(name + " has one or more children. Would you like to reparent all of these children to their closest remaining ancestor?"); - int dialogOptionIndex = EditorUtility.DisplayDialogComplex(title, infotext.ToString(), L10n.Tr("Delete and reparent children"), L10n.Tr("Delete only"), L10n.Tr("Cancel")); - if (dialogOptionIndex == 0) + infotext.AppendLine(name + " is inherited by one or more children. Deleting will result in the children re-mapping to their closest remaining ancestor. Would you like to proceed with re-parenting?"); + + bool dialogOptionIndex = EditorUtility.DisplayDialog(title, infotext.ToString(), L10n.Tr("Delete and re-parent children"), L10n.Tr("Cancel")); + + if (dialogOptionIndex) reparentMaterials = true; - else if (dialogOptionIndex == 2) + else return false; } else if (!EditorUtility.DisplayDialog(title, infotext.ToString(), L10n.Tr("Delete"), L10n.Tr("Cancel"))) diff --git a/Modules/BuildProfileEditor/Handlers/BuildProfileContextMenu.cs b/Modules/BuildProfileEditor/Handlers/BuildProfileContextMenu.cs index b1e4cac3a4..8823453864 100644 --- a/Modules/BuildProfileEditor/Handlers/BuildProfileContextMenu.cs +++ b/Modules/BuildProfileEditor/Handlers/BuildProfileContextMenu.cs @@ -95,14 +95,18 @@ internal ContextualMenuManipulator AddBuildProfileContextMenu() internal bool UpdateBuildProfileLabelName(object buildProfileObject, string buildProfileLabelName) { + buildProfileLabelName = buildProfileLabelName?.Trim(); + var buildProfile = buildProfileObject as BuildProfile; if (buildProfile == null || string.IsNullOrEmpty(buildProfileLabelName)) return false; string newName = buildProfileLabelName; - m_ProfileDataSource.RenameAsset(buildProfile, newName); - SelectBuildProfileInView(buildProfile, isClassic: false, shouldAppend: false); - return true; + if (m_ProfileDataSource.RenameAsset(buildProfile, newName)) { + SelectBuildProfileInView(buildProfile, isClassic: false, shouldAppend: false); + return true; + } + return false; } internal void HandleDuplicateSelectedProfiles(bool duplicateClassic) diff --git a/Modules/BuildProfileEditor/Handlers/BuildProfileDataSource.cs b/Modules/BuildProfileEditor/Handlers/BuildProfileDataSource.cs index fa9e03e41b..8552f47e61 100644 --- a/Modules/BuildProfileEditor/Handlers/BuildProfileDataSource.cs +++ b/Modules/BuildProfileEditor/Handlers/BuildProfileDataSource.cs @@ -186,10 +186,10 @@ internal void DeleteNullProfiles() /// build profile list. The build profile will be re-added when it /// gets enabled after renaming. /// - internal void RenameAsset(BuildProfile buildProfile, string newName) + internal bool RenameAsset(BuildProfile buildProfile, string newName) { if (buildProfile?.name == newName || string.IsNullOrEmpty(newName)) - return; + return false; var originalPath = AssetDatabase.GetAssetPath(buildProfile); var newPath = ReplaceFileNameInPath(originalPath, newName); @@ -204,7 +204,10 @@ internal void RenameAsset(BuildProfile buildProfile, string newName) customBuildProfiles.Remove(buildProfile); m_Window.RebuildProfileListViews(); AssetDatabase.RenameAsset(originalPath, finalName); + return true; } + + return false; } /// diff --git a/Modules/PackageManagerUI/Editor/Services/Common/Package.cs b/Modules/PackageManagerUI/Editor/Services/Common/Package.cs index 553e779703..1cacf61e5b 100644 --- a/Modules/PackageManagerUI/Editor/Services/Common/Package.cs +++ b/Modules/PackageManagerUI/Editor/Services/Common/Package.cs @@ -63,9 +63,6 @@ public PackageState state if (primary.HasTag(PackageTag.Custom)) return PackageState.InDevelopment; - if (isLocked) - return PackageState.Locked; - if (primary.isInstalled && !primary.isDirectDependency) return PackageState.InstalledAsDependency; @@ -100,10 +97,6 @@ public PackageState state private bool m_IsDeprecated; public virtual bool isDeprecated => m_IsDeprecated; - [SerializeField] - private bool m_IsLocked; - public virtual bool isLocked => m_IsLocked; - // errors on the package level (not just about a particular version) [SerializeField] private List m_Errors; @@ -144,7 +137,7 @@ public void OnAfterDeserialize() LinkPackageAndVersions(); } - private Package(string name, IVersionList versionList, Product product = null, bool isDiscoverable = true, bool isDeprecated = false, string deprecationMessage = null, bool isLocked = false) + private Package(string name, IVersionList versionList, Product product = null, bool isDiscoverable = true, bool isDeprecated = false, string deprecationMessage = null) { m_Name = name; m_VersionList = versionList; @@ -159,8 +152,6 @@ private Package(string name, IVersionList versionList, Product product = null, b m_IsDeprecated = versionList.primary?.HasTag(PackageTag.InstalledFromPath) == false && isDeprecated; m_DeprecationMessage = deprecationMessage; - m_IsLocked = isLocked; - LinkPackageAndVersions(); } @@ -169,9 +160,9 @@ private Package(string name, IVersionList versionList, Product product = null, b // package modifications that's not caught by the package change events. internal class Factory : BaseService { - public Package CreatePackage(string name, IVersionList versionList, Product product = null, bool isDiscoverable = true, bool isDeprecated = false, string deprecationMessage = null, bool isLocked = false) + public Package CreatePackage(string name, IVersionList versionList, Product product = null, bool isDiscoverable = true, bool isDeprecated = false, string deprecationMessage = null) { - return new Package(name, versionList, product, isDiscoverable, isDeprecated, deprecationMessage, isLocked); + return new Package(name, versionList, product, isDiscoverable, isDeprecated, deprecationMessage); } public void AddError(Package package, UIError error) diff --git a/Modules/PackageManagerUI/Editor/Services/Interfaces/IPackage.cs b/Modules/PackageManagerUI/Editor/Services/Interfaces/IPackage.cs index 211b697adc..5e79c7a60c 100644 --- a/Modules/PackageManagerUI/Editor/Services/Interfaces/IPackage.cs +++ b/Modules/PackageManagerUI/Editor/Services/Interfaces/IPackage.cs @@ -42,7 +42,5 @@ internal interface IPackage : UI.IPackage string deprecationMessage { get; } bool isDeprecated { get; } - - bool isLocked { get; } } } diff --git a/Modules/PackageManagerUI/Editor/Services/Packages/PackageState.cs b/Modules/PackageManagerUI/Editor/Services/Packages/PackageState.cs index 0d96a7f2eb..9d1d6164ea 100644 --- a/Modules/PackageManagerUI/Editor/Services/Packages/PackageState.cs +++ b/Modules/PackageManagerUI/Editor/Services/Packages/PackageState.cs @@ -17,8 +17,6 @@ internal enum PackageState UpdateAvailable, InProgress, Error, - Warning, - Locked, - UnlockedByUser + Warning } } diff --git a/Modules/PackageManagerUI/Editor/Services/Pages/SimplePage.cs b/Modules/PackageManagerUI/Editor/Services/Pages/SimplePage.cs index 22a98e56e7..eaee0de159 100644 --- a/Modules/PackageManagerUI/Editor/Services/Pages/SimplePage.cs +++ b/Modules/PackageManagerUI/Editor/Services/Pages/SimplePage.cs @@ -116,7 +116,8 @@ protected virtual void SortGroupNames(List groupNames) public override bool GetDefaultLockState(IPackage package) { - return package.isLocked; + return package.versions.installed?.isDirectDependency != true && + m_PackageDatabase.GetFeaturesThatUseThisPackage(package.versions.installed)?.Any() == true; } // All the following load functions do nothing, because for a SimplePage we already know the complete list and there's no more to load diff --git a/Modules/PackageManagerUI/Editor/Services/Upm/UpmPackageFactory.cs b/Modules/PackageManagerUI/Editor/Services/Upm/UpmPackageFactory.cs index 38f40121f7..0065e70f0a 100644 --- a/Modules/PackageManagerUI/Editor/Services/Upm/UpmPackageFactory.cs +++ b/Modules/PackageManagerUI/Editor/Services/Upm/UpmPackageFactory.cs @@ -168,9 +168,7 @@ public void GeneratePackagesAndTriggerChangeEvent(IEnumerable packageNam continue; } - var isLocked = versionList.installed?.isDirectDependency != true && - m_PackageDatabase.GetFeaturesThatUseThisPackage(versionList.installed)?.Any() == true; - var package = CreatePackage(packageName, versionList, isDiscoverable: searchInfo != null, isDeprecated: isDeprecated, deprecationMessage: deprecationMessage, isLocked: isLocked); + var package = CreatePackage(packageName, versionList, isDiscoverable: searchInfo != null, isDeprecated: isDeprecated, deprecationMessage: deprecationMessage); updatedPackages.Add(package); // if the primary version is not fully fetched, trigger an extra fetch automatically right away to get results early diff --git a/Modules/PackageManagerUI/Editor/UI/PackageDetails.cs b/Modules/PackageManagerUI/Editor/UI/PackageDetails.cs index bf9a0ef22c..5b8b1ed469 100644 --- a/Modules/PackageManagerUI/Editor/UI/PackageDetails.cs +++ b/Modules/PackageManagerUI/Editor/UI/PackageDetails.cs @@ -63,6 +63,8 @@ public void OnEnable() m_PageManager.onSelectionChanged += OnSelectionChanged; + m_PageManager.onVisualStateChange += OnVisualStateChange; + m_UnityConnectProxy.onUserLoginStateChange += OnUserLoginStateChange; // We need this refresh because there is a small delay between OnEnable and OnCreateGUI @@ -97,9 +99,17 @@ public void OnDisable() m_PageManager.onSelectionChanged -= OnSelectionChanged; + m_PageManager.onVisualStateChange -= OnVisualStateChange; + m_UnityConnectProxy.onUserLoginStateChange -= OnUserLoginStateChange; } + private void OnVisualStateChange(VisualStateChangeArgs args) + { + if (args.page == m_PageManager.activePage) + Refresh(m_PageManager.activePage.GetSelection()); + } + private void RefreshSelectedTabHeight(GeometryChangedEvent evt) { if (evt.oldRect.height == evt.newRect.height) diff --git a/Modules/PackageManagerUI/Editor/UI/PackageItem.cs b/Modules/PackageManagerUI/Editor/UI/PackageItem.cs index 57070719dc..bafa1b5264 100644 --- a/Modules/PackageManagerUI/Editor/UI/PackageItem.cs +++ b/Modules/PackageManagerUI/Editor/UI/PackageItem.cs @@ -101,6 +101,9 @@ private void BuildMainItem(bool isFeature) m_StateIcon = new VisualElement { name = "stateIcon", classList = { "status" } }; m_StateContainer.Add(m_StateIcon); + m_LockedIcon = new VisualElement { name = "lockedIcon", classList = { "lock" } }; + m_MainItem.Add(m_LockedIcon); + if (isFeature) { m_InfoStateIcon = new VisualElement { name = "versionState" }; @@ -134,7 +137,7 @@ public void Refresh(VisualState newVisualState = null) m_TagLabel.Refresh(package.versions.primary); - RefreshRightStateIcons(); + RefreshIconsOnTheRight(); RefreshSelection(); RefreshEntitlement(); } @@ -145,30 +148,19 @@ public void SetPackage(IPackage package) name = package?.displayName ?? package?.uniqueId ?? string.Empty; } - public void RefreshRightStateIcons() + private void RefreshIconsOnTheRight() { + UIUtils.SetElementDisplay(m_Spinner, false); + UIUtils.SetElementDisplay(m_StateIcon, false); + UIUtils.SetElementDisplay(m_LockedIcon, false); + if (RefreshSpinner()) return; - var state = GetCurrentPackageState(); - var stateClass = state != PackageState.None ? state.ToString().ToLower() : null; - if (!string.IsNullOrEmpty(m_CurrentStateClass)) - m_StateIcon.RemoveFromClassList(m_CurrentStateClass); - if (!string.IsNullOrEmpty(stateClass)) - m_StateIcon.AddToClassList(stateClass); - m_CurrentStateClass = stateClass; - - m_StateIcon.tooltip = GetTooltipByState(state); - - if (state == PackageState.Installed && package.versions.primary.HasTag(PackageTag.Feature)) - RefreshFeatureState(); - } + if (RefreshLockIcons()) + return; - private PackageState GetCurrentPackageState() - { - return package?.state == PackageState.Locked && visualState.userUnlocked - ? PackageState.UnlockedByUser - : package?.state ?? PackageState.None; + RefreshRightStateIcons(); } // Returns true if package is in progress and spinner is visible @@ -183,6 +175,52 @@ private bool RefreshSpinner() return isInProgress; } + private bool RefreshLockIcons() + { + const string k_Locked = "locked"; + const string k_UnlockedByUser = "unlockedbyuser"; + + m_LockedIcon.RemoveFromClassList(k_Locked); + m_LockedIcon.RemoveFromClassList(k_UnlockedByUser); + + if (!visualState.userUnlocked && !visualState.isLocked) + return false; + + UIUtils.SetElementDisplay(m_LockedIcon, true); + if (visualState.userUnlocked) + { + m_LockedIcon.AddToClassList(k_UnlockedByUser); + m_LockedIcon.tooltip = string.Format(L10n.Tr("This {0} is unlocked. You can now change its version."), + package.versions.primary.GetDescriptor()); + } + else if (visualState.isLocked) + { + m_LockedIcon.AddToClassList(k_Locked); + m_LockedIcon.tooltip = string.Format(L10n.Tr("This {0} is installed by a feature."), + package.versions.primary.GetDescriptor()); + } + + return true; + } + + public void RefreshRightStateIcons() + { + UIUtils.SetElementDisplay(m_StateIcon, true); + + var state = package?.state ?? PackageState.None; + var stateClass = state != PackageState.None ? state.ToString().ToLower() : null; + if (!string.IsNullOrEmpty(m_CurrentStateClass)) + m_StateIcon.RemoveFromClassList(m_CurrentStateClass); + if (!string.IsNullOrEmpty(stateClass)) + m_StateIcon.AddToClassList(stateClass); + m_CurrentStateClass = stateClass; + + m_StateIcon.tooltip = GetTooltipByState(state); + + if (state == PackageState.Installed && package.versions.primary.HasTag(PackageTag.Feature)) + RefreshFeatureState(); + } + private void RefreshFeatureState() { if (GetFeatureState(targetVersion) == FeatureState.Customized) @@ -246,6 +284,8 @@ public void ToggleSelectMainItem() private void StartSpinner() { + UIUtils.SetElementDisplay(m_Spinner, true); + if (m_Spinner == null) { m_Spinner = new LoadingSpinner {name = "packageSpinner"}; @@ -254,19 +294,18 @@ private void StartSpinner() m_Spinner.Start(); m_Spinner.tooltip = GetTooltipByProgress(package.progress); - UIUtils.SetElementDisplay(m_StateIcon, false); } private void StopSpinner() { m_Spinner?.Stop(); - UIUtils.SetElementDisplay(m_StateIcon, true); } private Label m_NameLabel; private PackageDynamicTagLabel m_TagLabel; private VisualElement m_MainItem; private VisualElement m_StateIcon; + private VisualElement m_LockedIcon; private VisualElement m_InfoStateIcon; private VisualElement m_StateContainer; private Label m_EntitlementLabel; @@ -289,9 +328,7 @@ private void StopSpinner() L10n.Tr("A newer version of this {0} is available."), "", L10n.Tr("There are errors with this {0}. Read the {0} details for further guidance."), - L10n.Tr("There are warnings with this {0}. Read the {0} details for further guidance."), - L10n.Tr("This {0} is installed by a feature."), - L10n.Tr("This {0} is unlocked. You can now change its version.") + L10n.Tr("There are warnings with this {0}. Read the {0} details for further guidance.") }; public string GetTooltipByState(PackageState state) diff --git a/Modules/PackageManagerUI/Editor/UI/PackageManagerWindow.cs b/Modules/PackageManagerUI/Editor/UI/PackageManagerWindow.cs index 36269af0cc..a732309c9c 100644 --- a/Modules/PackageManagerUI/Editor/UI/PackageManagerWindow.cs +++ b/Modules/PackageManagerUI/Editor/UI/PackageManagerWindow.cs @@ -63,7 +63,6 @@ internal class PackageManagerWindow : EditorWindow internal static PackageManagerWindow instance { get; private set; } private PackageManagerWindowRoot m_Root; - private ScrollView m_ScrollView; internal const string k_UpmUrl = "com.unity3d.kharma:upmpackage/"; @@ -76,7 +75,7 @@ void OnEnable() titleContent = GetLocalizedTitleContent(); - minSize = new Vector2(1050, 250); + minSize = new Vector2(748, 250); BuildGUI(); Events.registeredPackages += OnRegisteredPackages; @@ -98,23 +97,12 @@ private void BuildGUI() var assetStoreCachePathProxy = container.Resolve(); var pageRefreshHandler = container.Resolve(); var operationDispatcher = container.Resolve(); - - // Adding the ScrollView object here because it really need to be the first child under rootVisualElement for it to work properly. - // Since the StyleSheet is added to PackageManagerRoot, the css is exceptionally added directly to the object - m_ScrollView = new ScrollView - { - mode = ScrollViewMode.Horizontal, - style = - { - flexGrow = 1 - } - }; + m_Root = new PackageManagerWindowRoot(resourceLoader, extensionManager, selection, packageManagerPrefs, packageDatabase, pageManager, settingsProxy, unityConnectProxy, applicationProxy, upmClient, assetStoreCachePathProxy, pageRefreshHandler, operationDispatcher); try { m_Root.OnEnable(); - rootVisualElement.Add(m_ScrollView); - m_ScrollView.Add(m_Root); + rootVisualElement.Add(m_Root); } catch (ResourceLoaderException) { @@ -320,7 +308,7 @@ private static void OnRegisteredPackages(PackageRegistrationEventArgs args) internal static void SelectPackageAndPageStatic(string packageToSelect = null, string pageId = null, bool refresh = false, string searchText = "") { instance = GetWindow(); - instance.minSize = new Vector2(1050, 250); + instance.minSize = new Vector2(748, 250); instance.m_Root.SelectPackageAndPage(packageToSelect, pageId, refresh, searchText); instance.Show(); } diff --git a/Modules/PackageManagerUI/Editor/UI/ToolBar/PackageToolBar.cs b/Modules/PackageManagerUI/Editor/UI/ToolBar/PackageToolBar.cs index 37e0c63b25..0ea11807c3 100644 --- a/Modules/PackageManagerUI/Editor/UI/ToolBar/PackageToolBar.cs +++ b/Modules/PackageManagerUI/Editor/UI/ToolBar/PackageToolBar.cs @@ -63,15 +63,15 @@ public PackageToolbar() m_ErrorState = new PackageToolBarError { name = "toolbarErrorState" }; m_MainContainer.Add(m_ErrorState); - var leftItems = new VisualElement(); - leftItems.AddToClassList("leftItems"); - m_MainContainer.Add(leftItems); + var actionButtons = new VisualElement(); + actionButtons.AddToClassList("actionButtons"); + m_MainContainer.Add(actionButtons); extensions = new VisualElement { name = "extensionItems" }; - leftItems.Add(extensions); + actionButtons.Add(extensions); m_BuiltInActionsContainer = new VisualElement { name = "builtInActions" }; - m_BuiltInActionsContainer.AddToClassList("rightItems"); + m_BuiltInActionsContainer.AddToClassList("actionButtons"); m_MainContainer.Add(m_BuiltInActionsContainer); m_ProgressContainer = new VisualElement { name = "toolbarProgressContainer" }; diff --git a/Modules/ParticleSystemEditor/ParticleSystemModules/ShapeModuleUI.cs b/Modules/ParticleSystemEditor/ParticleSystemModules/ShapeModuleUI.cs index 3fa2a22078..cc1976bab2 100644 --- a/Modules/ParticleSystemEditor/ParticleSystemModules/ShapeModuleUI.cs +++ b/Modules/ParticleSystemEditor/ParticleSystemModules/ShapeModuleUI.cs @@ -1013,7 +1013,7 @@ internal static void OnShapeToolGUI(bool allowGizmoEditing, IEnumerable 0) { // Create new atlas texture SetupNewAtlasTexture(); diff --git a/Modules/TextCoreTextEngine/Managed/TextGenerator/NativeTextGenerationSettings.bindings.cs b/Modules/TextCoreTextEngine/Managed/TextGenerator/NativeTextGenerationSettings.bindings.cs index 771a828471..a6c9ae448a 100644 --- a/Modules/TextCoreTextEngine/Managed/TextGenerator/NativeTextGenerationSettings.bindings.cs +++ b/Modules/TextCoreTextEngine/Managed/TextGenerator/NativeTextGenerationSettings.bindings.cs @@ -23,6 +23,7 @@ internal struct NativeTextGenerationSettings public int screenWidth; // Encoded in Fixed Point. public int screenHeight; // Encoded in Fixed Point. public WhiteSpace wordWrap; + public TextOverflow overflow; public LanguageDirection languageDirection; public int vertexPadding; // Encoded in Fixed Point. [VisibleToOtherModules("UnityEngine.UIElementsModule")] @@ -100,6 +101,7 @@ internal NativeTextGenerationSettings(NativeTextGenerationSettings tgs) fontWeight = tgs.fontWeight; languageDirection = tgs.languageDirection; vertexPadding = tgs.vertexPadding; + overflow = tgs.overflow; textSpans = tgs.textSpans != null ? (TextSpan[])tgs.textSpans.Clone() : null; } @@ -140,6 +142,7 @@ public override string ToString() $"{nameof(fontStyle)}: {fontStyle}\n" + $"{nameof(fontWeight)}: {fontWeight}\n" + $"{nameof(vertexPadding)}: {vertexPadding}\n" + + $"{nameof(overflow)}: {overflow}\n" + $"{nameof(textSpans)}: {textSpansString}"; } } @@ -212,4 +215,10 @@ internal enum WhiteSpace PreWrap } + [VisibleToOtherModules("UnityEngine.UIElementsModule")] + internal enum TextOverflow + { + Clip, + Ellipsis + } } diff --git a/Modules/UIBuilder/Editor/Builder/Inspector/BuilderInspector.cs b/Modules/UIBuilder/Editor/Builder/Inspector/BuilderInspector.cs index e5f9a496f0..adf9726511 100644 --- a/Modules/UIBuilder/Editor/Builder/Inspector/BuilderInspector.cs +++ b/Modules/UIBuilder/Editor/Builder/Inspector/BuilderInspector.cs @@ -246,17 +246,9 @@ public BuilderInspector(BuilderPaneWindow paneWindow, BuilderSelection selection template.CloneTree(this); m_TextGeneratorStyle = this.Q(null, "unity-text-generator"); - if (Unsupported.IsDeveloperMode()) - { - UIToolkitProjectSettings.onEnableAdvancedTextChanged += ChangeTextGeneratorStyleVisibility; - m_TextGeneratorStyle.style.display = UIToolkitProjectSettings.enableAdvancedText ? DisplayStyle.Flex : DisplayStyle.None; - } - else - { - UIToolkitProjectSettings.onEnableAdvancedTextChanged -= ChangeTextGeneratorStyleVisibility; - m_TextGeneratorStyle.style.display = DisplayStyle.None; - } + UIToolkitProjectSettings.onEnableAdvancedTextChanged += ChangeTextGeneratorStyleVisibility; + m_TextGeneratorStyle.style.display = UIToolkitProjectSettings.enableAdvancedText ? DisplayStyle.Flex : DisplayStyle.None; // Get the scroll view. // HACK: ScrollView is not capable of remembering a scroll position for content that changes often. diff --git a/Modules/UIElements/Core/Renderer/UIRVEShaderInfoAllocator.cs b/Modules/UIElements/Core/Renderer/UIRVEShaderInfoAllocator.cs index 86da5f1dfa..2bb1d74282 100644 --- a/Modules/UIElements/Core/Renderer/UIRVEShaderInfoAllocator.cs +++ b/Modules/UIElements/Core/Renderer/UIRVEShaderInfoAllocator.cs @@ -162,20 +162,20 @@ class UIRVEShaderInfoAllocator // The page coordinates correspond to the atlas's internal algorithm's results. // If that algorithm changes, the new results must be put here to match - internal static readonly Vector2Int identityTransformTexel = new Vector2Int(0, 0); - internal static readonly Vector2Int infiniteClipRectTexel = new Vector2Int(0, 32); - internal static readonly Vector2Int fullOpacityTexel = new Vector2Int(32, 32); - internal static readonly Vector2Int clearColorTexel = new Vector2Int(0, 40); - internal static readonly Vector2Int defaultTextCoreSettingsTexel = new Vector2Int(32, 0); - - internal static readonly Matrix4x4 identityTransformValue = Matrix4x4.identity; - internal static readonly Vector4 identityTransformRow0Value = identityTransformValue.GetRow(0); - internal static readonly Vector4 identityTransformRow1Value = identityTransformValue.GetRow(1); - internal static readonly Vector4 identityTransformRow2Value = identityTransformValue.GetRow(2); - internal static readonly Vector4 infiniteClipRectValue = new Vector4(0, 0, 0, 0); - internal static readonly Vector4 fullOpacityValue = new Vector4(1, 1, 1, 1); - internal static readonly Vector4 clearColorValue = new Vector4(0, 0, 0, 0); - internal static readonly TextCoreSettings defaultTextCoreSettingsValue = new TextCoreSettings() { + static readonly Vector2Int identityTransformTexel = new Vector2Int(0, 0); + static readonly Vector2Int infiniteClipRectTexel = new Vector2Int(0, 32); + static readonly Vector2Int fullOpacityTexel = new Vector2Int(32, 32); + static readonly Vector2Int clearColorTexel = new Vector2Int(0, 40); + static readonly Vector2Int defaultTextCoreSettingsTexel = new Vector2Int(32, 0); + + static readonly Matrix4x4 identityTransformValue = Matrix4x4.identity; + static readonly Vector4 identityTransformRow0Value = identityTransformValue.GetRow(0); + static readonly Vector4 identityTransformRow1Value = identityTransformValue.GetRow(1); + static readonly Vector4 identityTransformRow2Value = identityTransformValue.GetRow(2); + static readonly Vector4 infiniteClipRectValue = new Vector4(0, 0, 0, 0); + static readonly Vector4 fullOpacityValue = new Vector4(1, 1, 1, 1); + static readonly Vector4 clearColorValue = new Vector4(0, 0, 0, 0); + static readonly TextCoreSettings defaultTextCoreSettingsValue = new TextCoreSettings() { faceColor = Color.white, outlineColor = Color.clear, outlineWidth = 0.0f, @@ -189,6 +189,38 @@ class UIRVEShaderInfoAllocator public static readonly BMPAlloc identityTransform, infiniteClipRect, fullOpacity, clearColor, defaultTextCoreSettings; #pragma warning restore 649 + static int s_DefaultShaderInfoTextureRefCount; + static Texture2D s_DefaultShaderInfoTexture; + static void AcquireDefaultShaderInfoTexture() + { + if (++s_DefaultShaderInfoTextureRefCount == 1) + { + s_DefaultShaderInfoTexture = new Texture2D(64, 64, TextureFormat.RGBAFloat, false); // No mips + s_DefaultShaderInfoTexture.name = "DefaultShaderInfoTexFloat"; + s_DefaultShaderInfoTexture.hideFlags = HideFlags.HideAndDontSave; + s_DefaultShaderInfoTexture.filterMode = FilterMode.Point; + s_DefaultShaderInfoTexture.SetPixel(identityTransformTexel.x, identityTransformTexel.y + 0, identityTransformRow0Value); + s_DefaultShaderInfoTexture.SetPixel(identityTransformTexel.x, identityTransformTexel.y + 1, identityTransformRow1Value); + s_DefaultShaderInfoTexture.SetPixel(identityTransformTexel.x, identityTransformTexel.y + 2, identityTransformRow2Value); + s_DefaultShaderInfoTexture.SetPixel(infiniteClipRectTexel.x, infiniteClipRectTexel.y, infiniteClipRectValue); + s_DefaultShaderInfoTexture.SetPixel(fullOpacityTexel.x, fullOpacityTexel.y, fullOpacityValue); + s_DefaultShaderInfoTexture.SetPixel(defaultTextCoreSettingsTexel.x, defaultTextCoreSettingsTexel.y + 0, Color.white); + s_DefaultShaderInfoTexture.SetPixel(defaultTextCoreSettingsTexel.x, defaultTextCoreSettingsTexel.y + 1, Color.clear); + s_DefaultShaderInfoTexture.SetPixel(defaultTextCoreSettingsTexel.x, defaultTextCoreSettingsTexel.y + 2, Color.clear); + s_DefaultShaderInfoTexture.SetPixel(defaultTextCoreSettingsTexel.x, defaultTextCoreSettingsTexel.y + 3, Color.clear); + s_DefaultShaderInfoTexture.Apply(false, true); + } + } + + static void ReleaseDefaultShaderInfoTexture() + { + if (--s_DefaultShaderInfoTextureRefCount == 0) + { + UIRUtility.Destroy(s_DefaultShaderInfoTexture); + s_DefaultShaderInfoTexture = null; + } + } + static Vector2Int AllocToTexelCoord(ref BitmapAllocator32 allocator, BMPAlloc alloc) { UInt16 x, y; @@ -213,7 +245,7 @@ public Texture atlas { if (m_StorageReallyCreated) return m_Storage.texture; - return UIRenderDevice.defaultShaderInfoTexFloat; + return s_DefaultShaderInfoTexture; } } public bool internalAtlasCreated { get { return m_StorageReallyCreated; } } // For diagnostics really @@ -236,6 +268,8 @@ public UIRVEShaderInfoAllocator(ColorSpace colorSpace) m_ColorAllocator.ForceFirstAlloc((ushort)clearColorTexel.x, (ushort)clearColorTexel.y); m_TextSettingsAllocator.Construct(pageHeight, 1, 4); m_TextSettingsAllocator.ForceFirstAlloc((ushort)defaultTextCoreSettingsTexel.x, (ushort)defaultTextCoreSettingsTexel.y); + + AcquireDefaultShaderInfoTexture(); } void ReallyCreateStorage() @@ -281,6 +315,7 @@ public void Dispose() m_Storage.Dispose(); m_Storage = null; m_StorageReallyCreated = false; + ReleaseDefaultShaderInfoTexture(); } public void IssuePendingStorageChanges() diff --git a/Modules/UIElements/Core/Renderer/UIRenderer/UIRenderDevice.cs b/Modules/UIElements/Core/Renderer/UIRenderer/UIRenderDevice.cs index 9b1be4b33c..20dff827b3 100644 --- a/Modules/UIElements/Core/Renderer/UIRenderer/UIRenderDevice.cs +++ b/Modules/UIElements/Core/Renderer/UIRenderer/UIRenderDevice.cs @@ -169,35 +169,6 @@ protected UIRenderDevice(uint initialVertexCapacity, uint initialIndexCapacity, } } - #region Default system resources - static private Texture2D s_DefaultShaderInfoTexFloat; - static internal Texture2D defaultShaderInfoTexFloat - { - get - { - if (s_DefaultShaderInfoTexFloat == null) - { - s_DefaultShaderInfoTexFloat = new Texture2D(64, 64, TextureFormat.RGBAFloat, false); // No mips - s_DefaultShaderInfoTexFloat.name = "DefaultShaderInfoTexFloat"; - s_DefaultShaderInfoTexFloat.hideFlags = HideFlags.HideAndDontSave; - s_DefaultShaderInfoTexFloat.filterMode = FilterMode.Point; - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.identityTransformTexel.x, UIRVEShaderInfoAllocator.identityTransformTexel.y + 0, UIRVEShaderInfoAllocator.identityTransformRow0Value); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.identityTransformTexel.x, UIRVEShaderInfoAllocator.identityTransformTexel.y + 1, UIRVEShaderInfoAllocator.identityTransformRow1Value); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.identityTransformTexel.x, UIRVEShaderInfoAllocator.identityTransformTexel.y + 2, UIRVEShaderInfoAllocator.identityTransformRow2Value); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.infiniteClipRectTexel.x, UIRVEShaderInfoAllocator.infiniteClipRectTexel.y, UIRVEShaderInfoAllocator.infiniteClipRectValue); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.fullOpacityTexel.x, UIRVEShaderInfoAllocator.fullOpacityTexel.y, UIRVEShaderInfoAllocator.fullOpacityValue); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.x, UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.y + 0, Color.white); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.x, UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.y + 1, Color.clear); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.x, UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.y + 2, Color.clear); - s_DefaultShaderInfoTexFloat.SetPixel(UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.x, UIRVEShaderInfoAllocator.defaultTextCoreSettingsTexel.y + 3, Color.clear); - s_DefaultShaderInfoTexFloat.Apply(false, true); - } - return s_DefaultShaderInfoTexFloat; - } - } - - #endregion - void InitVertexDeclaration() { var vertexDecl = new VertexAttributeDescriptor[] @@ -1216,11 +1187,6 @@ void PruneUnusedPages() internal static void PrepareForGfxDeviceRecreate() { m_ActiveDeviceCount += 1; // Don't let the count reach 0 and unsubscribe from GfxDeviceRecreate - if (s_DefaultShaderInfoTexFloat != null) - { - UIRUtility.Destroy(s_DefaultShaderInfoTexFloat); - s_DefaultShaderInfoTexFloat = null; - } } internal static void WrapUpGfxDeviceRecreate() { m_ActiveDeviceCount -= 1; } @@ -1305,11 +1271,6 @@ private static void ProcessDeviceFreeQueue() if (m_ActiveDeviceCount == 0 && m_SubscribedToNotifications) { - if (s_DefaultShaderInfoTexFloat != null) - { - UIRUtility.Destroy(s_DefaultShaderInfoTexFloat); - s_DefaultShaderInfoTexFloat = null; - } Utility.NotifyOfUIREvents(false); m_SubscribedToNotifications = false; } diff --git a/Modules/UIElements/Core/Text/ATGTextHandle.cs b/Modules/UIElements/Core/Text/ATGTextHandle.cs index e30f4ef63a..d51c829d93 100644 --- a/Modules/UIElements/Core/Text/ATGTextHandle.cs +++ b/Modules/UIElements/Core/Text/ATGTextHandle.cs @@ -148,11 +148,12 @@ internal bool ConvertUssToNativeTextGenerationSettings() nativeSettings.fontSize = (int)(style.fontSize.value > 0 ? style.fontSize.value * 64.0f : fa.faceInfo.pointSize * 64.0f); - nativeSettings.wordWrap = m_TextElement.computedStyle.whiteSpace.toTextCore(); + nativeSettings.wordWrap = style.whiteSpace.toTextCore(); + nativeSettings.overflow = style.textOverflow.toTextCore(style.overflow); nativeSettings.horizontalAlignment = TextGeneratorUtilities.GetHorizontalAlignment(style.unityTextAlign); nativeSettings.verticalAlignment = TextGeneratorUtilities.GetVerticalAlignment(style.unityTextAlign); - nativeSettings.color = m_TextElement.computedStyle.color; + nativeSettings.color = style.color; nativeSettings.fontAsset = fa.nativeFontAsset; nativeSettings.languageDirection = m_TextElement.localLanguageDirection.toTextCore(); nativeSettings.vertexPadding = (int)(GetVertexPadding(fa) * 64.0f); diff --git a/Modules/UIElements/Core/Text/TextUtilities.cs b/Modules/UIElements/Core/Text/TextUtilities.cs index f666306638..81798e1a4b 100644 --- a/Modules/UIElements/Core/Text/TextUtilities.cs +++ b/Modules/UIElements/Core/Text/TextUtilities.cs @@ -228,5 +228,14 @@ public static TextCore.WhiteSpace toTextCore(this WhiteSpace whiteSpace) _ => TextCore.WhiteSpace.Normal }; } + + public static TextCore.TextOverflow toTextCore(this TextOverflow textOverflow, OverflowInternal overflow) + { + return textOverflow switch + { + TextOverflow.Ellipsis when overflow == OverflowInternal.Hidden => TextCore.TextOverflow.Ellipsis, + _ => TextCore.TextOverflow.Clip + }; + } } } diff --git a/Modules/UIElements/Core/Text/UITKTextHandle.cs b/Modules/UIElements/Core/Text/UITKTextHandle.cs index 5567784dd5..4403f2c6c9 100644 --- a/Modules/UIElements/Core/Text/UITKTextHandle.cs +++ b/Modules/UIElements/Core/Text/UITKTextHandle.cs @@ -89,10 +89,16 @@ public void UpdateMesh() public override void AddTextInfoToPermanentCache() { if (useAdvancedText) - ConvertUssToNativeTextGenerationSettings(); - else - ConvertUssToTextGenerationSettings(); + { + if (textGenerationInfo == IntPtr.Zero) + textGenerationInfo = TextGenerationInfo.Create(); + bool success = false; + UpdateNative(ref success); + return; + } + + ConvertUssToTextGenerationSettings(); base.AddTextInfoToPermanentCache(); } diff --git a/Modules/UIElements/Core/UXML/VisualElementFactoryRegistry.cs b/Modules/UIElements/Core/UXML/VisualElementFactoryRegistry.cs index b00e0de94b..3cefb12805 100644 --- a/Modules/UIElements/Core/UXML/VisualElementFactoryRegistry.cs +++ b/Modules/UIElements/Core/UXML/VisualElementFactoryRegistry.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; using UnityEngine.Bindings; using UnityEngine.Scripting.APIUpdating; @@ -24,9 +23,9 @@ internal static string GetMovedUIControlTypeName(Type type, MovedFromAttribute a if (type == null) return string.Empty; - MovedFromAttributeData data = attr.data; - var namespaceName = data.nameSpaceHasChanged ? data.nameSpace : VisualElement.GetOrCreateTypeData(type).typeNamespace; - var typeName = data.classHasChanged ? data.className : VisualElement.GetOrCreateTypeData(type).typeName; + var data = attr.data; + var namespaceName = data.nameSpaceHasChanged ? data.nameSpace : type.Namespace; + var typeName = data.classHasChanged ? data.className : type.Name; var fullOldName = namespaceName + "." + typeName; return fullOldName; } diff --git a/Modules/UIElements/Core/VisualElement.cs b/Modules/UIElements/Core/VisualElement.cs index d9ce2fc0e4..8ccd0f0d46 100644 --- a/Modules/UIElements/Core/VisualElement.cs +++ b/Modules/UIElements/Core/VisualElement.cs @@ -222,8 +222,8 @@ public class UxmlSerializedData : UIElements.UxmlSerializedData [SerializeField, UxmlIgnore, HideInInspector] UxmlAttributeFlags languageDirection_UxmlAttributeFlags; [Tooltip(DataBinding.k_DataSourceTooltip)] - [SerializeField, HideInInspector, DataSourceDrawer] Object dataSource; - [SerializeField, UxmlIgnore, HideInInspector] UxmlAttributeFlags dataSource_UxmlAttributeFlags; + [SerializeField, HideInInspector, DataSourceDrawer, UxmlAttribute("data-source")] Object dataSourceUnityObject; + [SerializeField, UxmlIgnore, HideInInspector] UxmlAttributeFlags dataSourceUnityObject_UxmlAttributeFlags; // We use a string here because the PropertyPath struct is not serializable [UxmlAttribute("data-source-path")] @@ -279,8 +279,8 @@ public override void Deserialize(object obj) e.tabIndex = tabIndex; if (ShouldWriteAttributeValue(focusable_UxmlAttributeFlags)) e.focusable = focusable; - if (ShouldWriteAttributeValue(dataSource_UxmlAttributeFlags)) - e.dataSource = dataSource ? dataSource : null; + if (ShouldWriteAttributeValue(dataSourceUnityObject_UxmlAttributeFlags)) + e.dataSourceUnityObject = dataSourceUnityObject ? dataSourceUnityObject : null; if (ShouldWriteAttributeValue(dataSourcePathString_UxmlAttributeFlags)) e.dataSourcePathString = dataSourcePathString; if (ShouldWriteAttributeValue(dataSourceTypeString_UxmlAttributeFlags)) diff --git a/Modules/UIElements/Core/VisualElementDataBinding.cs b/Modules/UIElements/Core/VisualElementDataBinding.cs index ba93efd862..5111c5b42a 100644 --- a/Modules/UIElements/Core/VisualElementDataBinding.cs +++ b/Modules/UIElements/Core/VisualElementDataBinding.cs @@ -207,6 +207,14 @@ public object dataSource } } + // Used in the UI Builder + [UxmlAttributeBindingPath("dataSource")] + internal Object dataSourceUnityObject + { + get => dataSource as Object; + set => dataSource = value; + } + /// /// Path from the data source to the value. /// diff --git a/Modules/UIElements/Core/VisualElementTypeData.cs b/Modules/UIElements/Core/VisualElementTypeData.cs index 3085daa932..27daf30151 100644 --- a/Modules/UIElements/Core/VisualElementTypeData.cs +++ b/Modules/UIElements/Core/VisualElementTypeData.cs @@ -20,7 +20,6 @@ public TypeData(Type type) private string m_FullTypeName = string.Empty; private string m_TypeName = string.Empty; - private string m_TypeNamespace = string.Empty; public string fullTypeName { @@ -54,15 +53,6 @@ public string typeName return m_TypeName; } } - public string typeNamespace - { - get - { - if (string.IsNullOrEmpty(m_TypeNamespace)) - m_TypeNamespace = type.Namespace; - return m_TypeNamespace; - } - } } internal static TypeData GetOrCreateTypeData(Type t) diff --git a/Modules/UIElementsEditor/Debugger/Events/EventTypeSearchField.cs b/Modules/UIElementsEditor/Debugger/Events/EventTypeSearchField.cs index 31cd8f2bc2..5b181dada1 100644 --- a/Modules/UIElementsEditor/Debugger/Events/EventTypeSearchField.cs +++ b/Modules/UIElementsEditor/Debugger/Events/EventTypeSearchField.cs @@ -273,7 +273,7 @@ from z in x.GetInterfaces() void AddType(Type type, bool value) { var methodInfo = type.GetMethod("TypeId", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); - if (methodInfo == null) + if (methodInfo == null || methodInfo.ContainsGenericParameters) return; var typeId = (long)methodInfo.Invoke(null, null); diff --git a/Modules/UIElementsEditor/Debugger/Events/UIElementsEventDebugger.cs b/Modules/UIElementsEditor/Debugger/Events/UIElementsEventDebugger.cs index a38ee0cf5e..19f0b5f0cf 100644 --- a/Modules/UIElementsEditor/Debugger/Events/UIElementsEventDebugger.cs +++ b/Modules/UIElementsEditor/Debugger/Events/UIElementsEventDebugger.cs @@ -1391,10 +1391,10 @@ void UpdateSelectionCount() void UpdatePlaybackButtons() { var isProSkin = EditorGUIUtility.isProSkin; - m_DecreasePlaybackSpeedButton.EnableInClassList("light", !isProSkin); - m_IncreasePlaybackSpeedButton.EnableInClassList("light", !isProSkin); - m_SaveReplayButton.EnableInClassList("light", !isProSkin); - m_LoadReplayButton.EnableInClassList("light", !isProSkin); + m_DecreasePlaybackSpeedButton?.EnableInClassList("light", !isProSkin); + m_IncreasePlaybackSpeedButton?.EnableInClassList("light", !isProSkin); + m_SaveReplayButton?.EnableInClassList("light", !isProSkin); + m_LoadReplayButton?.EnableInClassList("light", !isProSkin); var anySelected = m_SelectedEvents != null && m_SelectedEvents.Any(); m_TogglePlayback?.SetEnabled(m_Debugger.isReplaying); diff --git a/README.md b/README.md index 7ef41e1fbd..855b5e06e9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Unity 6000.0.22f1 C# reference source code +## Unity 6000.0.23f1 C# reference source code The C# part of the Unity engine and editor source code. May be used for reference purposes only. diff --git a/Runtime/2D/Common/ScriptBindings/SpriteRenderer.bindings.cs b/Runtime/2D/Common/ScriptBindings/SpriteRenderer.bindings.cs index 547b0d02ba..020f3c7443 100644 --- a/Runtime/2D/Common/ScriptBindings/SpriteRenderer.bindings.cs +++ b/Runtime/2D/Common/ScriptBindings/SpriteRenderer.bindings.cs @@ -41,12 +41,17 @@ public void RegisterSpriteChangeCallback(UnityEngine.Events.UnityAction(); m_SpriteChangeEvent.AddListener(callback); + hasSpriteChangeEvents = true; } public void UnregisterSpriteChangeCallback(UnityEngine.Events.UnityAction callback) { if (m_SpriteChangeEvent != null) + { m_SpriteChangeEvent.RemoveListener(callback); + if (0 == m_SpriteChangeEvent.GetCallsCount()) + hasSpriteChangeEvents = false; + } } [RequiredByNativeCode] @@ -68,6 +73,12 @@ internal extern bool shouldSupportTiling get; } + internal extern bool hasSpriteChangeEvents + { + get; + set; + } + public extern Sprite sprite { get; diff --git a/Runtime/Export/UnityEvent/UnityEvent.cs b/Runtime/Export/UnityEvent/UnityEvent.cs index 36f97d48e7..92f3a0fcbd 100644 --- a/Runtime/Export/UnityEvent/UnityEvent.cs +++ b/Runtime/Export/UnityEvent/UnityEvent.cs @@ -807,6 +807,11 @@ internal MethodInfo FindMethod(string name, Type listenerType, PersistentListene } } + internal int GetCallsCount() + { + return m_Calls.Count; + } + public int GetPersistentEventCount() { return m_PersistentCalls.Count; diff --git a/Tools/Bee/build/Distribution/BeeDriver2/Bee.BeeDriver2.dll b/Tools/Bee/build/Distribution/BeeDriver2/Bee.BeeDriver2.dll index 0e45e236c95f0a243c084df46a012654bad3f02d..eb2a963265349caf26875d1000cd92b57319e56f 100644 GIT binary patch delta 642 zcmZoz!rriieL@Ed%aQNLC-%rNN=;lD&UkDxBcnR&lIM&JA(IuEbS6hKsxt;mZe*+% z{Plv70R%jNn2CXvp;|c8WVqt{OEs2BU=M`%!IzaGj>!wmJH}8Ya78(uDHh5*EBrt?fvFSBo6L~K%BYse zGy|&7iRmn3GLzC?kSP--<~#E9Bs1xOd2JFi9T^#tnasevW(GZm{oKh+9(-W#L&l-_Jj081ZOiz9DwkqspT-tX3~K2KpN&Su^dFm&0!J(^B^|OWs(B( zni=+THK@&HGJ^5A8`S1Ac_FD>$P@yVYh>Wm(f8yV{b zKfPdN009pmW@2Dv$k;5%ba*D?t;ttsud#D2x~0ZYz>?p`#K2XwM-0U52QoD#fQVv7 zpx_6v{6rwXSd4*zO++IQNNR*LfaE8iobz3Ufq_v2Wd1S+rxy&&d_XP(!y5*^UkoNi zKsFOYBxA|h&5!1)In+Pc4N}+0aK-nRYAh4S9tiJ)FDpYFlM|SCjG;>4igG+tD3o_r z_N$5+9YN=GBPAH>4AC8 z40;Uvxs#b3_`uwUj77nW3@J<|o2T9rXRLSG57G}2oXsR~0K%K5mcuZcNdd|OX_&+G z2T5)Y6W2kIN{CH!nS{W+W`@074Qg|lv|v2$2DSN2PDm;jGWkH|8ksxP7Baoqto`7# zIlIJ5MutiTi|wisjNZ)x0S}_464CmEFm*pDso=Y6%-dHO<){7uF8?@s4A#W>3dDq0*4 z6$P24qq(Z!pY-ub!pdo Date: Tue, 22 Oct 2024 16:22:51 +0700 Subject: [PATCH 2/2] Update Awaitable.Threading.cs Expose `MainThreadSynchronizationContext` so we can use in `Task` and similar API that can accept `SynchronizationContext` to return to main thread Add helper extension method to `Task` for conveniently scheduling task in one line --- .../Export/Scripting/Awaitable.Threading.cs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Runtime/Export/Scripting/Awaitable.Threading.cs b/Runtime/Export/Scripting/Awaitable.Threading.cs index 46e5f2fed5..e690069d72 100644 --- a/Runtime/Export/Scripting/Awaitable.Threading.cs +++ b/Runtime/Export/Scripting/Awaitable.Threading.cs @@ -16,6 +16,8 @@ internal static void SetSynchronizationContext(SynchronizationContext synchroniz _synchronizationContext = synchronizationContext; } + public static SynchronizationContext MainThreadSynchronizationContext => _synchronizationContext; + public static MainThreadAwaitable MainThreadAsync() { return new MainThreadAwaitable(_synchronizationContext); @@ -27,6 +29,74 @@ public static BackgroundThreadAwaitable BackgroundThreadAsync() } } + public static class AwaitableExtension + { + public static async Awaitable OnBackgroundThread(this Task task) + { + var result = await task; + await Awaitable.BackgroundThreadAsync(); + return result; + } + + public static async Awaitable OnMainThread(this Task task) + { + var result = await task; + await Awaitable.MainThreadAsync(); + return result; + } + + public static async Awaitable OnEndOfFrame(this Task task,CancellationToken cancellationToken = default) + { + var result = await task; + await Awaitable.EndOfFrameAsync(cancellationToken); + return result; + } + + public static async Awaitable OnFixedUpdate(this Task task,CancellationToken cancellationToken = default) + { + var result = await task; + await Awaitable.FixedUpdateAsync(cancellationToken); + return result; + } + + public static async Awaitable OnNextFrame(this Task task,CancellationToken cancellationToken = default) + { + var result = await task; + await Awaitable.NextFrameAsync(cancellationToken); + return result; + } + + public static async Awaitable OnBackgroundThread(this Task task) + { + await task; + await Awaitable.BackgroundThreadAsync(); + } + + public static async Awaitable OnMainThread(this Task task) + { + await task; + await Awaitable.MainThreadAsync(); + } + + public static async Awaitable OnEndOfFrame(this Task task,CancellationToken cancellationToken = default) + { + await task; + await Awaitable.EndOfFrameAsync(cancellationToken); + } + + public static async Awaitable OnFixedUpdate(this Task task,CancellationToken cancellationToken = default) + { + await task; + await Awaitable.FixedUpdateAsync(cancellationToken); + } + + public static async Awaitable OnNextFrame(this Task task,CancellationToken cancellationToken = default) + { + await task; + await Awaitable.NextFrameAsync(cancellationToken); + } + } + [Internal.ExcludeFromDocs] public struct MainThreadAwaitable : INotifyCompletion {