public void AddHelpBox(MessageType messageType, string messageText)
        {
            var helpBox = new HelpBoxRow(messageType);

            helpBox.Add(new Label(messageText));
            this.hierarchy.Add(helpBox);
        }
        VisualElement CreateGUI(AbstractMaterialNode node, InspectableAttribute attribute, out VisualElement propertyVisualElement)
        {
            VisualElement nodeSettings = new VisualElement();
            var           nameLabel    = PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold);

            nodeSettings.Add(nameLabel);
            if (node.sgVersion < node.latestVersion)
            {
                var help = HelpBoxRow.TryGetDeprecatedHelpBoxRow($"{node.name} Node", () =>
                {
                    m_setNodesAsDirtyCallback?.Invoke();
                    node.owner.owner.RegisterCompleteObjectUndo($"Update {node.name} Node");
                    node.ChangeVersion(node.latestVersion);
                    inspectorUpdateDelegate?.Invoke();
                    m_updateNodeViewsCallback?.Invoke();
                    node.Dirty(ModificationScope.Graph);
                });

                if (help != null)
                {
                    nodeSettings.Insert(0, help);
                }
            }

            PropertyDrawerUtils.AddDefaultNodeProperties(nodeSettings, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback);

            propertyVisualElement = null;

            return(nodeSettings);
        }
        VisualElement CreateGUI(AbstractMaterialNode node, InspectableAttribute attribute, out VisualElement propertyVisualElement)
        {
            VisualElement nodeSettings = new VisualElement();
            var           nameLabel    = PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold);

            nodeSettings.Add(nameLabel);
            if (node.sgVersion < node.latestVersion)
            {
                string      deprecationText = null;
                string      buttonText      = null;
                string      labelText       = null;
                MessageType messageType     = MessageType.Warning;
                if (node is IHasCustomDeprecationMessage nodeWithCustomDeprecationSettings)
                {
                    nodeWithCustomDeprecationSettings.GetCustomDeprecationMessage(out deprecationText, out buttonText, out labelText, out messageType);
                }

                Action dismissAction = null;
                if (node.dismissedUpdateVersion < node.latestVersion)
                {
                    dismissAction = () =>
                    {   // dismiss
                        m_setNodesAsDirtyCallback?.Invoke();
                        node.owner.owner.RegisterCompleteObjectUndo($"Dismiss {node.name} Node Upgrade Flag");
                        node.dismissedUpdateVersion = node.latestVersion;
                        node.owner.messageManager.ClearNodesFromProvider(node.owner, new AbstractMaterialNode[] { node });
                        node.Dirty(ModificationScope.Graph);
                        inspectorUpdateDelegate?.Invoke();
                        m_updateNodeViewsCallback?.Invoke();
                    };
                }

                var help = HelpBoxRow.TryGetDeprecatedHelpBoxRow($"{node.name} Node",
                                                                 () =>
                {       // upgrade
                    m_setNodesAsDirtyCallback?.Invoke();
                    node.owner.owner.RegisterCompleteObjectUndo($"Update {node.name} Node");
                    node.ChangeVersion(node.latestVersion);
                    node.owner.messageManager.ClearNodesFromProvider(node.owner, new AbstractMaterialNode[] { node });
                    node.Dirty(ModificationScope.Graph);
                    inspectorUpdateDelegate?.Invoke();
                    m_updateNodeViewsCallback?.Invoke();
                },
                                                                 dismissAction, deprecationText, buttonText, labelText, messageType);

                if (help != null)
                {
                    nodeSettings.Insert(0, help);
                }
            }

            PropertyDrawerUtils.AddDefaultNodeProperties(nodeSettings, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback);
            AddCustomNodeProperties(nodeSettings, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback);

            propertyVisualElement = null;

            return(nodeSettings);
        }
        VisualElement CreateGUI(AbstractMaterialNode node, InspectableAttribute attribute, out VisualElement propertyVisualElement)
        {
            VisualElement nodeSettings = new VisualElement();
            var           nameLabel    = PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold);

            nodeSettings.Add(nameLabel);
            if (node.sgVersion < node.latestVersion)
            {
                var help = HelpBoxRow.TryGetDeprecatedHelpBoxRow($"{node.name} Node", () =>
                {
                    m_setNodesAsDirtyCallback?.Invoke();
                    node.owner.owner.RegisterCompleteObjectUndo($"Update {node.name} Node");
                    node.ChangeVersion(node.latestVersion);
                    inspectorUpdateDelegate?.Invoke();
                    m_updateNodeViewsCallback?.Invoke();
                    node.Dirty(ModificationScope.Graph);
                });

                if (help != null)
                {
                    nodeSettings.Insert(0, help);
                }
            }
            EnumField precisionField = null;

            if (node.canSetPrecision)
            {
                precisionField = new EnumField(node.precision);
                var propertyRow = new PropertyRow(new Label("Precision"));
                propertyRow.Add(precisionField, (field) =>
                {
                    field.RegisterValueChangedCallback(evt =>
                    {
                        if (evt.newValue.Equals(node.precision))
                        {
                            return;
                        }

                        m_setNodesAsDirtyCallback();
                        node.owner.owner.RegisterCompleteObjectUndo("Change precision");
                        node.precision = (Precision)evt.newValue;
                        node.owner.ValidateGraph();
                        m_updateNodeViewsCallback();
                        node.Dirty(ModificationScope.Graph);
                    });
                });
                if (node is Serialization.MultiJsonInternal.UnknownNodeType)
                {
                    precisionField.SetEnabled(false);
                }
                nodeSettings.Add(propertyRow);
            }
            propertyVisualElement = precisionField;
            return(nodeSettings);
        }
Пример #5
0
        VisualElement GetSettings(GraphData graphData, Action onChange)
        {
            var element = new VisualElement()
            {
                name = "graphSettings"
            };

            if (graphData.isSubGraph)
            {
                return(element);
            }

            void RegisterActionToUndo(string actionName)
            {
                graphData.owner.RegisterCompleteObjectUndo(actionName);
            }

            // Add Label
            var targetSettingsLabel = new Label("Target Settings");

            targetSettingsLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
            element.Add(new PropertyRow(targetSettingsLabel));

            var targetList = new ReorderableListView <JsonData <Target> >(
                graphData.m_ActiveTargets,
                "Active Targets",
                false,      // disallow reordering (active list is sorted)
                target => target.value.displayName);

            targetList.GetAddMenuOptions = () => graphData.GetPotentialTargetDisplayNames();

            targetList.OnAddMenuItemCallback +=
                (list, addMenuOptionIndex, addMenuOption) =>
            {
                RegisterActionToUndo("Add Target");
                graphData.SetTargetActive(addMenuOptionIndex);
                m_postChangeTargetSettingsCallback();
            };

            targetList.RemoveItemCallback +=
                (list, itemIndex) =>
            {
                RegisterActionToUndo("Remove Target");
                graphData.SetTargetInactive(list[itemIndex].value);
                m_postChangeTargetSettingsCallback();
            };

            element.Add(targetList);

            // Iterate active TargetImplementations
            foreach (var target in graphData.activeTargets)
            {
                // Ensure enabled state is being tracked and get value
                bool foldoutActive;
                if (!m_TargetFoldouts.TryGetValue(target, out foldoutActive))
                {
                    foldoutActive = true;
                    m_TargetFoldouts.Add(target, foldoutActive);
                }

                // Create foldout
                var foldout = new Foldout()
                {
                    text = target.displayName, value = foldoutActive, name = "foldout"
                };
                element.Add(foldout);
                foldout.AddToClassList("MainFoldout");
                foldout.RegisterValueChangedCallback(evt =>
                {
                    // Update foldout value and rebuild
                    m_TargetFoldouts[target] = evt.newValue;
                    foldout.value            = evt.newValue;
                    onChange();
                });

                if (foldout.value)
                {
                    // Get settings for Target
                    var context = new TargetPropertyGUIContext();
                    // Indent the content of the foldout
                    context.globalIndentLevel++;
                    target.GetPropertiesGUI(ref context, onChange, RegisterActionToUndo);
                    context.globalIndentLevel--;
                    element.Add(context);
                }
            }

#if VFX_GRAPH_10_0_0_OR_NEWER
            // Inform the user that VFXTarget is deprecated, if they are using one.
            var activeTargetSRP = graphData.m_ActiveTargets.Where(t => !(t.value is VFXTarget));
            if (graphData.m_ActiveTargets.Any(t => t.value is VFXTarget) && //Use Old VFXTarget
                activeTargetSRP.Any() &&
                activeTargetSRP.All(o => o.value.CanSupportVFX()))
            {
                var vfxWarning = new HelpBoxRow(MessageType.Info);

                var vfxWarningLabel = new Label("The Visual Effect target is deprecated.\n" +
                                                "Use the SRP target(s) instead, and enable 'Support VFX Graph' in the Graph Inspector.\n" +
                                                "Then, you can remove the Visual Effect Target.");

                vfxWarningLabel.style.color      = new StyleColor(Color.white);
                vfxWarningLabel.style.whiteSpace = WhiteSpace.Normal;

                vfxWarning.Add(vfxWarningLabel);
                element.Add(vfxWarning);
            }
#endif

            return(element);
        }
        VisualElement CreateGUI(SampleVirtualTextureNode node, InspectableAttribute attribute,
                                out VisualElement propertyVisualElement)
        {
            PropertySheet propertySheet = new PropertySheet();

            var enumPropertyDrawer = new EnumPropertyDrawer();

            propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.addressMode == (SampleVirtualTextureNode.AddressMode)newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Address Mode Change");
                node.addressMode = (SampleVirtualTextureNode.AddressMode)newValue;
            },
                                                           node.addressMode,
                                                           "Address Mode",
                                                           SampleVirtualTextureNode.AddressMode.VtAddressMode_Wrap,
                                                           out var addressModeVisualElement));

            propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.lodCalculation == (SampleVirtualTextureNode.LodCalculation)newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Lod Mode Change");
                node.lodCalculation = (SampleVirtualTextureNode.LodCalculation)newValue;
            },
                                                           node.lodCalculation,
                                                           "Lod Mode",
                                                           SampleVirtualTextureNode.LodCalculation.VtLevel_Automatic,
                                                           out var lodCalculationVisualElement));

            propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.sampleQuality == (SampleVirtualTextureNode.QualityMode)newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Quality Change");
                node.sampleQuality = (SampleVirtualTextureNode.QualityMode)newValue;
            },
                                                           node.sampleQuality,
                                                           "Quality",
                                                           SampleVirtualTextureNode.QualityMode.VtSampleQuality_High,
                                                           out var qualityVisualElement));

            var boolPropertyDrawer = new BoolPropertyDrawer();

            propertySheet.Add(boolPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.noFeedback == !newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Feedback Settings Change");
                node.noFeedback = !newValue;
            },
                                                           !node.noFeedback,
                                                           "Automatic Streaming",
                                                           out var propertyToggle));

            propertySheet.Add(boolPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.enableGlobalMipBias == newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Enable Global Mip Bias VT Change");
                node.enableGlobalMipBias = newValue;
            },
                                                           node.enableGlobalMipBias,
                                                           "Use Global Mip Bias",
                                                           out var enableGlobalMipBias));


            // display warning if the current master node doesn't support virtual texturing
            // TODO: Add warning when no active subTarget supports VT
            // if (!node.owner.isSubGraph)
            // {
            //     bool supportedByMasterNode =
            //         node.owner.GetNodes<IMasterNode>().FirstOrDefault()?.supportsVirtualTexturing ?? false;
            //     if (!supportedByMasterNode)
            //         propertySheet.Add(new HelpBoxRow(MessageType.Warning),
            //             (row) => row.Add(new Label(
            //                 "The current master node does not support Virtual Texturing, this node will do regular 2D sampling.")));
            // }

            // display warning if the current render pipeline doesn't support virtual texturing
            HelpBoxRow help = new HelpBoxRow(MessageType.Warning);
            string     labelText;
            IVirtualTexturingEnabledRenderPipeline vtRp =
                GraphicsSettings.currentRenderPipeline as IVirtualTexturingEnabledRenderPipeline;

            if (vtRp == null)
            {
                labelText = "The current render pipeline does not support Virtual Texturing, this node will do regular 2D sampling.";
            }
            else if (vtRp.virtualTexturingEnabled == false)
            {
                labelText = "The current render pipeline has disabled Virtual Texturing, this node will do regular 2D sampling.";
            }
            else
            {
#if !ENABLE_VIRTUALTEXTURES
                labelText = "Virtual Texturing is disabled globally (possibly by the render pipeline settings), this node will do regular 2D sampling.";
#else
                labelText = "";
#endif
            }

            if (!string.IsNullOrEmpty(labelText))
            {
                var label = new Label(labelText)
                {
                    name = "message-warn"
                };
                label.style.whiteSpace = WhiteSpace.Normal;
                propertySheet.Add(help, (row) => row.Add(label));
            }
            propertyVisualElement = propertySheet;
            return(propertySheet);
        }