public override void OnInspectorGUI() { m_compositionManager = (CompositionManager)target; if (m_compositionManager == null) { Debug.LogError("Compositor target was null"); return; } var headerStyle = EditorStyles.helpBox; headerStyle.fontSize = 14; // Cache the serialized property fields if (m_IsEditorDirty || m_SerializedProperties == null) { if (CacheSerializedObjects()) { m_IsEditorDirty = false; } else { return; } } m_SerializedProperties.Update(); m_EnablePreview = EditorGUILayout.Toggle(Styles.k_EnablePreview, m_compositionManager.enableOutput); { m_compositionManager.enableOutput = m_EnablePreview; } bool cameraChange = false; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_SerializedProperties.outputCamera, Styles.k_OutputCamera); if (EditorGUI.EndChangeCheck()) { cameraChange = true; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_SerializedProperties.compositionShader, Styles.k_CompositionGraph); bool shaderChange = false; if (EditorGUI.EndChangeCheck()) { // Clear the existing shader (the new shader will be loaded in the next Update) m_IsEditorDirty = true; shaderChange = true; } if (m_compositionManager.shader == null) { EditorGUILayout.Space(5); EditorGUILayout.HelpBox(Styles.k_ShaderWarning, MessageType.Error); } EditorGUILayout.PropertyField(m_SerializedProperties.displayNumber); // Draw some warnings in case alpha is not fully supported if (m_compositionManager.alphaSupport == CompositionManager.AlphaChannelSupport.None) { EditorGUILayout.Space(5); EditorGUILayout.HelpBox(Styles.k_AlphaWarningPipeline, MessageType.Warning); } else if (m_compositionManager.alphaSupport == CompositionManager.AlphaChannelSupport.Rendering) { EditorGUILayout.Space(5); EditorGUILayout.HelpBox(Styles.k_AlphaWarningPost, MessageType.Warning); } // Now draw the composition shader properties DrawCompositionParameters(); // Now draw the list of layers EditorGUILayout.Separator(); layerListChange = false; if (m_layerList == null) { var serializedLayerList = m_SerializedProperties.layerList; m_layerList = new ReorderableList(m_SerializedProperties.compositorSO, serializedLayerList, true, false, true, true); // Pre-select the "default" item in the list (used to remember the last selected item when re-creating the Editor) if (defaultSelection >= 0) { m_layerList.index = Math.Min(defaultSelection, m_layerList.count - 1); } m_layerList.drawHeaderCallback = (Rect rect) => { }; m_layerList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (index < m_SerializedLayerProperties.Count) { var serializedProperties = m_SerializedLayerProperties[index]; CompositionLayerUI.DrawItemInList(rect, serializedProperties, m_compositionManager.GetRenderTarget(index), m_compositionManager.aspectRatio, m_compositionManager.alphaSupport != CompositionManager.AlphaChannelSupport.None); } }; m_layerList.onReorderCallbackWithDetails += (list, oldIndex, newIndex) => { layerListChange = true; m_IsEditorDirty = true; m_compositionManager.ReorderChildren(oldIndex, newIndex); m_compositionManager.ValidateLayerListOrder(oldIndex, newIndex); }; m_layerList.elementHeightCallback = (index) => { if (index < m_SerializedLayerProperties.Count) { return(m_SerializedLayerProperties[index].GetListItemHeight()); } return(0); }; m_layerList.onAddCallback = (list) => { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Image"), false, AddLayerOfTypeCallback, CompositorLayer.LayerType.Image); menu.AddItem(new GUIContent("Video"), false, AddLayerOfTypeCallback, CompositorLayer.LayerType.Video); menu.AddItem(new GUIContent("Camera"), false, AddLayerOfTypeCallback, CompositorLayer.LayerType.Camera); menu.ShowAsContext(); m_IsEditorDirty = true; m_SerializedProperties.layerList.serializedObject.Update(); EditorUtility.SetDirty(m_compositionManager.profile); }; m_layerList.onRemoveCallback = (list) => { Undo.RecordObject(m_compositionManager, "Remove compositor sublayer"); m_compositionManager.RemoveLayerAtIndex(list.index); m_IsEditorDirty = true; EditorUtility.SetDirty(m_compositionManager.profile); }; m_layerList.onSelectCallback = (index) => { m_filterList = null; }; m_layerList.onCanRemoveCallback = (list) => { return(!m_compositionManager.IsOutputLayer(list.index)); }; m_layerList.onCanAddCallback = (list) => { return(list.index >= 0); }; m_layerList.headerHeight = 0; } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField(Styles.k_RenderSchedule, headerStyle); m_layerList.DoLayoutList(); EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { layerListChange = true; } float height = EditorGUIUtility.singleLineHeight; if (m_layerList.index >= 0) { height += m_SerializedLayerProperties[m_layerList.index].GetPropertiesHeight(); } var rectangle = EditorGUILayout.BeginVertical(GUILayout.Height(height)); EditorGUI.BeginChangeCheck(); if (m_layerList.index >= 0) { EditorGUILayout.LabelField(Styles.k_Properties, headerStyle); rectangle.y += EditorGUIUtility.singleLineHeight * 1.5f; rectangle.x += 5; rectangle.width -= 10; var serializedProperties = m_SerializedLayerProperties[m_layerList.index]; DrawLayerProperties(rectangle, serializedProperties, m_layerList.index, null); } EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { // Also the layers might need to be re-initialized layerListChange = true; } if (m_SerializedProperties != null) { m_SerializedProperties.ApplyModifiedProperties(); } if (shaderChange) { // This needs to run after m_SerializedProperties.ApplyModifiedProperties CompositionUtils.LoadOrCreateCompositionProfileAsset(m_compositionManager); m_compositionManager.SetupCompositionMaterial(); CompositionUtils.SetDefaultLayers(m_compositionManager); } if (cameraChange) { m_compositionManager.DropCompositorCamera(); m_compositionManager.Init(); } if (layerListChange) { // Some properties were changed, mark the profile as dirty so it can be saved if the user saves the scene EditorUtility.SetDirty(m_compositionManager); EditorUtility.SetDirty(m_compositionManager.profile); m_compositionManager.UpdateLayerSetup(); } }
void OnGUI() { m_TimeSinceLastRepaint = 0; CompositionManager compositor = CompositionManager.GetInstance(); bool enableCompositor = false; if (compositor) { enableCompositor = compositor.enabled; } bool enableCompositorCached = enableCompositor; enableCompositor = EditorGUILayout.Toggle(Styles.enableCompositor, enableCompositor); // Track if the user changed the compositor enable state and mark the scene dirty if necessary if (enableCompositorCached != enableCompositor && compositor != null) { EditorUtility.SetDirty(compositor); } if (compositor == null && enableCompositor) { Debug.Log("The scene does not have a compositor. Creating a new one with the default configuration."); GameObject go = new GameObject("HDRP Compositor") { hideFlags = HideFlags.HideInHierarchy }; compositor = go.AddComponent <CompositionManager>(); // Mark as dirty, so if the user closes the scene right away, the change will be saved. EditorUtility.SetDirty(compositor); // Now add the default configuration CompositionUtils.LoadDefaultCompositionGraph(compositor); CompositionUtils.LoadOrCreateCompositionProfileAsset(compositor); compositor.SetupCompositionMaterial(); CompositionUtils.SetDefaultCamera(compositor); CompositionUtils.SetDefaultLayers(compositor); Undo.RegisterCreatedObjectUndo(compositor.outputCamera.gameObject, "Create Compositor"); Undo.RegisterCreatedObjectUndo(go, "Create Compositor"); } else if (compositor && (compositor.enabled != enableCompositor)) { string message = enableCompositor ? "Enable Compositor" : "Disable Compositor"; Undo.RecordObject(compositor, message); compositor.enabled = enableCompositor; } else if (!compositor) { return; } if (compositor && !compositor.enabled) { if (GUILayout.Button(new GUIContent(Styles.removeCompositor))) { if (compositor.outputCamera) { if (compositor.outputCamera.name == CompositionUtils.k_DefaultCameraName) { var cameraData = compositor.outputCamera.GetComponent <HDAdditionalCameraData>(); if (cameraData != null) { CoreUtils.Destroy(cameraData); } CoreUtils.Destroy(compositor.outputCamera.gameObject); CoreUtils.Destroy(compositor.outputCamera); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } CoreUtils.Destroy(compositor); return; } } // keep track of shader graph changes: when the user saves a graph, we should load/reflect any new shader properties GraphData.onSaveGraph += MarkShaderAsDirty; if (compositor.profile == null) { // The compositor was loaded, but there was no profile (someone deleted the asset from disk?), so create a new one CompositionUtils.LoadOrCreateCompositionProfileAsset(compositor); compositor.SetupCompositionMaterial(); m_RequiresRedraw = true; } if (m_Editor == null || m_Editor.target == null || m_Editor.isDirty || m_RequiresRedraw) { if (m_Editor != null) { // Remember the previously selected layer when recreating the Editor s_SelectionIndex = m_Editor.selectionIndex; } m_Editor = (CompositionManagerEditor)Editor.CreateEditor(compositor); m_RequiresRedraw = false; m_Editor.defaultSelection = s_SelectionIndex; } m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition); using (new EditorGUI.DisabledScope(!compositor.enabled)) { if (m_Editor) { m_Editor.OnInspectorGUI(); // Remember which layer was selected / drawn in the last draw call s_SelectionIndex = m_Editor.selectionIndex; } } GUILayout.EndScrollView(); }