Пример #1
0
        // 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,
                      InjectionPoint injectionPoint, QuibliPostProcess 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} 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 Available"));
                                                        }

                                                        menu.ShowAsContext();
                                                        EditorUtility.SetDirty(feature); };
            reorderableList.onRemoveCallback = (list) => {
                Undo.RegisterCompleteObjectUndo(feature, $"Removed {list.list[list.index]} 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.
            };
        }
Пример #2
0
 /// <summary>
 /// Force recreating the render feature
 /// </summary>
 /// <param name="feature">The render feature to recreate</param>
 private void forceRecreate(QuibliPostProcess feature)
 {
     feature.Create();
 }