Skip to content

Commit d36031d

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.5] HDRP: Rendering Debugger - "Freeze Camera For Culling" dropdown was only showing None as an option.
1 parent 8e15ec0 commit d36031d

4 files changed

Lines changed: 105 additions & 30 deletions

File tree

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Fields.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,41 @@ public CameraSelector()
10401040
private Camera[] m_CamerasArray;
10411041
private List<Camera> m_Cameras = new List<Camera>();
10421042

1043+
#if ENABLE_RENDERING_DEBUGGER_UI
1044+
/// <inheritdoc/>
1045+
protected override VisualElement Create()
1046+
{
1047+
var objectPopUpField = base.Create() as UIElements.PopupField<UnityEngine.Object>;
1048+
1049+
if (objectPopUpField == null)
1050+
return new Label("Error creating CameraSelector field");
1051+
1052+
objectPopUpField.choices ??= new List<UnityEngine.Object>() { null };
1053+
1054+
// Refresh the dropdown choices to keep it in sync with available cameras in the scene.
1055+
// NOTE: If the currently selected camera is deleted, PopupField handles it internally,
1056+
// so we only need to maintain the available choices list.
1057+
this.ScheduleTracked(objectPopUpField, () => objectPopUpField.schedule.Execute(() =>
1058+
{
1059+
// Using ListPool and SequenceEqual to avoid unnecessary allocations and UI updates
1060+
using (UnityEngine.Pool.ListPool<UnityEngine.Object>.Get(out var tmp))
1061+
{
1062+
tmp.Add(null);
1063+
tmp.AddRange(getObjects());
1064+
1065+
if (!tmp.SequenceEqual(objectPopUpField.choices))
1066+
{
1067+
objectPopUpField.choices.Clear();
1068+
objectPopUpField.choices.AddRange(tmp);
1069+
}
1070+
}
1071+
1072+
}).Every(500));
1073+
1074+
return objectPopUpField;
1075+
}
1076+
#endif
1077+
10431078
IEnumerable<Camera> cameras
10441079
{
10451080
get

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,22 +308,19 @@ internal VisualElement ToVisualElement(Context context)
308308
m_Context = context;
309309
m_VisualElement = Create();
310310

311-
//Debug.Log($"ToVisualElement for {queryPath}");
312-
313311
if (m_VisualElement == null)
314312
{
315313
Debug.LogWarning($"Unable to create a Visual Element for type {GetType()}");
316314
return null;
317315
}
318316
m_VisualElement.AddToClassList("unity-inspector-element");
319-
317+
m_VisualElement.name = displayName;
320318

321319
#if UNITY_EDITOR
322320
// Support for legacy state handling
323321
if (this is ISupportsLegacyStateHandling legacyStateWidget)
324322
{
325323
m_RequiresLegacyStateHandling = legacyStateWidget.RequiresLegacyStateHandling();
326-
//Debug.Log($"LegacyState: {m_RequiresLegacyStateHandling} ({queryPath})");
327324
}
328325
#endif
329326

Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,6 @@ public partial class DebugDisplaySettings : IDebugData, ISerializedDebugDisplayS
273273
static GUIContent[] s_RenderingMipmapDebugMaterialTextureSlotStrings = null;
274274
static int[] s_RenderingMipmapDebugMaterialTextureSlotValues = null;
275275

276-
static List<GUIContent> s_CameraNames = new List<GUIContent>() { new("None") };
277-
static GUIContent[] s_CameraNamesStrings = { new ("No Visible Camera") };
278-
static int[] s_CameraNamesValues = { 0 };
279-
280-
static bool needsRefreshingCameraFreezeList = true;
281-
282276
#if ENABLE_NVIDIA && ENABLE_NVIDIA_MODULE
283277
internal UnityEngine.NVIDIA.DebugView nvidiaDebugView { get; } = new UnityEngine.NVIDIA.DebugView();
284278
#endif
@@ -341,8 +335,66 @@ public partial class DebugData
341335
public bool countRays = false;
342336
/// <summary>Display Show Lens Flare Data Driven Only.</summary>
343337
public bool showLensFlareDataDrivenOnly = false;
338+
339+
[Obsolete("This API has been deprecated. #from(6000.6)")] // TODO: Remove with debugCameraToFreeze
340+
private static Camera[] GetAvailableDebuggableCameras()
341+
{
342+
using (ListPool<Camera>.Get(out var tmp))
343+
{
344+
345+
#if UNITY_EDITOR
346+
if (UnityEditor.SceneView.lastActiveSceneView != null)
347+
{
348+
var sceneCamera = UnityEditor.SceneView.lastActiveSceneView.camera;
349+
if (sceneCamera != null)
350+
tmp.Add(sceneCamera);
351+
}
352+
#endif
353+
354+
var cameraArray = new Camera[Camera.allCamerasCount];
355+
Camera.GetAllCameras(cameraArray);
356+
357+
foreach (var camera in cameraArray)
358+
{
359+
if (camera == null)
360+
continue;
361+
362+
if (camera.cameraType != CameraType.Preview && camera.cameraType != CameraType.Reflection)
363+
{
364+
if (camera.TryGetComponent<IAdditionalData>(out _))
365+
tmp.Add(camera);
366+
}
367+
}
368+
369+
return tmp.ToArray();
370+
}
371+
}
372+
344373
/// <summary>Index of the camera to freeze for visibility.</summary>
345-
public int debugCameraToFreeze = 0;
374+
[Obsolete("Replace 'debugCameraToFreeze = index' with 'selectedCameraToFreeze = camera'. Index-based access is deprecated because camera list order is not stable. #from(6000.5)", false)]
375+
public int debugCameraToFreeze
376+
{
377+
get
378+
{
379+
var cameras = GetAvailableDebuggableCameras();
380+
if (cameras == null || cameras.Length == 0 || selectedCameraToFreeze == null)
381+
return -1;
382+
383+
return Array.IndexOf(cameras, selectedCameraToFreeze);
384+
}
385+
set
386+
{
387+
var cameras = GetAvailableDebuggableCameras();
388+
if (value < 0 || value >= cameras.Length)
389+
selectedCameraToFreeze = null;
390+
else
391+
selectedCameraToFreeze = cameras[value];
392+
}
393+
}
394+
395+
/// <summary>The camera to freeze for visibility.</summary>
396+
public Camera selectedCameraToFreeze;
397+
346398
internal RTASDebugView rtasDebugView = RTASDebugView.Shadows;
347399
internal RTASDebugMode rtasDebugMode = RTASDebugMode.InstanceID;
348400
internal VolumetricCloudsDebug volumetricCloudDebug = VolumetricCloudsDebug.Lighting;
@@ -680,7 +732,7 @@ public ColorPickerDebugMode GetDebugColorPickerMode()
680732
/// <returns>True if camera visibility is frozen</returns>
681733
public bool IsCameraFreezeEnabled()
682734
{
683-
return data.debugCameraToFreeze != 0;
735+
return data.selectedCameraToFreeze != null;
684736
}
685737

686738
/// <summary>
@@ -690,7 +742,7 @@ public bool IsCameraFreezeEnabled()
690742
/// <returns>True if a specific camera is frozen for visibility.</returns>
691743
public bool IsCameraFrozen(Camera camera)
692744
{
693-
return IsCameraFreezeEnabled() && camera.name.Equals(s_CameraNamesStrings[data.debugCameraToFreeze].text);
745+
return IsCameraFreezeEnabled() && camera == data.selectedCameraToFreeze;
694746
}
695747

696748
/// <summary>
@@ -1962,7 +2014,14 @@ void RegisterRenderingDebug()
19622014
});
19632015
}
19642016

1965-
renderingSettings.children.Add(new DebugUI.EnumField { nameAndTooltip = RenderingStrings.FreezeCameraForCulling, getter = () => data.debugCameraToFreeze, setter = value => data.debugCameraToFreeze = value, enumNames = s_CameraNamesStrings, enumValues = s_CameraNamesValues, getIndex = () => data.debugCameraToFreezeEnumIndex, setIndex = value => data.debugCameraToFreezeEnumIndex = value });
2017+
var freezeCameraForCullingSelector = new DebugUI.CameraSelector()
2018+
{
2019+
nameAndTooltip = RenderingStrings.FreezeCameraForCulling,
2020+
getter = () => data.selectedCameraToFreeze,
2021+
setter = value => data.selectedCameraToFreeze = value as Camera
2022+
};
2023+
2024+
renderingSettings.children.Add(freezeCameraForCullingSelector);
19662025

19672026
renderingSettings.children.Add(new DebugUI.Container
19682027
{
@@ -2218,19 +2277,6 @@ internal void UpdateMaterials()
22182277
}
22192278
}
22202279

2221-
internal void UpdateCameraFreezeOptions()
2222-
{
2223-
if (needsRefreshingCameraFreezeList)
2224-
{
2225-
s_CameraNamesStrings = s_CameraNames.ToArray();
2226-
s_CameraNamesValues = Enumerable.Range(0, s_CameraNames.Count()).ToArray();
2227-
2228-
UnregisterRenderingDebug();
2229-
RegisterRenderingDebug();
2230-
needsRefreshingCameraFreezeList = false;
2231-
}
2232-
}
2233-
22342280
internal bool DebugHideSky(HDCamera hdCamera)
22352281
{
22362282
return (IsMatcapViewEnabled(hdCamera) ||

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,9 +2757,6 @@ AOVRequestData aovRequest
27572757
}
27582758
else
27592759
{
2760-
#if DEVELOPMENT_BUILD || UNITY_EDITOR
2761-
m_DebugDisplaySettings.UpdateCameraFreezeOptions();
2762-
#endif
27632760
m_CurrentDebugDisplaySettings = m_DebugDisplaySettings;
27642761
}
27652762

0 commit comments

Comments
 (0)