// This code is mostly copied from Unity's HDRP repository /// <summary> /// Intialize a reoderable list /// </summary> void InitList(ref ReorderableList reorderableList, List <string> elements, string headerName, CustomPostProcessInjectionPoint injectionPoint, CustomPostProcess feature) { reorderableList = new ReorderableList(elements, typeof(string), true, true, true, true); reorderableList.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, headerName, EditorStyles.boldLabel); reorderableList.drawElementCallback = (rect, index, isActive, isFocused) => { rect.height = EditorGUIUtility.singleLineHeight; var elemType = Type.GetType(elements[index]); EditorGUI.LabelField(rect, GetName(elemType), EditorStyles.boldLabel); }; reorderableList.onAddCallback = (list) => { var menu = new GenericMenu(); foreach (var type in _availableRenderers[injectionPoint]) { if (!elements.Contains(type.AssemblyQualifiedName)) { menu.AddItem(new GUIContent(GetName(type)), false, () => { Undo.RegisterCompleteObjectUndo(feature, $"Added {type.ToString()} Custom Post Process"); elements.Add(type.AssemblyQualifiedName); forceRecreate(feature); // This is done since OnValidate doesn't get called. }); } } if (menu.GetItemCount() == 0) { menu.AddDisabledItem(new GUIContent("No Custom Post Process Availble")); } menu.ShowAsContext(); EditorUtility.SetDirty(feature); }; reorderableList.onRemoveCallback = (list) => { Undo.RegisterCompleteObjectUndo(feature, $"Removed {list.list[list.index].ToString()} Custom Post Process"); elements.RemoveAt(list.index); EditorUtility.SetDirty(feature); forceRecreate(feature); // This is done since OnValidate doesn't get called. }; reorderableList.elementHeightCallback = _ => EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; reorderableList.onReorderCallback = (list) => { EditorUtility.SetDirty(feature); forceRecreate(feature); // This is done since OnValidate doesn't get called. }; }
private void OnEnable() { _component = (CustomPostProcess)target; _injectionPointProperty = serializedObject.FindProperty("injectionPoint"); _shaderProperty = serializedObject.FindProperty("shader"); }
/// <summary> /// Force recreating the render feature /// </summary> /// <param name="feature">The render feature to recreate</param> private void forceRecreate(CustomPostProcess feature) { feature.Create(); }