| Parameter | Description |
|---|---|
| sceneView | The SceneView that opened the SceneViewCameraWindow. |
This function is called to create custom additional settings in the UI.
using UnityEditor; using UnityEngine.UIElements;
[InitializeOnLoad] static class AdditionalCameraSettings { static AdditionalCameraSettings() { SceneViewCameraWindow.createAdditionalSettingsGUI += CreateGUI; } static VisualElement CreateGUI(SceneView sceneView) { var root = new VisualElement(); root.Add(new Label("My custom additional settings GUI")); return root; } }
The following advanced example demonstrates how to use it with binded additional settings in the context of a specific render pipeline.
using System; using UnityEditor; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UIElements;
namespace CustomRP { [InitializeOnLoad] static class AdditionalCameraSettings { static AdditionalCameraSettings() { RenderPipelineManager.activeRenderPipelineCreated += AddHooks; SceneView.onCameraCreated += EnsureAdditionalSettings; } static void AddHooks() { // Filter to add these hooks only if your custom SRP is active if (GraphicsSettings.currentRenderPipelineAssetType != typeof(CustomRPAsset)) return; SceneViewCameraWindow.createAdditionalSettingsGUI += CreateGUI; SceneViewCameraWindow.bindAdditionalSettings += BindGUI; RenderPipelineManager.activeRenderPipelineDisposed += RemoveHooks; }
public static void RemoveHooks() { SceneViewCameraWindow.createAdditionalSettingsGUI -= CreateGUI; SceneViewCameraWindow.bindAdditionalSettings -= BindGUI; RenderPipelineManager.activeRenderPipelineDisposed -= RemoveHooks; }
static void EnsureAdditionalSettings(SceneView sceneView) { // Ensure additional sibling component on Camera for SceneView if (!sceneView.camera.TryGetComponent(out CustomAdditonalCameraData hdAdditionalCameraData)) hdAdditionalCameraData = sceneView.camera.gameObject.AddComponent<CustomAdditonalCameraData>();
// Ensure additional serialized container to persist through Editor closing and DomainReload var additionalData = sceneView.GetAdditionalSettings<CustomAdditionalSettings>(); if (additionalData == null) { additionalData = new CustomAdditionalSettings(hdAdditionalCameraData); sceneView.AddAdditionalSettings(additionalData); }
additionalData.SetLinkedComponent(hdAdditionalCameraData); additionalData.Apply(); } // This is called when the GUI is created (when opening the dropdown) static VisualElement CreateGUI(SceneView sceneView) { var root = new VisualElement(); var header = new Label("Rendering (Custom SRP)"); header.AddToClassList("header"); // format the title of the section as other section of the dropdown root.Add(header); root.Add(new Toggle() { name = "CustomValue" }); return root; } // This is called: // - after CreateGUI // - after Reset is performed on additional settings // - after Paste is performed on additional settings static void BindGUI(SceneView sceneView, VisualElement root) { var customValueToggle = root.Q<Toggle>("CustomValue"); var settings = sceneView.GetAdditionalSettings<CustomAdditionalSettings>(); customValueToggle.SetValueWithoutNotify(settings.customValue); } }
// AdditionalData ensures persistence through DomainReload and when the Editor is opened again [Serializable] class CustomAdditionalSettings : SceneView.AdditionalSettings<CustomRPAsset, CustomAdditonalCameraData> { // Settings here are serialized and kept through the DomainReload [SerializeField] bool m_CustomValue;
// Accessor are prefered to ensure change here (from UI) will be puched on the component public bool customValue { get => m_CustomValue; set { m_CustomValue = value; linkedComponent.customValue = value; //partial Apply } }
public CustomAdditionalSettings(CustomAdditonalCameraData component) { Reset(); SetLinkedComponent(component); Apply(); }
public void SetLinkedComponent(CustomAdditonalCameraData component) => linkedComponent = component; // Called by the engine when user select in the menu: // - `Reset Settings` (after Reset is called) // - `Paste Settings` public override void Apply() => linkedComponent.customValue = customValue;
// Called by the engine when user select `Reset Settings` in the menu public override void Reset() => customValue = true; }
// Minimal implementation of Custom SRP for the purpose of the example. class CustomRP : RenderPipeline { } class CustomRPAsset : RenderPipelineAsset<CustomRP> { protected override RenderPipeline CreatePipeline() => new CustomRP(); }
// Minimal implementation of additional data component for the purpose of the example. // The Camera of the SceneView being recreated at each DomainReload, the information would be lost. // This component should be defined in runtime assembly and will be gatherable by your code. class CustomAdditonalCameraData : MonoBehaviour { public bool customValue; } }